Skip to content

Commit

Permalink
feat: do not add _uccVersion to the root globalConfig file (#1519)
Browse files Browse the repository at this point in the history
### PR Type

**What kind of change does this PR introduce?**
* [x] Feature
* [ ] Bug Fix
* [ ] Refactoring (no functional or API changes)
* [ ] Documentation Update
* [ ] Maintenance (dependency updates, CI, etc.)

## Summary

### Changes

Now `_uccVersion` is not added to the root `globalConfig.json`. Only to
the `appserver/static/js/build/globalConfig.json`.

If `_uccVersion` is specified in the root `globalConfig.json`, it is
removed.

### User experience

No `_uccVersion` in the root `globalConfig.json`.

## Checklist

If an item doesn't apply to your changes, leave it unchecked.

* [x] I have performed a self-review of this change according to the
[development
guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines)
* [x] Tests have been added/modified to cover the changes [(testing
doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test)
* [ ] Changes are documented
* [x] PR title and description follows the [contributing
principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)
  • Loading branch information
kkedziak-splunk authored Jan 3, 2025
1 parent 00b3b89 commit 0beab3b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 20 deletions.
3 changes: 2 additions & 1 deletion splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions splunk_add_on_ucc_framework/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions tests/smoke/test_ucc_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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__)),
"..",
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
37 changes: 37 additions & 0 deletions tests/unit/test_global_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import itertools
import json
import os.path
from typing import Any, Iterator

import pytest
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0beab3b

Please sign in to comment.