use yaml instead of edn

This commit is contained in:
jerger 2022-12-30 17:59:40 +01:00
parent f254fccde2
commit 23b143f5af
3 changed files with 12 additions and 21 deletions

View file

@ -4,3 +4,4 @@ setuptools
dda-python-terraform==2.0.1 dda-python-terraform==2.0.1
packaging packaging
boto3 boto3
pyyaml

View file

@ -1,4 +1,5 @@
from os import chmod from os import chmod
import yaml
from .python_util import execute from .python_util import execute
from .devops_build import DevopsBuild from .devops_build import DevopsBuild
from .credential import gopass_field_from_path, gopass_password_from_path from .credential import gopass_field_from_path, gopass_password_from_path
@ -40,33 +41,22 @@ class C4kMixin(DevopsBuild):
'cluster-stage': self.stage}) 'cluster-stage': self.stage})
self.c4k_mixin_config.update({'mon-cfg': tmp}) self.c4k_mixin_config.update({'mon-cfg': tmp})
def __generate_clojure_map(self, template_dict):
clojure_map_str = '{'
for key, value in template_dict.items():
if isinstance(value, dict):
clojure_map_str += f':{key} {self.__generate_clojure_map(value)}\n'
else:
clojure_map_str += f':{key} "{value}"\n'
clojure_map_str += '}'
return clojure_map_str
def write_c4k_config(self): def write_c4k_config(self):
fqdn = self.get('fqdn') fqdn = self.get('fqdn')
self.c4k_mixin_config.update({'fqdn': fqdn}) self.c4k_mixin_config.update({'fqdn': fqdn})
with open(self.build_path() + '/out_config.edn', 'w', encoding="utf-8") as output_file: with open(self.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file:
output_file.write( yaml.dump(self.c4k_mixin_config, output_file)
self.__generate_clojure_map(self.c4k_mixin_config))
def write_c4k_auth(self): def write_c4k_auth(self):
with open(self.build_path() + '/out_auth.edn', 'w', encoding="utf-8") as output_file: with open(self.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file:
output_file.write(self.__generate_clojure_map(self.c4k_mixin_auth)) yaml.dump(self.c4k_mixin_auth, output_file)
chmod(self.build_path() + '/out_auth.edn', 0o600) chmod(self.build_path() + '/out_c4k_auth.yaml', 0o600)
def c4k_apply(self, dry_run=False): def c4k_apply(self, dry_run=False):
cmd = f'c4k-{self.c4k_module_name}-standalone.jar {self.build_path()}/out_config.edn {self.build_path()}/out_auth.edn > {self.build_path()}/out_{self.c4k_module_name}.yaml' cmd = f'c4k-{self.c4k_module_name}-standalone.jar {self.build_path()}/out_c4k_config.yaml {self.build_path()}/out_c4k_auth.yaml > {self.build_path()}/out_{self.c4k_module_name}.yaml'
output = '' output = ''
if dry_run: if dry_run:
print(" ".join(cmd)) print(cmd)
else: else:
output = execute(cmd, True) output = execute(cmd, True)
print(output) print(output)

View file

@ -40,9 +40,9 @@ def test_c4k_mixin(tmp_path):
mixin.write_c4k_config() mixin.write_c4k_config()
assert 'fqdn' in mixin.c4k_mixin_config assert 'fqdn' in mixin.c4k_mixin_config
assert 'mon-cfg' in mixin.c4k_mixin_config assert 'mon-cfg' in mixin.c4k_mixin_config
assert os.path.exists(f'{mixin.build_path()}/out_config.edn') assert os.path.exists(f'{mixin.build_path()}/out_c4k_config.yaml')
mixin.write_c4k_auth() mixin.write_c4k_auth()
assert 'mon-auth' in mixin.c4k_mixin_auth assert 'mon-auth' in mixin.c4k_mixin_auth
assert os.path.exists(f'{mixin.build_path()}/out_auth.edn') assert os.path.exists(f'{mixin.build_path()}/out_c4k_auth.yaml')