diff --git a/splunk_add_on_ucc_framework/commands/build.py b/splunk_add_on_ucc_framework/commands/build.py index 0340171f4..9633aa225 100644 --- a/splunk_add_on_ucc_framework/commands/build.py +++ b/splunk_add_on_ucc_framework/commands/build.py @@ -446,6 +446,7 @@ def generate( if gc_path: logger.info(f"Using globalConfig file located @ {gc_path}") global_config = global_config_lib.GlobalConfig(gc_path) + global_config.cleanup_unwanted_params() # handle the update of globalConfig before validating global_config_update.handle_global_config_update(global_config) try: @@ -458,11 +459,11 @@ def generate( logger.error(f"globalConfig file is not valid. Error: {e}") sys.exit(1) global_config.update_addon_version(addon_version) - global_config.add_ucc_version(__version__) global_config.dump(global_config.original_path) logger.info( f"Updated and saved add-on version in the globalConfig file to {addon_version}" ) + global_config.add_ucc_version(__version__) global_config.expand() if ta_name != global_config.product: logger.error( diff --git a/splunk_add_on_ucc_framework/global_config.py b/splunk_add_on_ucc_framework/global_config.py index 80193dc1e..09716b0d1 100644 --- a/splunk_add_on_ucc_framework/global_config.py +++ b/splunk_add_on_ucc_framework/global_config.py @@ -197,6 +197,10 @@ def update_schema_version(self, new_schema_version: str) -> None: def update_addon_version(self, version: str) -> None: self._content.setdefault("meta", {})["version"] = version + def cleanup_unwanted_params(self) -> None: + if "_uccVersion" in self.content["meta"]: + del self.content["meta"]["_uccVersion"] + def add_ucc_version(self, version: str) -> None: self.content.setdefault("meta", {})["_uccVersion"] = version diff --git a/splunk_add_on_ucc_framework/schema/schema.json b/splunk_add_on_ucc_framework/schema/schema.json index 1999b670f..5f4e2e444 100644 --- a/splunk_add_on_ucc_framework/schema/schema.json +++ b/splunk_add_on_ucc_framework/schema/schema.json @@ -2083,7 +2083,7 @@ }, "_uccVersion": { "type": "string", - "description": "Version of UCC used during build process" + "description": "Version of UCC used during build process. Do not use." }, "hideUCCVersion": { "type": "boolean", diff --git a/tests/smoke/test_ucc_build.py b/tests/smoke/test_ucc_build.py index 0620e5b33..1566a4108 100644 --- a/tests/smoke/test_ucc_build.py +++ b/tests/smoke/test_ucc_build.py @@ -62,7 +62,7 @@ def test_ucc_generate_with_config_param(): """ def check_ucc_versions(parent_folder): - global_config_path = path.join( + gc_appserver = path.join( parent_folder, "Splunk_TA_UCCExample", "appserver", @@ -71,12 +71,18 @@ def check_ucc_versions(parent_folder): "build", "globalConfig.json", ) + gc_root = config_path - with open(global_config_path) as _f: + with open(gc_appserver) as _f: global_config = json.load(_f) assert global_config["meta"]["_uccVersion"] == __version__ + with open(gc_root) as _f: + global_config = json.load(_f) + + assert "_uccVersion" not in global_config["meta"] + package_folder = path.join( path.dirname(path.realpath(__file__)), "..", @@ -94,6 +100,14 @@ def check_ucc_versions(parent_folder): "globalConfig.json", ) with tempfile.TemporaryDirectory(prefix="ucc") as temp: + with open(config_path) as fp: + cfg = json.load(fp) + + cfg["meta"]["_uccVersion"] = "0.0.1" + + with open(config_path, "w") as fp: + json.dump(cfg, fp) + build.generate( source=package_folder, config_path=config_path, output_directory=temp ) diff --git a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json index a2cc7192a..0dcdc2c80 100644 --- a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json +++ b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json @@ -199,9 +199,8 @@ "meta": { "name": "test_addon", "restRoot": "test_addon", - "version": "5.50.1+099cf36c", + "version": "5.55.0+dcdb201e", "displayName": "This is my add-on", - "schemaVersion": "0.0.8", - "_uccVersion": "5.50.1" + "schemaVersion": "0.0.9" } } diff --git a/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json b/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json index 205374eab..71f224258 100644 --- a/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_configuration/globalConfig.json @@ -387,7 +387,6 @@ "restRoot": "splunk_ta_uccexample", "version": "1.1.1", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.7", - "_uccVersion": "5.50.1" + "schemaVersion": "0.0.9" } } diff --git a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json index 8ec3bff2d..5cf04d258 100644 --- a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json @@ -1907,10 +1907,9 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.55.0+e45124ce1", + "version": "5.55.0+36810ea3", "displayName": "Splunk UCC test Add-on", "schemaVersion": "0.0.9", - "_uccVersion": "5.55.0", "supportedThemes": [ "light", "dark" diff --git a/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json b/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json index 664c89d90..739032266 100644 --- a/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json @@ -1171,9 +1171,8 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.50.1+099cf36c", + "version": "5.55.0+dcdb201e", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.8", - "_uccVersion": "5.50.1" + "schemaVersion": "0.0.9" } } diff --git a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json index b6393c616..1893806f1 100644 --- a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json @@ -694,9 +694,8 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.52.0+2e44cba94", + "version": "5.55.0+dcdb201e", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.9", - "_uccVersion": "5.52.0" + "schemaVersion": "0.0.9" } } diff --git a/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json b/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json index 11c9b2575..b4ba2a5f5 100644 --- a/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json @@ -36,9 +36,8 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.50.1+099cf36c", + "version": "5.55.0+dcdb201e", "displayName": "Splunk UCC test Add-on", - "schemaVersion": "0.0.7", - "_uccVersion": "5.50.1" + "schemaVersion": "0.0.9" } } diff --git a/tests/unit/test_global_config.py b/tests/unit/test_global_config.py index 721062034..6759bffa8 100644 --- a/tests/unit/test_global_config.py +++ b/tests/unit/test_global_config.py @@ -1,4 +1,6 @@ import itertools +import json +import os.path from typing import Any, Iterator import pytest @@ -99,6 +101,41 @@ def test_global_config_expand(tmp_path): assert count_entities(global_config, type="text", field="interval") == 3 +def test_global_config_cleanup_unwanted_params(global_config_only_logging, tmp_path): + global_config_path = helpers.get_testdata_file_path("valid_config.json") + + with open(global_config_path) as fp: + content = json.load(fp) + + content["meta"]["_uccVersion"] = "1.0.0" + + new_path = os.path.join(tmp_path, "config.json") + + with open(new_path, "w") as fp: + json.dump(content, fp) + + global_config = global_config_lib.GlobalConfig(new_path) + + assert global_config.content["meta"].get("_uccVersion") == "1.0.0" + + global_config.cleanup_unwanted_params() + + assert "_uccVersion" not in global_config.content["meta"] + + +def test_global_config_add_ucc_version(global_config_only_logging, tmp_path): + global_config_path = helpers.get_testdata_file_path("valid_config.json") + global_config = global_config_lib.GlobalConfig(global_config_path) + + assert "_uccVersion" not in global_config.content["meta"] + global_config.add_ucc_version("1.0.0") + assert ( + global_config.content["meta"].get("_uccVersion") + == global_config.ucc_version + == "1.0.0" + ) + + def all_entities(gc: global_config_lib.GlobalConfig) -> Iterator[Any]: objects = itertools.chain(gc.tabs, gc.alerts, gc.inputs) return itertools.chain(*(obj["entity"] for obj in objects if "entity" in obj))