From 1737b432ee19ca3618230bc33d4b8aa580659010 Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Fri, 15 Nov 2024 17:26:53 -0800 Subject: [PATCH] make host/port configurable for Snowflake connections (#44079) --- .../connections/snowflake.rst | 2 ++ .../src/airflow/providers/snowflake/hooks/snowflake.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/apache-airflow-providers-snowflake/connections/snowflake.rst b/docs/apache-airflow-providers-snowflake/connections/snowflake.rst index 8d4a3aad646ea..741d73a62e3d4 100644 --- a/docs/apache-airflow-providers-snowflake/connections/snowflake.rst +++ b/docs/apache-airflow-providers-snowflake/connections/snowflake.rst @@ -62,6 +62,8 @@ Extra (optional) * ``private_key_content``: Specify the content of the private key file. * ``session_parameters``: Specify `session level parameters `_. * ``insecure_mode``: Turn off OCSP certificate checks. For details, see: `How To: Turn Off OCSP Checking in Snowflake Client Drivers - Snowflake Community `_. + * ``host``: Target Snowflake hostname to connect to (e.g., for local testing with LocalStack). + * ``port``: Target Snowflake port to connect to (e.g., for local testing with LocalStack). URI format example ^^^^^^^^^^^^^^^^^^ diff --git a/providers/src/airflow/providers/snowflake/hooks/snowflake.py b/providers/src/airflow/providers/snowflake/hooks/snowflake.py index 0f81f2e38408c..81785338e7ba5 100644 --- a/providers/src/airflow/providers/snowflake/hooks/snowflake.py +++ b/providers/src/airflow/providers/snowflake/hooks/snowflake.py @@ -279,6 +279,14 @@ def _get_conn_params(self) -> dict[str, str | None]: conn_config.pop("login", None) conn_config.pop("password", None) + # configure custom target hostname and port, if specified + snowflake_host = extra_dict.get("host") + snowflake_port = extra_dict.get("port") + if snowflake_host: + conn_config["host"] = snowflake_host + if snowflake_port: + conn_config["port"] = snowflake_port + return conn_config def get_uri(self) -> str: