Skip to content

Commit a40f502

Browse files
authored
remove secrets from config while parsing private config (ecmwf#269)
* remove secrets from dataloader while parsing private config
1 parent 8d6c346 commit a40f502

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/weathergen/utils/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def _format_cf(config: Config) -> str:
3838
stream = io.StringIO()
3939
for key, value in config.items():
4040
match key:
41-
case "secrets":
42-
continue
4341
case "streams":
4442
for rt in value:
4543
for k, v in rt.items():
@@ -103,7 +101,8 @@ def load_config(
103101
*overwrites: Path | dict | Config,
104102
) -> Config:
105103
"""
106-
Merge config information from multiple sources into one run_config.
104+
Merge config information from multiple sources into one run_config. Anything in the
105+
private configs "secrets" section will be discarted.
107106
108107
Args:
109108
private_home: Configuration file containing platform dependent information and secretes
@@ -211,6 +210,7 @@ def _load_private_conf(private_home: Path | None) -> DictConfig:
211210
private_cf["model_path"] = (
212211
private_cf["model_path"] if "model_path" in private_cf.keys() else "./models"
213212
)
213+
del private_cf["secrets"]
214214
return private_cf
215215

216216

tests/test_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def config_fresh(private_config_file):
150150

151151

152152
def test_contains_private(config_fresh):
153-
assert contains_keys(config_fresh, DUMMY_PRIVATE_CONF)
153+
sanitized_private_conf = DUMMY_PRIVATE_CONF.copy()
154+
del sanitized_private_conf["secrets"]
155+
assert contains_keys(config_fresh, sanitized_private_conf)
154156

155157

156158
@pytest.mark.parametrize("overwrite_dict", DUMMY_OVERWRITES, indirect=True)
@@ -207,9 +209,8 @@ def test_from_cli(options, cf):
207209

208210
def test_print_cf_no_secrets(config_fresh):
209211
output = config._format_cf(config_fresh)
210-
print(output)
211212

212-
assert "53CR3T" not in output
213+
assert "53CR3T" not in output and "secrets" not in config_fresh.keys()
213214

214215

215216
@pytest.mark.parametrize("streams_dir", VALID_STREAMS, indirect=True)

0 commit comments

Comments
 (0)