From 13664c08c28acc24d56fec1ba7a4910097e50d8c Mon Sep 17 00:00:00 2001 From: harshpatel-crest Date: Mon, 31 May 2021 15:04:33 +0530 Subject: [PATCH] chore: update ucc ui and revert commit: 6d0850982cb7f5fe69387f364dcec2877d00e3dd --- .ucc-ui-version | 2 +- pyproject.toml | 4 - splunk_add_on_ucc_framework/__init__.py | 160 ++++++++++++------------ 3 files changed, 81 insertions(+), 85 deletions(-) diff --git a/.ucc-ui-version b/.ucc-ui-version index f0d805009..bbd422197 100644 --- a/.ucc-ui-version +++ b/.ucc-ui-version @@ -1,2 +1,2 @@ #https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.5.0/splunk-ucc-ui.tgz -VERSION=v1.5.0 +VERSION=v1.5.6 diff --git a/pyproject.toml b/pyproject.toml index b5c25643c..acfa518ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,10 +7,6 @@ name = "splunk_add_on_ucc_framework" version = "0.0.0" description = "Splunk Add-on SDK formerly UCC is a build and code generation framework" authors = ["rfaircloth-splunk "] -exclude = [ - "build.py", - "splunk_add_on_ucc_framework/ucc_ui_lib/", - ] include = [ "splunk_add_on_ucc_framework/package", "splunk_add_on_ucc_framework/package/locale", diff --git a/splunk_add_on_ucc_framework/__init__.py b/splunk_add_on_ucc_framework/__init__.py index 98a3bc8a0..98d65c514 100644 --- a/splunk_add_on_ucc_framework/__init__.py +++ b/splunk_add_on_ucc_framework/__init__.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -__version__ = "0.0.0" +__version__ = "4.5.0" import logging import os, time @@ -240,7 +240,7 @@ def replace_token(args, ta_name): # replace token in template logger.info("Replace tokens in views") - # views = ["inputs.xml", "configuration.xml", "redirect.xml"] + views = ["inputs.xml", "configuration.xml", "redirect.xml"] views = ["inputs.xml", "configuration.xml"] for view in views: template_dir = os.path.join( @@ -252,8 +252,8 @@ def replace_token(args, ta_name): # Safely write the changed content, if found in the file with open(os.path.join(template_dir, view), "w") as f: s = s.replace("${package.name}", ta_name) - # if view == "redirect.xml": - # s = s.replace("${ta.name}", ta_name.lower()) + if view == "redirect.xml": + s = s.replace("${ta.name}", ta_name.lower()) f.write(s) def install_libs(path, ucc_lib_target): @@ -371,79 +371,79 @@ def is_oauth_configured(ta_tabs): return False -# def replace_oauth_html_template_token(args, ta_name, ta_version): -# """ -# Replace tokens with addon name and version in redirect.html. - -# Args: -# args (argparse.Namespace): Object with command-line arguments. -# ta_name (str): Name of TA. -# ta_version (str): Version of TA. -# """ - -# html_template_path = os.path.join( -# outputdir, ta_name, "appserver", "templates" -# ) -# with open(os.path.join(html_template_path, "redirect.html")) as f: -# s = f.read() - -# # Safely write the changed content, if found in the file -# with open(os.path.join(html_template_path, "redirect.html"), "w") as f: -# # replace addon name in html template -# s = s.replace("${ta.name}", ta_name.lower()) -# # replace addon version in html template -# s = s.replace("${ta.version}", ta_version) -# f.write(s) - - -# def modify_and_replace_token_for_oauth_templates( -# args, ta_name, ta_tabs, ta_version -# ): -# """ -# Rename templates with respect to addon name if OAuth is configured. - -# Args: -# args (argparse.Namespace): Object with command-line arguments. -# ta_name (str): Name of TA. -# ta_version (str): Version of TA. -# ta_tabs (list): List of tabs mentioned in globalConfig.json. - -# """ -# redirect_xml_src = os.path.join( -# outputdir, ta_name, "default", "data", "ui", "views", "redirect.xml" -# ) -# redirect_js_src = os.path.join( -# outputdir, ta_name, "appserver", "static", "js", "build", "redirect_page.js" -# ) -# redirect_html_src = os.path.join( -# outputdir, ta_name, "appserver", "templates", "redirect.html" -# ) - -# if is_oauth_configured(ta_tabs): -# replace_oauth_html_template_token(args, ta_name, ta_version) - -# redirect_js_dest = ( -# os.path.join(outputdir, ta_name, "appserver", "static", "js", "build", "") -# + ta_name.lower() -# + "_redirect_page." -# + ta_version -# + ".js" -# ) -# redirect_html_dest = ( -# os.path.join(outputdir, ta_name, "appserver", "templates", ta_name.lower() + "_redirect.html") -# ) -# redirect_xml_dest = ( -# os.path.join(outputdir, ta_name, "default", "data", "ui", "views", ta_name.lower() + "_redirect.xml") -# ) -# os.rename(redirect_js_src, redirect_js_dest) -# os.rename(redirect_html_src, redirect_html_dest) -# os.rename(redirect_xml_src, redirect_xml_dest) - -# # if oauth is not configured remove the extra template -# else: -# os.remove(redirect_xml_src) -# os.remove(redirect_html_src) -# os.remove(redirect_js_src) +def replace_oauth_html_template_token(args, ta_name, ta_version): + """ + Replace tokens with addon name and version in redirect.html. + + Args: + args (argparse.Namespace): Object with command-line arguments. + ta_name (str): Name of TA. + ta_version (str): Version of TA. + """ + + html_template_path = os.path.join( + outputdir, ta_name, "appserver", "templates" + ) + with open(os.path.join(html_template_path, "redirect.html")) as f: + s = f.read() + + # Safely write the changed content, if found in the file + with open(os.path.join(html_template_path, "redirect.html"), "w") as f: + # replace addon name in html template + s = s.replace("${ta.name}", ta_name.lower()) + # replace addon version in html template + s = s.replace("${ta.version}", ta_version) + f.write(s) + + +def modify_and_replace_token_for_oauth_templates( + args, ta_name, ta_tabs, ta_version +): + """ + Rename templates with respect to addon name if OAuth is configured. + + Args: + args (argparse.Namespace): Object with command-line arguments. + ta_name (str): Name of TA. + ta_version (str): Version of TA. + ta_tabs (list): List of tabs mentioned in globalConfig.json. + + """ + redirect_xml_src = os.path.join( + outputdir, ta_name, "default", "data", "ui", "views", "redirect.xml" + ) + redirect_js_src = os.path.join( + outputdir, ta_name, "appserver", "static", "js", "build", "redirect_page.js" + ) + redirect_html_src = os.path.join( + outputdir, ta_name, "appserver", "templates", "redirect.html" + ) + + if is_oauth_configured(ta_tabs): + replace_oauth_html_template_token(args, ta_name, ta_version) + + redirect_js_dest = ( + os.path.join(outputdir, ta_name, "appserver", "static", "js", "build", "") + + ta_name.lower() + + "_redirect_page." + + ta_version + + ".js" + ) + redirect_html_dest = ( + os.path.join(outputdir, ta_name, "appserver", "templates", ta_name.lower() + "_redirect.html") + ) + redirect_xml_dest = ( + os.path.join(outputdir, ta_name, "default", "data", "ui", "views", ta_name.lower() + "_redirect.xml") + ) + os.rename(redirect_js_src, redirect_js_dest) + os.rename(redirect_html_src, redirect_html_dest) + os.rename(redirect_xml_src, redirect_xml_dest) + + # if oauth is not configured remove the extra template + else: + os.remove(redirect_xml_src) + os.remove(redirect_html_src) + os.remove(redirect_js_src) def add_modular_input( args, ta_name, schema_content, import_declare_name @@ -752,9 +752,9 @@ def main(): generate_rest(args, ta_name, scheme, import_declare_name) - # modify_and_replace_token_for_oauth_templates( - # args, ta_name, ta_tabs, schema_content.get('meta').get('version') - # ) + modify_and_replace_token_for_oauth_templates( + args, ta_name, ta_tabs, schema_content.get('meta').get('version') + ) if is_inputs: add_modular_input( args, ta_name, schema_content, import_declare_name