Skip to content

Commit

Permalink
feat: restructure conf and spec file generation (#1328)
Browse files Browse the repository at this point in the history
**Issue number:** ADDON-73368

## Summary

### Changes

> As per the new design, we are restructuring the code of generating
`.conf` and `.conf.spec` files that are supported by UCC.
One specific change for `inputs.conf.spec`, we are now writing the
default value and description of a field in the spec file.

### User experience

> One change for `inputs.conf.spec`, we are now writing the description
and default value of a field in the spec file if they are mentioned in
the globalConfig, apart from it there are no changes from user end, all
the files that were generated before will be generated as is with these
changes.

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [ ] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)

---------

Co-authored-by: srv-rr-github-token <[email protected]>
  • Loading branch information
hetangmodi-crest and srv-rr-github-token committed Sep 13, 2024
1 parent 17d29d0 commit bc6a36b
Show file tree
Hide file tree
Showing 82 changed files with 2,791 additions and 1,121 deletions.
2 changes: 1 addition & 1 deletion docs/alert_actions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Developers are required to add alerts in the global config file to create an Ale

| Property | Type | Description |
|---------------------------------------------------------------------------|--------|--------------------------------------------------------------------------------------------------------|
| type<span class="required-asterisk">\*</span> | string | The type of the user input in the alert. Available choices: "text", "checkbox", "singleSelect", "radio", "singleSelectSplunkSearch". |
| type<span class="required-asterisk">\*</span> | string | The type of the user input in the alert. Available choices: "text", "textarea", "checkbox", "singleSelect", "radio", "singleSelectSplunkSearch". |
| label<span class="required-asterisk">\*</span> | string | The text that would be shown in the alert action UI. |
| field<span class="required-asterisk">\*</span> | string | The field that would be used in the scripts to get the value from the user input. These are defined as `param.<field_mentioned>` in the `alert_actions.conf`. |
| options | array | Static choices that a user can select in the alert action UI. |
Expand Down
10 changes: 10 additions & 0 deletions docs/generated_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Below table describes the files generated by UCC framework

| File Name | File Location | File Description |
| ------------ | ------------ | ----------------- |
| app.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `app.conf` with the details mentioned in globalConfig[meta] |
| inputs.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `inputs.conf` and `inputs.conf.spec` file for the services mentioned in globalConfig |
| server.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `server.conf` for the custom conf files created as per configurations in globalConfig |
| restmap.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `restmap.conf` for the custom REST handlers that are generated based on configs from globalConfig |
| web.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `web.conf` to expose the endpoints generated in `restmap.conf` which is generated based on configurations from globalConfig. |
| alert_actions.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `alert_actions.conf` and `alert_actions.conf.spec` file for the custom alert actions defined in globalConfig |
| eventtypes.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `eventtypes.conf` file if the sourcetype is mentioned in Adaptive Response of custom alert action in globalConfig |
| tags.conf | output/&lt;YOUR_ADDON_NAME&gt;/default | Generates `tags.conf` file based on the `eventtypes.conf` created for custom alert actions. |
| _account.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_account.conf.spec` file for the configuration mentioned in globalConfig |
| _settings.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_settings.conf.spec` file for the Proxy, Logging or Custom Tab mentioned in globalConfig |
| configuration.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates configuration.xml file in `default/data/ui/views/` folder if globalConfig is present. |
| dashboard.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates dashboard.xml file based on dashboard configuration present in globalConfig in `default/data/ui/views` folder. |
| default.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/nav | Generates default.xml file based on configs present in globalConfigin in `default/data/ui/nav` folder. |
Expand Down
75 changes: 0 additions & 75 deletions splunk_add_on_ucc_framework/app_conf.py

This file was deleted.

74 changes: 14 additions & 60 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import configparser
import glob
import json
import logging
Expand All @@ -34,9 +33,7 @@
utils,
)
from splunk_add_on_ucc_framework import dashboard
from splunk_add_on_ucc_framework import app_conf as app_conf_lib
from splunk_add_on_ucc_framework import meta_conf as meta_conf_lib
from splunk_add_on_ucc_framework import server_conf as server_conf_lib
from splunk_add_on_ucc_framework import app_manifest as app_manifest_lib
from splunk_add_on_ucc_framework import global_config as global_config_lib
from splunk_add_on_ucc_framework.commands.modular_alert_builder import (
Expand All @@ -54,6 +51,7 @@
ucc_to_oas,
)
from splunk_add_on_ucc_framework.generators.file_generator import begin
from splunk_add_on_ucc_framework.generators.conf_files.create_app_conf import AppConf


logger = logging.getLogger("ucc_gen")
Expand Down Expand Up @@ -160,19 +158,6 @@ def _add_modular_input(
with open(helper_filename, "w") as helper_file:
helper_file.write(content)

input_default = os.path.join(outputdir, ta_name, "default", "inputs.conf")
config = configparser.ConfigParser()
if os.path.exists(input_default):
config.read(input_default)

if config.has_section(input_name):
config[input_name]["python.version"] = "python3"
else:
config[input_name] = {"python.version": "python3"}

with open(input_default, "w") as configfile:
config.write(configfile)


def _get_ignore_list(
addon_name: str, ucc_ignore_path: str, output_directory: str
Expand Down Expand Up @@ -454,6 +439,7 @@ def generate(

gc_path = _get_and_check_global_config_path(source, config_path)
if gc_path:
ui_available = True
logger.info(f"Using globalConfig file located @ {gc_path}")
global_config = global_config_lib.GlobalConfig(gc_path)
# handle the update of globalConfig before validating
Expand Down Expand Up @@ -536,31 +522,13 @@ def generate(
_add_modular_input(ta_name, global_config, output_directory)
if global_config.has_alerts():
logger.info("Generating alerts code")
alert_builder.generate_alerts(
global_config, ta_name, internal_root_dir, output_directory
)
alert_builder.generate_alerts(global_config, ta_name, output_directory)

conf_file_names = []
conf_file_names.extend(list(scheme.settings_conf_file_names))
conf_file_names.extend(list(scheme.configs_conf_file_names))
conf_file_names.extend(list(scheme.oauth_conf_file_names))

source_server_conf_path = os.path.join(source, "default", "server.conf")
# For now, only create server.conf only if no server.conf is present in
# the source package.
if not os.path.isfile(source_server_conf_path):
server_conf = server_conf_lib.ServerConf()
server_conf.create_default(conf_file_names)
output_server_conf_path = os.path.join(
output_directory,
ta_name,
"default",
server_conf_lib.SERVER_CONF_FILE_NAME,
)
server_conf.write(output_server_conf_path)
logger.info(
f"Created default {server_conf_lib.SERVER_CONF_FILE_NAME} file in the output folder"
)
if global_config.has_dashboard():
logger.info("Including dashboard")
dashboard_definition_json_path = os.path.join(
Expand Down Expand Up @@ -632,31 +600,17 @@ def generate(
f"Updated {app_manifest_lib.APP_MANIFEST_FILE_NAME} file in the output folder"
)

app_conf = app_conf_lib.AppConf()
output_app_conf_path = os.path.join(
output_directory, ta_name, "default", app_conf_lib.APP_CONF_FILE_NAME
)
app_conf.read(output_app_conf_path)
should_be_visible = False
check_for_updates = "true"
supported_themes = ""
if global_config:
should_be_visible = True
if global_config.meta.get("checkForUpdates") is False:
check_for_updates = "false"
if global_config.meta.get("supportedThemes") is not None:
supported_themes = ", ".join(global_config.meta["supportedThemes"])
app_conf.update(
addon_version,
app_manifest,
conf_file_names,
should_be_visible,
check_for_updates=check_for_updates,
supported_themes=supported_themes,
)
app_conf.write(output_app_conf_path)
logger.info(f"Updated {app_conf_lib.APP_CONF_FILE_NAME} file in the output folder")

# NOTE: merging source and generated 'app.conf' as per previous design
AppConf(
global_config=global_config,
input_dir=source,
output_dir=output_directory,
ucc_dir=internal_root_dir,
addon_name=ta_name,
app_manifest=app_manifest,
addon_version=addon_version,
has_ui=ui_available,
).generate()
license_dir = os.path.abspath(os.path.join(source, os.pardir, "LICENSES"))
if os.path.exists(license_dir):
logger.info("Copy LICENSES directory")
Expand Down
Loading

0 comments on commit bc6a36b

Please sign in to comment.