气流> = 1.10.10支持秘密后端,并支持从Hashicorp Vault获取气流变量和连接。
气流文档中的更多详细信息:https : //airflow.apache.org/docs/stable/howto/use-alternative-secrets-backend.html#hashicorp-vault-secrets-backend
如果您想在本地进行测试,请查看https://www.astronomer.io/guides/airflow-and-hashicorp-vault/中的教程
在中设置以下配置airflow.cfg
,根据您的环境进行更新:
backend = airflow.contrib.secrets.hashicorp_vault.VaultBackend
backend_kwargs = {"connections_path": "connections", "variables_path": "variables", "mount_point": "airflow", "url": "http://127.0.0.1:8200"}
DAG示例用于测试集成:
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
from airflow.hooks.base_hook import BaseHook
def get_secrets(**kwargs):
conn = BaseHook.get_connection(kwargs['my_conn_id'])
print(f"Password: {conn.password}, Login: {conn.login}, URI: {conn.get_uri()}, Host: {conn.host}")
with DAG('example_secrets_dags', 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'},
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句