Skip to content

Instantly share code, notes, and snippets.

@vshih
Created April 14, 2021 01:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vshih/c486bef62d072f13ba21e327f094ec6f to your computer and use it in GitHub Desktop.
Save vshih/c486bef62d072f13ba21e327f094ec6f to your computer and use it in GitHub Desktop.
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