Skip to content

Commit

Permalink
Merge pull request #92 from splunk/feature/ta-version-param
Browse files Browse the repository at this point in the history
feat: supporting the new version mechanism
  • Loading branch information
arjunkhunti-crest authored Jan 21, 2021
2 parents 7c402c1 + 1768138 commit 8085717
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,18 @@ def remove_listed_files(ignore_list):
else:
logger.info("While ignoring the files mentioned in .uccignore {} was not found".format(path))

def update_ta_version(args):
def update_ta_version(config, ta_version):
"""
Update version of TA in globalConfig.json.
Args:
args (argparse.Namespace): Object with command-line arguments.
"""

with open(args.config, "r") as config_file:
with open(config, "r") as config_file:
schema_content = json.load(config_file)
schema_content.setdefault("meta", {})["version"] = args.ta_version
with open(args.config, "w") as config_file:
schema_content.setdefault("meta", {})["version"] = ta_version
with open(config, "w") as config_file:
json.dump(schema_content, config_file, indent=4)

def handle_no_inputs(ta_name):
Expand Down Expand Up @@ -619,7 +619,9 @@ def main():
default = version_splunk
)
args = parser.parse_args()

ta_version = args.ta_version.strip()
if not ta_version:
ta_version = version_splunk
if not os.path.exists(args.source):
raise NotADirectoryError("{} not Found.".format(os.path.abspath(args.source)))

Expand All @@ -635,16 +637,15 @@ def main():
ta_name = manifest['info']['id']['name']

if os.path.exists(args.config):

if args.ta_version:
update_ta_version(args)
update_ta_version(args.config, ta_version)

# handle_update check schemaVersion and update globalConfig.json if required and return schema
schema_content = handle_update(args.config)

scheme = GlobalConfigBuilderSchema(schema_content, j2_env)

ta_version = schema_content.get("meta").get("version")
logger.info("Addon Version : " + ta_version)
ta_tabs = schema_content.get("pages").get("configuration").get("tabs")
ta_namespace = schema_content.get("meta").get("restRoot")
import_declare_name = "import_declare_test"
Expand Down Expand Up @@ -686,6 +687,7 @@ def main():
make_modular_alerts(args, ta_name, ta_namespace, schema_content)

else:
logger.info("Addon Version : " + ta_version)
logger.warning("Skipped installing UCC required python modules as GlobalConfig.json does not exist.")
logger.warning("Skipped Generating UI components as GlobalConfig.json does not exist.")
logger.info("Setting TA name as generic")
Expand All @@ -705,13 +707,13 @@ def main():
with open(os.path.join(outputdir, ta_name,'VERSION'), 'w') as version_file:
version_file.write(version_str)
version_file.write("\n")
version_file.write(version_splunk)
version_file.write(ta_version)


manifest= None
with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "r") as manifest_file:
manifest = json.load(manifest_file)
manifest['info']['id']['version'] = version_splunk
manifest['info']['id']['version'] = ta_version


with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "w") as manifest_file:
Expand All @@ -731,10 +733,10 @@ def main():
if not 'ui' in app_config:
app_config.add_section('ui')

app_config['launcher']['version']=version_splunk
app_config['launcher']['version'] = ta_version
app_config['launcher']['description']=manifest['info']['description']

app_config['id']['version']=version_splunk
app_config['id']['version'] = ta_version

app_config['install']['build']=str(int(time.time()))
app_config['package']['id']=manifest['info']['id']['name']
Expand Down

0 comments on commit 8085717

Please sign in to comment.