Last active
July 14, 2020 10:43
-
-
Save dmlogv/51979e38a5c80e83f2cb1715f226f94a to your computer and use it in GitHub Desktop.
Export Airflow connections
This file contains hidden or 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
#!/usr/bin/env python3 | |
"""Export Apache Airflow connections | |
Run under `airflow` user (or another user owns an `airflow` DB) inside its home directory. Like a: | |
[dm-logv@airflow ~]$ sudo -u airflow /bin/bash | |
[airflow@airflow dm-logv]$ cd ~ | |
[airflow@airflow ~]$ chmod +x export_airflow_connections.py | |
[airflow@airflow ~]$ ./export_airflow_connections.py > secrets.py | |
""" | |
# Disable Airflow logging | |
from logging import getLogger, CRITICAL | |
getLogger('airflow').setLevel(CRITICAL) | |
from airflow import settings | |
from airflow.models import Connection | |
fields = 'conn_id conn_type host port schema login password extra'.split() | |
session = settings.Session() | |
for conn in session.query(Connection).order_by(Connection.conn_id): | |
d = {field: getattr(conn, field) for field in fields} | |
print(conn.conn_id, '=', d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment