Skip to content

Commit 3ffe462

Browse files
committed
SNOW-2306184: config refactor - plugin tests in JSON format
1 parent 8a1a6c9 commit 3ffe462

File tree

5 files changed

+2825
-81
lines changed

5 files changed

+2825
-81
lines changed

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

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- CLI configuration files (TOML format, first-found)
2121
- Connections configuration files (dedicated connections.toml)
2222
- SnowSQL environment variables (SNOWSQL_* prefix)
23-
- CLI environment variables (SNOWFLAKE_* and SNOWFLAKE_CONNECTION_* patterns)
23+
- CLI environment variables (SNOWFLAKE_* patterns)
2424
- CLI command-line parameters
2525
2626
Precedence is determined by the order sources are provided to the resolver.
@@ -439,19 +439,17 @@ class CliEnvironment(ValueSource):
439439
"""
440440
CLI environment variables source.
441441
442-
Discovers SNOWFLAKE_* environment variables with three patterns:
442+
Discovers SNOWFLAKE_* environment variables with two patterns:
443443
1. General: SNOWFLAKE_ACCOUNT (applies to all connections)
444-
2. Connection-specific: SNOWFLAKE_CONNECTION_<name>_ACCOUNT (overrides general)
445-
3. Legacy connection-specific: SNOWFLAKE_CONNECTIONS_<name>_ACCOUNT (backward compatibility)
444+
2. Connection-specific: SNOWFLAKE_CONNECTIONS_<name>_ACCOUNT (overrides general)
446445
447446
Connection-specific variables take precedence within this source.
448447
449448
Examples:
450449
SNOWFLAKE_ACCOUNT -> account (general)
451-
SNOWFLAKE_CONNECTION_PROD_ACCOUNT -> account (for "prod" connection)
452-
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT -> account (for "integration" connection, legacy)
450+
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT -> account (for "integration" connection)
453451
SNOWFLAKE_USER -> user
454-
SNOWFLAKE_CONNECTION_DEV_USER -> user (for "dev" connection)
452+
SNOWFLAKE_CONNECTIONS_DEV_USER -> user (for "dev" connection)
455453
"""
456454

457455
# Base configuration keys that can be set via environment
@@ -500,8 +498,7 @@ def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
500498
501499
Patterns:
502500
1. SNOWFLAKE_ACCOUNT=x -> account=x (flat key)
503-
2. SNOWFLAKE_CONNECTION_PROD_ACCOUNT=y -> connections.prod.account=y
504-
3. SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT=z -> connections.integration.account=z (legacy)
501+
2. SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT=y -> connections.integration.account=y
505502
"""
506503
values: Dict[str, ConfigValue] = {}
507504

@@ -510,28 +507,8 @@ def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
510507
if not env_name.startswith("SNOWFLAKE_"):
511508
continue
512509

513-
# Check for connection-specific pattern: SNOWFLAKE_CONNECTION_<NAME>_<KEY>
514-
if env_name.startswith("SNOWFLAKE_CONNECTION_"):
515-
# Extract connection name and config key
516-
remainder = env_name[len("SNOWFLAKE_CONNECTION_") :]
517-
parts = remainder.split("_", 1)
518-
if len(parts) == 2:
519-
conn_name_upper, config_key_upper = parts
520-
conn_name = conn_name_upper.lower()
521-
config_key = config_key_upper.lower()
522-
523-
if config_key in self.CONFIG_KEYS:
524-
full_key = f"connections.{conn_name}.{config_key}"
525-
if key is None or full_key == key:
526-
values[full_key] = ConfigValue(
527-
key=full_key,
528-
value=env_value,
529-
source_name=self.source_name,
530-
raw_value=f"{env_name}={env_value}",
531-
)
532-
533-
# Check for legacy connection-specific pattern: SNOWFLAKE_CONNECTIONS_<NAME>_<KEY>
534-
elif env_name.startswith("SNOWFLAKE_CONNECTIONS_"):
510+
# Check for connection-specific pattern: SNOWFLAKE_CONNECTIONS_<NAME>_<KEY>
511+
if env_name.startswith("SNOWFLAKE_CONNECTIONS_"):
535512
# Extract connection name and config key
536513
remainder = env_name[len("SNOWFLAKE_CONNECTIONS_") :]
537514
parts = remainder.split("_", 1)
@@ -551,7 +528,7 @@ def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
551528
)
552529

553530
# Check for general pattern: SNOWFLAKE_<KEY>
554-
else:
531+
elif not env_name.startswith("SNOWFLAKE_CONNECTIONS_"):
555532
config_key_upper = env_name[len("SNOWFLAKE_") :]
556533
config_key = config_key_upper.lower()
557534

@@ -575,19 +552,12 @@ def supports_key(self, key: str) -> bool:
575552
if os.getenv(f"SNOWFLAKE_{key.upper()}") is not None:
576553
return True
577554

578-
# Check connection-specific var (new pattern)
555+
# Check connection-specific var
579556
if hasattr(self, "_connection_name") and self._connection_name:
580557
conn_var = (
581-
f"SNOWFLAKE_CONNECTION_{self._connection_name.upper()}_{key.upper()}"
582-
)
583-
if os.getenv(conn_var) is not None:
584-
return True
585-
586-
# Check legacy connection-specific var (legacy pattern)
587-
legacy_conn_var = (
588558
f"SNOWFLAKE_CONNECTIONS_{self._connection_name.upper()}_{key.upper()}"
589559
)
590-
if os.getenv(legacy_conn_var) is not None:
560+
if os.getenv(conn_var) is not None:
591561
return True
592562

593563
return False

0 commit comments

Comments
 (0)