You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
963 B
32 lines
963 B
import os |
|
from datetime import datetime |
|
from os import environ |
|
|
|
from airflow import DAG |
|
from airflow.hooks.base_hook import BaseHook |
|
from airflow.operators.python_operator import PythonOperator |
|
|
|
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": "token", "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"}, |
|
)
|
|
|