Skip to content

Commit

Permalink
feat: IDP Defaults
Browse files Browse the repository at this point in the history
Give the idp namespace the ability to bake in defaults, useful for
things such as default regions
  • Loading branch information
techman83 committed Mar 21, 2024
1 parent 2e70cf3 commit d0943ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cally/cli/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import yaml
from dynaconf import LazySettings

try:
from cally.idp.defaults import DEFAULTS as IDP_DEFAULTS # type: ignore
except ModuleNotFoundError:
IDP_DEFAULTS: dict = {} # type: ignore[no-redef]


def load(obj: LazySettings, *args, **kwargs) -> None: # noqa: ARG001
"""
Expand Down Expand Up @@ -31,6 +36,7 @@ def load(obj: LazySettings, *args, **kwargs) -> None: # noqa: ARG001
loaded = yaml.safe_load(config_file.read_text())

# Defaults
obj.update(IDP_DEFAULTS)
obj.update(loaded.get('defaults', {}))
if obj.cally_env is not None:
obj.update(environment=obj.cally_env)
Expand Down
17 changes: 17 additions & 0 deletions tests/cli/config/test_idp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from cally.cli.config import CallyConfig

from ... import CallyIdpTestHarness


class CallyIdpConfigTests(CallyIdpTestHarness):

def test_idp_defaults(self):
config = CallyConfig(config_file='blah.yaml')
config.environment = 'harness'
config.service = 'idp-defaults-ya'
data = {
'ENVIRONMENT': 'harness',
'NAME': 'idp-defaults-ya',
'PROVIDERS': {'provido': {'location': 'some-place1'}},
}
self.assertDictEqual(config.settings.to_dict(), data)
1 change: 1 addition & 0 deletions tests/testdata/test_cls/cally/idp/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULTS = {'providers': {'provido': {'location': 'some-place1'}}}

0 comments on commit d0943ce

Please sign in to comment.