Skip to content

Commit

Permalink
feat: delete apiVersion from globalConfig.json and bump schemaVersion
Browse files Browse the repository at this point in the history
`apiVersion` from globalConfig is not used.
  • Loading branch information
artemrys authored and Artem Rys committed Aug 16, 2021
1 parent 5c930bf commit 6c22704
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .ucc-ui-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.8.4/splunk-ucc-ui.tgz
VERSION=v1.8.4
#https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.9.0/splunk-ucc-ui.tgz
VERSION=v1.9.0
14 changes: 12 additions & 2 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ def handle_biased_terms_update(schema_content: dict) -> dict:
return schema_content


def handle_dropping_api_version_update(schema_content: dict) -> dict:
if schema_content["meta"].get("apiVersion"):
del schema_content["meta"]["apiVersion"]
schema_content["meta"]["schemaVersion"] = "0.0.3"
return schema_content


def handle_update(config_path):
"""
handle changes in globalConfig.json
Expand All @@ -189,11 +196,9 @@ def handle_update(config_path):
with open(config_path, "w") as config_file:
json.dump(schema_content, config_file, ensure_ascii=False, indent=4)

# check for schemaVersion, if it's less than 0.0.2 then updating globalConfig.json
if version_tuple(version) < version_tuple("0.0.2"):
ta_tabs = schema_content.get("pages").get("configuration", {}).get("tabs", {})

# check for schema changes in configuration page of globalConfig.json
for tab in ta_tabs:
if tab["name"] == "account":
conf_entities = tab.get("entity")
Expand Down Expand Up @@ -256,6 +261,11 @@ def handle_update(config_path):
with open(config_path, "w") as config_file:
json.dump(schema_content, config_file, ensure_ascii=False, indent=4)

if version_tuple(version) < version_tuple("0.0.3"):
schema_content = handle_dropping_api_version_update(schema_content)
with open(config_path, "w") as config_file:
json.dump(schema_content, config_file, ensure_ascii=False, indent=4)

return schema_content


Expand Down
4 changes: 0 additions & 4 deletions splunk_add_on_ucc_framework/uccrestbuilder/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def namespace(self):
def admin_match(self):
return ""

@property
def version(self):
return self._meta["apiVersion"]

@property
def inputs(self):
return self._inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,10 @@
}
},
"meta": {
"apiVersion": "3.2.0",
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.6.2R6cc76bdf",
"version": "5.7.0Rc1c9ff9f",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.2"
"schemaVersion": "0.0.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,10 @@
}
],
"meta": {
"apiVersion": "3.2.0",
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.6.2R6cc76bdf",
"version": "5.7.0Rc1c9ff9f",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.2"
"schemaVersion": "0.0.3"
}
}
15 changes: 14 additions & 1 deletion tests/unit/test_config_file_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import unittest

import tests.unit.helpers as helpers
from splunk_add_on_ucc_framework import handle_biased_terms_update
from splunk_add_on_ucc_framework import (
handle_biased_terms_update,
handle_dropping_api_version_update,
)


class ConfigFileUpdateTest(unittest.TestCase):
Expand Down Expand Up @@ -49,3 +52,13 @@ def test_handle_biased_terms_update(self):
][0]["entity"][1]["options"].keys()
self.assertIn("allowList", configuration_entity_2_options_keys)
self.assertNotIn("whiteList", configuration_entity_2_options_keys)

def test_handle_dropping_api_version_update(self):
config = helpers.get_testdata_file("config_with_biased_terms.json")
config = json.loads(config)
updated_config = handle_dropping_api_version_update(config)
expected_schema_version = "0.0.3"
self.assertEqual(
expected_schema_version, updated_config["meta"]["schemaVersion"]
)
self.assertNotIn("apiVersion", updated_config["meta"])

0 comments on commit 6c22704

Please sign in to comment.