From 37aa2e3be99e4181a62d9329a3969c24548f5c53 Mon Sep 17 00:00:00 2001 From: Matthew Warren Date: Thu, 30 May 2024 16:01:53 -0400 Subject: [PATCH 1/3] sc-12773 use a more rigid regex for tfvars templating --- src/dynamic_importer/api/client.py | 3 +-- src/dynamic_importer/processors/__init__.py | 3 ++- src/dynamic_importer/processors/tf.py | 8 ++++++-- src/dynamic_importer/processors/tfvars.py | 9 +++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/dynamic_importer/api/client.py b/src/dynamic_importer/api/client.py index 15b66ff..92af6c1 100644 --- a/src/dynamic_importer/api/client.py +++ b/src/dynamic_importer/api/client.py @@ -305,7 +305,6 @@ def create_value( environment_id = self.create_environment(environment_name)["id"] parameter_id = self.create_parameter(project_name, parameter_name)["id"] - value = str(value) if isinstance(value, bool) else value resp = self._make_request( f"projects/{project_id}/parameters/{parameter_id}/values", "POST", @@ -329,7 +328,7 @@ def update_value( environment_id = self.get_environment_id(environment_name) parameter_id = self.get_parameter_id(project_name, parameter_name) - value = str(value) if isinstance(value, bool) else value + value = str(value).lower() if isinstance(value, bool) else value return self._make_request( f"projects/{project_id}/parameters/{parameter_id}/values/{value_id}", "PATCH", diff --git a/src/dynamic_importer/processors/__init__.py b/src/dynamic_importer/processors/__init__.py index ae333f0..f6afb28 100644 --- a/src/dynamic_importer/processors/__init__.py +++ b/src/dynamic_importer/processors/__init__.py @@ -158,9 +158,10 @@ def _traverse_data( if not hints: obj_type = self.guess_type(obj) param_name = self.path_to_param_name(path) + value = str(obj).lower() if obj_type == "boolean" else obj return f"{{{{ cloudtruth.parameters.{param_name} }}}}", { path: { - "values": {env: obj}, + "values": {env: value}, "param_name": param_name, "type": obj_type, "secret": self.is_param_secret(param_name), diff --git a/src/dynamic_importer/processors/tf.py b/src/dynamic_importer/processors/tf.py index 8533522..ccbfe1d 100644 --- a/src/dynamic_importer/processors/tf.py +++ b/src/dynamic_importer/processors/tf.py @@ -83,9 +83,12 @@ def _traverse_data( if set(obj.keys()) >= self.data_keys: if not hints: param_name = self.path_to_param_name(path) + value = ( + str(obj["default"]).lower() if obj["type"] == "boolean" else obj + ) return f"{{{{ cloudtruth.parameters.{param_name} }}}}", { path: { - "values": {env: obj["default"]}, + "values": {env: value}, "param_name": param_name, "description": obj.get("description", ""), "type": obj["type"], @@ -111,9 +114,10 @@ def _traverse_data( if not hints: obj_type = self.guess_type(obj) param_name = self.path_to_param_name(path) + value = str(obj).lower() if obj_type == "boolean" else obj return f"{{{{ cloudtruth.parameters.{param_name} }}}}", { path: { - "values": {env: obj}, + "values": {env: value}, "param_name": param_name, "type": obj_type, "secret": False, diff --git a/src/dynamic_importer/processors/tfvars.py b/src/dynamic_importer/processors/tfvars.py index 110facf..342d49a 100644 --- a/src/dynamic_importer/processors/tfvars.py +++ b/src/dynamic_importer/processors/tfvars.py @@ -42,8 +42,13 @@ def encode_template_references( environment = "default" if config_data: for _, data in config_data.items(): - value = str(data["values"][environment]) - reference = rf'{{{{ cloudtruth.parameters.{data["param_name"]} }}}}' + source_name = sub(r"_\d+", "", data["param_name"]) + value = ( + rf"({source_name})(\s*=\s*.*){str(data['values'][environment])}(.*)" + ) + reference = ( + rf'\1\2{{{{ cloudtruth.parameters.{data["param_name"]} }}}}\3' + ) template_body = sub(value, reference, template_body) return template_body From b34e8a7bb615ea8ba36d22772e790ddc5bb595d2 Mon Sep 17 00:00:00 2001 From: Matthew Warren Date: Thu, 30 May 2024 16:04:57 -0400 Subject: [PATCH 2/3] oops --- src/dynamic_importer/api/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dynamic_importer/api/client.py b/src/dynamic_importer/api/client.py index 92af6c1..ba413fb 100644 --- a/src/dynamic_importer/api/client.py +++ b/src/dynamic_importer/api/client.py @@ -305,6 +305,7 @@ def create_value( environment_id = self.create_environment(environment_name)["id"] parameter_id = self.create_parameter(project_name, parameter_name)["id"] + value = str(value).lower() if isinstance(value, bool) else value resp = self._make_request( f"projects/{project_id}/parameters/{parameter_id}/values", "POST", From e3ced6c188220ad955852bcd610abab643f970ed Mon Sep 17 00:00:00 2001 From: Matthew Warren Date: Thu, 30 May 2024 16:07:33 -0400 Subject: [PATCH 3/3] shrug --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2485664..c09ffb4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Config Catalyst automatically converts static config files in your repos into parameterized templates. It's the easiest way to "pay down config tech debt" with a single command. -We :heart: feedback, [bugs](https://github.com/cloudtruth/config-catalyst/issues/new), and [enhancement suggestions](https://github.com/cloudtruth/config-catalyst/issues/new). +We :heart: feedback, [bugs](https://github.com/cloudtruth/config-catalyst/issues/new), and [enhancement suggestions](https://github.com/cloudtruth/config-catalyst/issues/new). We also have a #config-catalyst channel [on our Discord](https://discord.com/invite/eBZXm9Tzr7). @@ -19,7 +19,7 @@ Config Catalyst exists to solve this problem: >"I need to take this weird network config that Bob (who left five years ago) roughed out by hand and turn it into a crisp little YAML template with parameterized variables." -Static, hard-coded config is a form of "tech debt" many teams want to eliminate, but the "pay it down" process is tedious and time-consuming. Until now. +Static, hard-coded config is a form of "tech debt" many teams want to eliminate, but the "pay it down" process is tedious and time-consuming. Until now. # How it works Config Catalyst works off of a local copy of your repo folder structure.