You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@airflow.apache.org by ra...@gmail.com, ra...@gmail.com on 2018/11/02 05:11:31 UTC

Airflow credentials: I'm wondering Is there a way to access the stored credentials from Airflow using python script and validate the url and database?

Does using hooks can do this job? Any code snippet or ideas would be useful.

Saving logins on Airflow:

Example from official documentation:
        Python 2.7.9 (default, Feb 10 2015, 03:28:08)
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import airflow
    >>> from airflow import models, settings
    >>> from airflow.contrib.auth.backends.password_auth import PasswordUser
    >>> user = PasswordUser(models.User())
    >>> user.username = 'new_user_name'
    >>> user.email = 'new_user_email@example.com'
    >>> user.password = 'set_the_password'
    >>> session = settings.Session()
    >>> session.add(user)
    >>> session.commit()
    >>> session.close()
    >>> exit()




Does using hooks can do this job? Any code snippet be useful to get an idea.

Saving logins on Airflow:

Example from official documentation:
        Python 2.7.9 (default, Feb 10 2015, 03:28:08)
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import airflow
    >>> from airflow import models, settings
    >>> from airflow.contrib.auth.backends.password_auth import PasswordUser
    >>> user = PasswordUser(models.User())
    >>> user.username = 'new_user_name'
    >>> user.email = 'new_user_email@example.com'
    >>> user.password = 'set_the_password'
    >>> session = settings.Session()
    >>> session.add(user)
    >>> session.commit()
    >>> session.close()
    >>> exit()

I want to grab these credentials from my python script when I run the Dags.

Is "passing these credentials on the command line using bash operator and grabbing it with my script" only way of achieving this?

Thanks in advance! 
Raj