Skip to content

Commit 01ec265

Browse files
committed
SNOW-2306184: config refactor - simplify abstractions
1 parent c20ed4d commit 01ec265

26 files changed

+506
-6351
lines changed

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

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"""
1616
Enhanced Configuration System - Next Generation (NG)
1717
18-
This package implements a layered, extensible configuration system with:
19-
- Clear precedence rules (CLI > Environment > Files)
18+
This package implements a simple, extensible configuration system with:
19+
- List-order precedence (explicit ordering in source list)
2020
- Migration support (SnowCLI and SnowSQL compatibility)
2121
- Complete resolution history tracking
2222
- Read-only, immutable configuration sources
@@ -26,20 +26,8 @@
2626
ConfigValue,
2727
ResolutionEntry,
2828
ResolutionHistory,
29-
SourcePriority,
3029
ValueSource,
3130
)
32-
from snowflake.cli.api.config_ng.env_handlers import (
33-
SNOWSQL_TO_SNOWCLI_KEY_MAPPINGS,
34-
SnowCliEnvHandler,
35-
SnowSqlEnvHandler,
36-
)
37-
from snowflake.cli.api.config_ng.file_handlers import (
38-
SNOWSQL_CONFIG_KEY_MAPPINGS,
39-
IniFileHandler,
40-
TomlFileHandler,
41-
get_snowsql_config_paths,
42-
)
4331
from snowflake.cli.api.config_ng.resolution_logger import (
4432
check_value_source,
4533
explain_configuration,
@@ -56,38 +44,34 @@
5644
ResolutionHistoryTracker,
5745
)
5846
from snowflake.cli.api.config_ng.sources import (
59-
CliArgumentSource,
60-
ConfigurationSource,
61-
EnvironmentSource,
62-
FileSource,
47+
CliConfigFile,
48+
CliEnvironment,
49+
CliParameters,
50+
ConnectionsConfigFile,
51+
SnowSQLConfigFile,
52+
SnowSQLEnvironment,
6353
)
6454

6555
__all__ = [
6656
"check_value_source",
67-
"CliArgumentSource",
57+
"CliConfigFile",
58+
"CliEnvironment",
59+
"CliParameters",
6860
"ConfigurationResolver",
69-
"ConfigurationSource",
7061
"ConfigValue",
71-
"EnvironmentSource",
62+
"ConnectionsConfigFile",
7263
"explain_configuration",
7364
"export_resolution_history",
74-
"FileSource",
7565
"format_summary_for_display",
7666
"get_resolution_summary",
7767
"get_resolver",
78-
"get_snowsql_config_paths",
7968
"is_resolution_logging_available",
8069
"ResolutionEntry",
8170
"ResolutionHistory",
8271
"ResolutionHistoryTracker",
8372
"show_all_resolution_chains",
8473
"show_resolution_chain",
85-
"SnowCliEnvHandler",
86-
"SNOWSQL_CONFIG_KEY_MAPPINGS",
87-
"SNOWSQL_TO_SNOWCLI_KEY_MAPPINGS",
88-
"SnowSqlEnvHandler",
89-
"IniFileHandler",
90-
"SourcePriority",
91-
"TomlFileHandler",
74+
"SnowSQLConfigFile",
75+
"SnowSQLEnvironment",
9276
"ValueSource",
9377
]

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
Core abstractions for the enhanced configuration system.
1717
1818
This module implements the foundational data structures and interfaces:
19-
- SourcePriority: Defines precedence levels
2019
- ConfigValue: Immutable value container with provenance
2120
- ValueSource: Common protocol for all configuration sources
2221
- ResolutionHistory: Tracks the complete resolution process
@@ -27,21 +26,9 @@
2726
from abc import ABC, abstractmethod
2827
from dataclasses import dataclass, field
2928
from datetime import datetime
30-
from enum import Enum
3129
from typing import Any, Callable, Dict, List, Optional
3230

3331

34-
class SourcePriority(Enum):
35-
"""
36-
Defines top-level precedence for configuration sources.
37-
Lower numeric value = higher priority.
38-
"""
39-
40-
CLI_ARGUMENT = 1 # Highest: command-line arguments
41-
ENVIRONMENT = 2 # Medium: environment variables
42-
FILE = 3 # Lowest: configuration files
43-
44-
4532
@dataclass(frozen=True)
4633
class ConfigValue:
4734
"""
@@ -52,7 +39,6 @@ class ConfigValue:
5239
key: str
5340
value: Any
5441
source_name: str
55-
priority: SourcePriority
5642
raw_value: Optional[Any] = None
5743

5844
def __repr__(self) -> str:
@@ -68,17 +54,15 @@ def from_source(
6854
key: str,
6955
raw_value: str,
7056
source_name: str,
71-
priority: SourcePriority,
7257
value_parser: Optional[Callable[[str], Any]] = None,
7358
) -> ConfigValue:
7459
"""
75-
Factory method to create ConfigValue from a source handler.
60+
Factory method to create ConfigValue from a source.
7661
7762
Args:
7863
key: Configuration key
7964
raw_value: Raw string value from the source
8065
source_name: Name of the configuration source
81-
priority: Source priority level
8266
value_parser: Optional parser function; if None, raw_value is used as-is
8367
8468
Returns:
@@ -89,32 +73,26 @@ def from_source(
8973
key=key,
9074
value=parsed_value,
9175
source_name=source_name,
92-
priority=priority,
9376
raw_value=raw_value,
9477
)
9578

9679

9780
class ValueSource(ABC):
9881
"""
99-
Common interface for all configuration sources and handlers.
82+
Common interface for all configuration sources.
10083
All implementations are READ-ONLY discovery mechanisms.
84+
Precedence is determined by the order sources are provided to the resolver.
10185
"""
10286

10387
@property
10488
@abstractmethod
10589
def source_name(self) -> str:
10690
"""
10791
Unique identifier for this source.
108-
Examples: "cli_arguments", "snowflake_cli_env", "toml:connections"
92+
Examples: "cli_arguments", "snowsql_config", "cli_env"
10993
"""
11094
...
11195

112-
@property
113-
@abstractmethod
114-
def priority(self) -> SourcePriority:
115-
"""Top-level priority for this source."""
116-
...
117-
11896
@abstractmethod
11997
def discover(self, key: Optional[str] = None) -> Dict[str, ConfigValue]:
12098
"""
@@ -241,7 +219,6 @@ def to_dict(self) -> dict:
241219
"source": entry.config_value.source_name,
242220
"value": entry.config_value.value,
243221
"raw_value": entry.config_value.raw_value,
244-
"priority": entry.config_value.priority.name,
245222
"was_used": entry.was_used,
246223
"overridden_by": entry.overridden_by,
247224
"timestamp": entry.timestamp.isoformat(),

0 commit comments

Comments
 (0)