Coverage for savcfg/bootstrap.py: 100%

1"""Config service cons"""

2

3 from typing import Literal

4 from azure.identity import DefaultAzureCredential

5 from savcfg.keyvault import KeyVaultVars

6 from .read import ConfigService

7 from .edit import ConfigEditor

8

9

10 def get_savia_config_service(

11 env: Literal["prod", "pre", "devel"], app_name: str

12) -> ConfigService:

13 """Construct the config service for"""

14 readers = []

15 credential = DefaultAzureCredential()

16 match env:

17 case "prod":

18 readers = [

19 KeyVaultVars("savia-production", credential),

20 KeyVaultVars("savia-common", credential),

21 ]

22 case "pre":

23 readers = [

24 KeyVaultVars("savia-preproduction", credential),

25 KeyVaultVars("savia-common", credential),

26 ]

27 case "devel":

28 readers = [KeyVaultVars("savia-development", credential)]

29

30 return ConfigService(app_name, *readers)

31

32

33 def get_savia_config_editor(key: Literal["prod", "pre", "devel", "common"]):

34 var_editor = None

35 credential = DefaultAzureCredential()

36 match key:

37 case "prod":

38 var_editor = KeyVaultVars("savia-production", credential)

39 case "pre":

40 var_editor = KeyVaultVars("savia-preproduction", credential)

41 case "common":

42 var_editor = KeyVaultVars("savia-common", credential)

43 case "devel":

44 var_editor = KeyVaultVars("savia-development", credential)

45

46 return ConfigEditor(var_editor)