use yaml instead of edn

merge-requests/7/merge
jerger 1 year ago
parent f254fccde2
commit 23b143f5af

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

@ -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)

@ -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')
Loading…
Cancel
Save