Skip to content

Commit 4357f8b

Browse files
committed
SNOW-2306184: config refactor - tests for value masking
1 parent b849f52 commit 4357f8b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/snowflake/cli/api/config.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from typing import (
2424
Any,
2525
Dict,
26+
Final,
2627
List,
2728
Literal,
2829
Optional,
@@ -91,6 +92,12 @@ class Empty:
9192
FEATURE_FLAGS_SECTION_PATH = [CLI_SECTION, "features"]
9293

9394

95+
LEGACY_OAUTH_PKCE_KEY: Literal["oatuh_enable_pkce"] = "oatuh_enable_pkce"
96+
LEGACY_CONNECTION_SETTING_ALIASES: Final[dict[str, str]] = {
97+
LEGACY_OAUTH_PKCE_KEY: "oauth_enable_pkce",
98+
}
99+
100+
94101
@dataclass
95102
class ConnectionConfig:
96103
account: Optional[str] = None
@@ -130,12 +137,17 @@ def from_dict(cls, config_dict: dict) -> ConnectionConfig:
130137
known_settings = {}
131138
other_settings = {}
132139
for key, value in config_dict.items():
133-
if key in cls.__dict__:
134-
known_settings[key] = value
140+
normalized_key = cls._normalize_setting_key(key)
141+
if normalized_key in cls.__dict__:
142+
known_settings[normalized_key] = value
135143
else:
136144
other_settings[key] = value
137145
return cls(**known_settings, _other_settings=other_settings)
138146

147+
@staticmethod
148+
def _normalize_setting_key(key: str) -> str:
149+
return LEGACY_CONNECTION_SETTING_ALIASES.get(key, key)
150+
139151
def to_dict_of_known_non_empty_values(self) -> dict:
140152
return {
141153
k: v
@@ -340,7 +352,9 @@ def get_connection_dict(connection_name: str) -> dict:
340352
from snowflake.cli.api.config_provider import get_config_provider_singleton
341353

342354
provider = get_config_provider_singleton()
343-
return provider.get_connection_dict(connection_name)
355+
connection_raw = provider.get_connection_dict(connection_name)
356+
connection = ConnectionConfig.from_dict(connection_raw)
357+
return connection.to_dict_of_all_non_empty_values()
344358

345359

346360
def get_default_connection_name() -> str:

tests/test_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ def test_environment_variables_works_if_config_value_not_present(test_snowcli_co
111111
}
112112

113113

114+
def test_legacy_pkce_key_is_normalized(config_file):
115+
config_content = """
116+
[connections.test]
117+
account = "legacy"
118+
oatuh_enable_pkce = true
119+
"""
120+
with config_file(config_content) as cfg:
121+
config_init(cfg)
122+
123+
conn = get_connection_dict("test")
124+
125+
assert conn["account"] == "legacy"
126+
assert conn["oauth_enable_pkce"] is True
127+
assert "oatuh_enable_pkce" not in conn
128+
129+
114130
@mock.patch.dict(
115131
os.environ,
116132
{

0 commit comments

Comments
 (0)