Skip to content

Instantly share code, notes, and snippets.

@jimathyp
Last active February 15, 2022 01:14
Show Gist options
  • Select an option

  • Save jimathyp/3c7741e2272bb8e1d1d4dcb86bbe7289 to your computer and use it in GitHub Desktop.

Select an option

Save jimathyp/3c7741e2272bb8e1d1d4dcb86bbe7289 to your computer and use it in GitHub Desktop.

Airflow

Airflow connections

https://airflow.apache.org/docs/apache-airflow/1.10.3/howto/connection/index.html

https://airflow.apache.org/docs/apache-airflow/1.10.5/_modules/airflow/models/connection.html

Airflow connections can be managed in the GUI.

Airflow connections are stored in the database. They are encrypted.

Doesn't seem to be possible to see when a connection was changed.

It is possible to run some python to obtain the connection details unencrypted.

from airflow.hooks.base_hook import BaseHook
connection = BaseHook.get_connection("conn_name")
# connection = BaseHook.get_connection("username_connection")
conn_password = connection.password
conn_login = connection.login

To actually use a connection

from airflow.models import Connection
def create_conn(username, password, host=None):
new_conn = Connection(conn_id=f'{username}_connection',
                                  login=username,
                                  host=host if host else None)
new_conn.set_password(password)

https://stackoverflow.com/questions/45280650/store-and-access-password-using-apache-airflow https://stackoverflow.com/questions/55626195/export-all-airflow-connections-to-new-environment

From CLI can list connections

https://airflow.apache.org/docs/apache-airflow/1.10.3/cli.html?highlight=connections#connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment