Created
April 14, 2021 01:00
-
-
Save vshih/c486bef62d072f13ba21e327f094ec6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from airflow import DAG | |
from airflow.models import Connection | |
from airflow.operators import PythonOperator | |
from airflow.utils import db | |
from datetime import datetime | |
from yaml import dump | |
def dump_connections(**kwargs): | |
with db.create_session() as session: | |
connections = session.query(Connection).all() | |
print(dump({ | |
'airflow': { | |
'connections': [ | |
{ | |
(column if column.startswith('conn_') else 'conn_' + column): getattr(connection, column) | |
for column in ['conn_id', 'conn_type', 'schema', 'host', 'port', 'login', 'password', 'extra'] | |
} | |
for connection in connections | |
] | |
} | |
}, sort_keys=False)) | |
with DAG( | |
dag_id='dump-connections', | |
start_date=datetime.min, | |
) as dag: | |
PythonOperator( | |
task_id='dump-connections', | |
python_callable=dump_connections, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment