Skip to content

Commit

Permalink
Add "env_label" override to BaseProjectConfig.get_stage_config
Browse files Browse the repository at this point in the history
When wanting to deploy stages outside of a CodePipeline context
there will still be a need to provide a `env_label`.
  • Loading branch information
njmei committed Jul 16, 2024
1 parent a3ae555 commit aadc219
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/aibs_informatics_cdk_lib/project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,21 @@ def get_global_config_cls(cls) -> Type[G]:
def get_stage_config_cls(cls) -> Type[S]:
return cls.model_fields["default_config"].annotation # type: ignore

def get_stage_config(self, env_type: Union[str, EnvType]) -> S:
def get_stage_config(
self, env_type: Union[str, EnvType], env_label: Optional[str] = None
) -> S:
"""Get default config with `EnvType` overrides"""

if env_label is None:
env_label_override = {}
else:
env_label_override = {"env": {"label": env_label}}

try:
return self.get_stage_config_cls().model_validate(
{
**DeepChainMap(
env_label_override,
self.default_config_overrides[EnvType(env_type)],
self.default_config.model_dump(mode="json", exclude_unset=True),
),
Expand Down
30 changes: 30 additions & 0 deletions test/aibs_informatics_cdk_lib/project/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,36 @@ def test__parse_file__test_loads_json_and_yml(self):
another_proj_config = ProjectConfig.load_config(proj_config_json_path)
self.assertEqual(proj_config, another_proj_config)

def test__get_stage_config__providing_an_optional_env_label_override(self):
global_config = create_global_config()
default_config = create_stage_config()

default_config_overrides = {
EnvType.DEV: {
"env": {
"env_type": "dev",
"label": "marmot",
"account": "111222333",
}
}
}
proj_config = ProjectConfig(
global_config=global_config,
default_config=default_config,
default_config_overrides=default_config_overrides,
)
expected_config = StageConfig.model_validate(
{
**default_config.model_copy().model_dump(exclude_unset=True),
}
)
expected_config.env.env_type = EnvType.DEV
expected_config.env.label = "overridelabel"
expected_config.env.account = "111222333"

resolved_config = proj_config.get_stage_config("dev", "overridelabel")
self.assertEqual(resolved_config, expected_config)


class ConfigProviderTests(BaseTest):
def test__get_stage_config__fails_with_invalid_env_type(self):
Expand Down

0 comments on commit aadc219

Please sign in to comment.