Skip to content

Commit 5deaf40

Browse files
committed
SNOW-2306184: config refactory - top tier configuration sources
1 parent 0c22b9f commit 5deaf40

File tree

7 files changed

+1759
-0
lines changed

7 files changed

+1759
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@
2929
SourcePriority,
3030
ValueSource,
3131
)
32+
from snowflake.cli.api.config_ng.sources import (
33+
CliArgumentSource,
34+
ConfigurationSource,
35+
EnvironmentSource,
36+
FileSource,
37+
)
3238

3339
__all__ = [
40+
"CliArgumentSource",
41+
"ConfigurationSource",
3442
"ConfigValue",
43+
"EnvironmentSource",
44+
"FileSource",
3545
"ResolutionEntry",
3646
"ResolutionHistory",
3747
"SourcePriority",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) 2024 Snowflake Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Configuration handlers for specific formats and schemas.
17+
18+
This module will implement specific handlers for:
19+
- Environment variables (SNOWFLAKE_*, SNOWSQL_*)
20+
- File formats (TOML, SnowSQL config, JSON, YAML)
21+
22+
To be implemented in Phase 3-4.
23+
"""
24+
25+
from __future__ import annotations
26+
27+
from abc import abstractmethod
28+
from pathlib import Path
29+
from typing import Dict, Optional
30+
31+
from snowflake.cli.api.config_ng.core import ConfigValue, ValueSource
32+
33+
34+
class SourceHandler(ValueSource):
35+
"""
36+
Specific handler for a configuration format or schema.
37+
Examples: TOML files, SnowSQL config, SNOWFLAKE_* env vars, etc.
38+
"""
39+
40+
@property
41+
@abstractmethod
42+
def handler_type(self) -> str:
43+
"""
44+
Type identifier for this handler.
45+
Examples: 'toml', 'json', 'snowsql_env', 'snowsql_config'
46+
"""
47+
...
48+
49+
@abstractmethod
50+
def can_handle(self) -> bool:
51+
"""
52+
Check if this handler is applicable/available.
53+
54+
Returns:
55+
True if handler can be used, False otherwise
56+
"""
57+
...
58+
59+
def can_handle_file(self, file_path: Path) -> bool:
60+
"""
61+
Check if this handler can process the given file.
62+
63+
Args:
64+
file_path: Path to file to check
65+
66+
Returns:
67+
True if handler can process this file, False otherwise
68+
"""
69+
return False
70+
71+
def discover_from_file(
72+
self, file_path: Path, key: Optional[str] = None
73+
) -> Dict[str, ConfigValue]:
74+
"""
75+
Discover values from a file.
76+
77+
Args:
78+
file_path: Path to file to read
79+
key: Specific key to discover, or None for all
80+
81+
Returns:
82+
Dictionary of discovered values
83+
"""
84+
return {}

0 commit comments

Comments
 (0)