我已在Airflow中保存了类型为“ google_cloud_platform”的连接,如此处https://cloud.google.com/composer/docs/how-to/managing/connections
所述现在在我的DAG中,我需要从保存的连接中提取密钥文件JSON
要使用的正确钩子是什么?
答案 0 :(得分:1)
您可以按如下方式使用BaseHook
:
from airflow.hooks.base_hook import BaseHook
GCP_CONNECTION_ID="my-gcp-connection"
BaseHook.get_connection(GCP_CONNECTION_ID).extras["extra__google_cloud_platform__keyfile_dict"]
答案 1 :(得分:1)
使用airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook
获取存储的连接。例如
from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
gcp_hook = GoogleCloudBaseHook(gcp_conn_id="<your-conn-id>")
keyfile_dict = gcp_hook._get_field('keyfile_dict')