Skip to content

Commit 74d35b6

Browse files
committed
SNOW-2306184: config refactor - cli env update
1 parent e1410d5 commit 74d35b6

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/snowflake/cli/api/config_ng/sources.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,17 @@ class CliEnvironment(ValueSource):
355355
"""
356356
CLI environment variables source.
357357
358-
Discovers SNOWFLAKE_* environment variables with two patterns:
358+
Discovers SNOWFLAKE_* environment variables with three patterns:
359359
1. General: SNOWFLAKE_ACCOUNT (applies to all connections)
360360
2. Connection-specific: SNOWFLAKE_CONNECTION_<name>_ACCOUNT (overrides general)
361+
3. Legacy connection-specific: SNOWFLAKE_CONNECTIONS_<name>_ACCOUNT (backward compatibility)
361362
362363
Connection-specific variables take precedence within this source.
363364
364365
Examples:
365366
SNOWFLAKE_ACCOUNT -> account (general)
366367
SNOWFLAKE_CONNECTION_PROD_ACCOUNT -> account (for "prod" connection)
368+
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT -> account (for "integration" connection, legacy)
367369
SNOWFLAKE_USER -> user
368370
SNOWFLAKE_CONNECTION_DEV_USER -> user (for "dev" connection)
369371
"""
@@ -382,6 +384,21 @@ class CliEnvironment(ValueSource):
382384
"port",
383385
"region",
384386
"authenticator",
387+
"workload_identity_provider",
388+
"private_key_file",
389+
"private_key_path", # Used by integration tests
390+
"private_key_raw", # Used by integration tests
391+
"token_file_path",
392+
"oauth_client_id",
393+
"oauth_client_secret",
394+
"oauth_authorization_url",
395+
"oauth_token_request_url",
396+
"oauth_redirect_uri",
397+
"oauth_scope",
398+
"oatuh_enable_pkce",
399+
"oauth_enable_refresh_tokens",
400+
"oauth_enable_single_use_refresh_tokens",
401+
"client_store_temporary_credential",
385402
]
386403

387404
@property
@@ -396,6 +413,7 @@ def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
396413
Patterns:
397414
1. SNOWFLAKE_ACCOUNT=x -> account=x (flat key)
398415
2. SNOWFLAKE_CONNECTION_PROD_ACCOUNT=y -> connections.prod.account=y
416+
3. SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT=z -> connections.integration.account=z (legacy)
399417
"""
400418
values: Dict[str, ConfigValue] = {}
401419

@@ -424,6 +442,26 @@ def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
424442
raw_value=f"{env_name}={env_value}",
425443
)
426444

445+
# Check for legacy connection-specific pattern: SNOWFLAKE_CONNECTIONS_<NAME>_<KEY>
446+
elif env_name.startswith("SNOWFLAKE_CONNECTIONS_"):
447+
# Extract connection name and config key
448+
remainder = env_name[len("SNOWFLAKE_CONNECTIONS_") :]
449+
parts = remainder.split("_", 1)
450+
if len(parts) == 2:
451+
conn_name_upper, config_key_upper = parts
452+
conn_name = conn_name_upper.lower()
453+
config_key = config_key_upper.lower()
454+
455+
if config_key in self.CONFIG_KEYS:
456+
full_key = f"connections.{conn_name}.{config_key}"
457+
if key is None or full_key == key:
458+
values[full_key] = ConfigValue(
459+
key=full_key,
460+
value=env_value,
461+
source_name=self.source_name,
462+
raw_value=f"{env_name}={env_value}",
463+
)
464+
427465
# Check for general pattern: SNOWFLAKE_<KEY>
428466
else:
429467
config_key_upper = env_name[len("SNOWFLAKE_") :]
@@ -449,14 +487,21 @@ def supports_key(self, key: str) -> bool:
449487
if os.getenv(f"SNOWFLAKE_{key.upper()}") is not None:
450488
return True
451489

452-
# Check connection-specific var
453-
if self._connection_name:
490+
# Check connection-specific var (new pattern)
491+
if hasattr(self, "_connection_name") and self._connection_name:
454492
conn_var = (
455493
f"SNOWFLAKE_CONNECTION_{self._connection_name.upper()}_{key.upper()}"
456494
)
457495
if os.getenv(conn_var) is not None:
458496
return True
459497

498+
# Check legacy connection-specific var (legacy pattern)
499+
legacy_conn_var = (
500+
f"SNOWFLAKE_CONNECTIONS_{self._connection_name.upper()}_{key.upper()}"
501+
)
502+
if os.getenv(legacy_conn_var) is not None:
503+
return True
504+
460505
return False
461506

462507

0 commit comments

Comments
 (0)