-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_vault.py
24 lines (20 loc) · 967 Bytes
/
example_vault.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
from os import environ
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
from airflow.hooks.base_hook import BaseHook
os.environ['AIRFLOW__SECRETS__BACKEND'] = "airflow.providers.hashicorp.secrets.vault.VaultBackend"
os.environ['AIRFLOW__SECRETS__BACKEND_KWARGS'] = '{"connections_path": "myapp", "mount_point": "secret", "auth_type": "token", "token": "s.syjqsHYKDG0zmCE6YkUyGCIy", "url": "http://vault:8200"}'
def get_secrets(**kwargs):
conn = BaseHook.get_connection(kwargs['my_conn_id'])
print("Password:", {conn.password} )
print(" Login:", {conn.login} )
print(" URI:", {conn.get_uri()} )
print("Host:", {conn.host})
with DAG('vault_example', start_date=datetime(2020, 1, 1), schedule_interval=None) as dag:
test_task = PythonOperator(
task_id='test-task',
python_callable=get_secrets,
op_kwargs={'my_conn_id': 'smtp_default'},
)