Код: Выделить всё
podman run -d --name airflow --network airflow-net --cpus 8 --memory 8192m -e AIRFLOW__CORE__EXECUTOR=LocalExecutor -e AIRFLOW_UID=50000 -e AIRFLOW__CORE__HIDE_SENSITIVE_VAR_CONN_FIELDS=False -e AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres:5432/airflow -v doc-dbt:/opt/airflow/doc-dbt -v airflow-dags:/opt/airflow/dags -v airflow-logs:/opt/airflow/logs -v airflow-plugins:/opt/airflow/plugins -p 8080:8080 apache/airflow:2.10.5 webserver

Для получения пароля я использую следующий код:
Код: Выделить всё
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago
from airflow.models.connection import Connection
from cryptography.hazmat.primitives import serialization
import base64
# Define the Python function
def python_test():
# Fetch the connection from Airflow secrets
conn = Connection.get_connection_from_secrets("snowflake_test")
# Extract extra fields
extra_dict = conn.extra_dejson
private_key_content = extra_dict.get("private_key_content") # safer than self._get_field
print(f"private_key_content: {private_key_content}")
if conn.password:
print(f"conn.test:{conn.password}")
passphrase = conn.password.strip().encode()
private_key_pem = base64.b64decode(private_key_content)
from typing import Any
def default_backend() -> Any:
from cryptography.hazmat.backends.openssl.backend import backend
return backend
p_key = serialization.load_pem_private_key(private_key_pem, password=passphrase,backend=default_backend())
# Define the DAG
with DAG(
dag_id="snowflake_private_key_dag",
start_date=days_ago(1),
schedule_interval=None, # Run on demand
catchup=False,
tags=["example", "snowflake"]
) as dag:
python_task = PythonOperator(
task_id="print_private_key",
python_callable=python_test
)
Подробнее здесь: https://stackoverflow.com/questions/798 ... lse-and-st
Мобильная версия