From 23b143f5af943fd7f00783561b32f41672150542 Mon Sep 17 00:00:00 2001 From: jerger Date: Fri, 30 Dec 2022 17:59:40 +0100 Subject: [PATCH] use yaml instead of edn --- requirements.txt | 3 ++- src/main/python/ddadevops/c4k_mixin.py | 26 ++++++++------------------ src/test/test_c4k_mixin.py | 4 ++-- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/requirements.txt b/requirements.txt index c4eaf68..7a391b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ deprecation setuptools dda-python-terraform==2.0.1 packaging -boto3 \ No newline at end of file +boto3 +pyyaml \ No newline at end of file diff --git a/src/main/python/ddadevops/c4k_mixin.py b/src/main/python/ddadevops/c4k_mixin.py index 3462157..6f5604c 100644 --- a/src/main/python/ddadevops/c4k_mixin.py +++ b/src/main/python/ddadevops/c4k_mixin.py @@ -1,4 +1,5 @@ from os import chmod +import yaml from .python_util import execute from .devops_build import DevopsBuild from .credential import gopass_field_from_path, gopass_password_from_path @@ -40,33 +41,22 @@ class C4kMixin(DevopsBuild): 'cluster-stage': self.stage}) 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): fqdn = self.get('fqdn') self.c4k_mixin_config.update({'fqdn': fqdn}) - with open(self.build_path() + '/out_config.edn', 'w', encoding="utf-8") as output_file: - output_file.write( - self.__generate_clojure_map(self.c4k_mixin_config)) + with open(self.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file: + yaml.dump(self.c4k_mixin_config, output_file) def write_c4k_auth(self): - with open(self.build_path() + '/out_auth.edn', 'w', encoding="utf-8") as output_file: - output_file.write(self.__generate_clojure_map(self.c4k_mixin_auth)) - chmod(self.build_path() + '/out_auth.edn', 0o600) + with open(self.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file: + yaml.dump(self.c4k_mixin_auth, output_file) + chmod(self.build_path() + '/out_c4k_auth.yaml', 0o600) 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 = '' if dry_run: - print(" ".join(cmd)) + print(cmd) else: output = execute(cmd, True) print(output) diff --git a/src/test/test_c4k_mixin.py b/src/test/test_c4k_mixin.py index 96049e4..eb16d53 100644 --- a/src/test/test_c4k_mixin.py +++ b/src/test/test_c4k_mixin.py @@ -40,9 +40,9 @@ def test_c4k_mixin(tmp_path): mixin.write_c4k_config() assert 'fqdn' 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() 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') \ No newline at end of file