Skip to content

Commit

Permalink
chore: merge develop into main (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
soleksy-splunk authored Dec 10, 2024
2 parents 1b2b283 + 0c1ef99 commit f656c70
Show file tree
Hide file tree
Showing 50 changed files with 1,000 additions and 304 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

* add license during init command ([#1475](https://github.com/splunk/addonfactory-ucc-generator/issues/1475)) ([471294a](https://github.com/splunk/addonfactory-ucc-generator/commit/471294ae8e4c266a2f685aa4c01eb75fd1974db1))
* confirmation modal when activate/deactivate single input ([#1421](https://github.com/splunk/addonfactory-ucc-generator/issues/1421)) ([34c8ec2](https://github.com/splunk/addonfactory-ucc-generator/commit/34c8ec250861eb06bd1cd4b22b430e5aa7e26a7c))
* do not create __pycache__ in lib dir ([#1469](https://github.com/splunk/addonfactory-ucc-generator/issues/1469)) ([ad58e50](https://github.com/splunk/addonfactory-ucc-generator/commit/ad58e50ca2b5588f6824a4da95a15e8c0857f032))
* do not create `__pycache__` in lib dir ([#1469](https://github.com/splunk/addonfactory-ucc-generator/issues/1469)) ([ad58e50](https://github.com/splunk/addonfactory-ucc-generator/commit/ad58e50ca2b5588f6824a4da95a15e8c0857f032))
* **inputs:** show input services status count ([#1430](https://github.com/splunk/addonfactory-ucc-generator/issues/1430)) ([2574451](https://github.com/splunk/addonfactory-ucc-generator/commit/257445159898a2207cdf7a397345c218678c8fcb))

## [5.53.2](https://github.com/splunk/addonfactory-ucc-generator/compare/v5.53.1...v5.53.2) (2024-11-21)
Expand Down
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ It takes the following parameters:
* `--overwrite` - [optional] overwrites the already existing folder. By default, you can't generate a new add-on to an already existing folder.
* `--add-license` - [optional] Adds license agreement such as [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt), [MIT License](https://mit-license.org/), or
[SPLUNK PRE-RELEASE SOFTWARE LICENSE AGREEMENT](https://www.splunk.com/en_us/legal/splunk-pre-release-software-license-agreement.html) in your `package/LICENSES` directory. If not mentioned an empty License.txt will be generated.
* `--include-author` - [optional] Allows you to specify the author of the add-on during initialization. The author's name will appear in `app.manifest` under `info -> author -> name` and in `app.conf` (after building your add-on) under `launcher -> author` field.

> **Note:** The add-on will not build if the input for `--add-license` is not one of the following: `Apache License 2.0`, `MIT License`, or `SPLUNK PRE-RELEASE SOFTWARE LICENSE AGREEMENT`. If you want to keep another license in your add-on, place it in `package/LICENSES` directory and it will be shipped
Expand Down
10 changes: 5 additions & 5 deletions docs/entity/modifyFieldsOnValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This feature allows to specify conditions to modify other fields based on curren

### Modification Object Properties

| Property | Type | Description |
| --------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------- |
| fieldValue<span class="required-asterisk">\*</span> | string | Value that will trigger the update, put `[[any_other_value]]` to trigger update for any other values than specified |
| mode | string | Mode that adds possibility to use modification only on certain mode |
| fieldsToModify | array | List of fields modifications that will be applied after com ponent value will match |
| Property | Type | Description |
| --------------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| fieldValue<span class="required-asterisk">\*</span> | string | Value of current field that will trigger the update. Put `[[any_other_value]]` to make update for any other value than specified. |
| mode | string | Mode that adds possibility to use modification only on certain mode. One of ( `create` / `edit` / `clone` / `config` ) |
| fieldsToModify | array | List of fields modifications that will be applied after com ponent value will match. |

### fieldsToModify Properties

Expand Down
1 change: 1 addition & 0 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ def generate(
removed_list = _remove_listed_files(ignore_list)
if removed_list:
logger.info("Removed:\n{}".format("\n".join(removed_list)))
utils.check_author_name(source, app_manifest)
utils.recursive_overwrite(source, os.path.join(output_directory, ta_name))
logger.info("Copied package directory")

Expand Down
9 changes: 9 additions & 0 deletions splunk_add_on_ucc_framework/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _generate_addon(
addon_rest_root: str | None = None,
overwrite: bool = False,
add_license: str | None = None,
include_author: str | None = None,
) -> str:
generated_addon_path = os.path.join(
os.getcwd(),
Expand Down Expand Up @@ -131,6 +132,7 @@ def _generate_addon(
addon_version=addon_version,
addon_display_name=addon_display_name,
add_license=add_license,
include_author=include_author,
)
)
with open(package_app_manifest_path, "w") as _f:
Expand Down Expand Up @@ -175,6 +177,7 @@ def init(
addon_rest_root: str | None = None,
overwrite: bool = False,
add_license: str | None = None,
include_author: str | None = None,
) -> str:
if not _is_valid_addon_name(addon_name):
logger.error(
Expand Down Expand Up @@ -207,6 +210,11 @@ def init(
f"it should follow '{ADDON_INPUT_NAME_RE_STR}' regex and be less than 50 characters."
)
sys.exit(1)
if include_author == "":
logger.error("The author name cannot be left empty, please provide some input.")
sys.exit(1)
if include_author:
include_author = include_author.strip()
generated_addon_path = _generate_addon(
addon_name,
addon_display_name,
Expand All @@ -215,6 +223,7 @@ def init(
addon_rest_root,
overwrite,
add_license,
include_author,
)
logger.info(f"Generated add-on is located here {generated_addon_path}")
if add_license:
Expand Down
74 changes: 44 additions & 30 deletions splunk_add_on_ucc_framework/global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def _validate_groups(self) -> None:
f"Service {service['name']} uses group field {group_field} which is not defined in entity"
)

def _is_circular(
def _is_circular_modification(
self,
mods: List[Any],
visited: Dict[str, str],
Expand All @@ -551,61 +551,73 @@ def _is_circular(
# no more dependent modification fields
visited[current_field] = DEAD_END
return visited
else:
for influenced_field in current_field_mods["influenced_fields"]:
if influenced_field not in all_entity_fields:
raise GlobalConfigValidatorException(
f"""Modification in field '{current_field}' for not existing field '{influenced_field}'"""
)
if influenced_field == current_field:
raise GlobalConfigValidatorException(
f"""Field '{current_field}' tries to modify itself"""
)

if current_field in current_field_mods["influenced_fields_value_change"]:
# field can modify itself except "value" property
raise GlobalConfigValidatorException(
f"""Field '{current_field}' tries to modify itself value"""
)

for influenced_field in current_field_mods["influenced_fields"]:
if influenced_field not in all_entity_fields:
raise GlobalConfigValidatorException(
f"""Modification in field '{current_field}' for not existing field '{influenced_field}'"""
)

if influenced_field in current_field_mods["influenced_fields_value_change"]:
if visited[influenced_field] == VISITING:
raise GlobalConfigValidatorException(
f"""Circular modifications for field '{influenced_field}' in field '{current_field}'"""
)
else:
visited = self._is_circular(
mods, visited, all_entity_fields, influenced_field
)
# check next influenced by value change field
visited = self._is_circular_modification(
mods, visited, all_entity_fields, influenced_field
)

# All dependent modifications fields are dead_end
visited[current_field] = DEAD_END
return visited

def _check_if_circular(
def _check_if_circular_modification(
self,
all_entity_fields: List[Any],
fields_with_mods: List[Any],
modifications: List[Any],
) -> None:
visited = {field: "not_visited" for field in all_entity_fields}

for start_field in fields_with_mods:
# DFS algorithm for all fields with modifications
visited = self._is_circular(
visited = self._is_circular_modification(
modifications, visited, all_entity_fields, start_field
)

@staticmethod
def _get_mods_data_for_single_entity(
fields_with_mods: List[Any],
all_modifications: List[Any],
entity: Dict[str, Any],
) -> List[Any]:
"""
Add modification entity data to lists and returns them
Get modification entity data as lists
"""
entity_modifications = []
if "modifyFieldsOnValue" in entity:
influenced_fields_value_change = set()
influenced_fields = set()
fields_with_mods.append(entity["field"])
for mods in entity["modifyFieldsOnValue"]:
for mod in mods["fieldsToModify"]:
influenced_fields.add(mod["fieldId"])
all_modifications.append(
{"fieldId": entity["field"], "influenced_fields": influenced_fields}

if (
mod.get("value") is not None
): # circular deps are not a problem if not about value
influenced_fields_value_change.add(mod["fieldId"])
entity_modifications.append(
{
"fieldId": entity["field"],
"influenced_fields": influenced_fields,
"influenced_fields_value_change": influenced_fields_value_change,
}
)
return [fields_with_mods, all_modifications]
return entity_modifications

@staticmethod
def _get_all_entities(
Expand Down Expand Up @@ -638,11 +650,13 @@ def _get_all_modification_data(

entities = self._get_all_entities(collections)
for entity in entities:
self._get_mods_data_for_single_entity(
fields_with_mods, all_modifications, entity
)
all_fields.append(entity["field"])

if "modifyFieldsOnValue" in entity:
fields_with_mods.append(entity["field"])
entity_mods = self._get_mods_data_for_single_entity(entity)
all_modifications.extend(entity_mods)

return [fields_with_mods, all_modifications, all_fields]

def _validate_field_modifications(self) -> None:
Expand All @@ -664,7 +678,7 @@ def _validate_field_modifications(self) -> None:
all_fields_config,
) = self._get_all_modification_data(tabs)

self._check_if_circular(
self._check_if_circular_modification(
all_fields_config, fields_with_mods_config, all_modifications_config
)

Expand All @@ -678,7 +692,7 @@ def _validate_field_modifications(self) -> None:
all_fields_inputs,
) = self._get_all_modification_data(services)

self._check_if_circular(
self._check_if_circular_modification(
all_fields_inputs, fields_with_mods_inputs, all_modifications_inputs
)

Expand Down
8 changes: 8 additions & 0 deletions splunk_add_on_ucc_framework/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
required=False,
default=None,
)
init_parser.add_argument(
"--include-author",
type=str,
help="adds author in app.mainifest under `info -> author -> name` field",
required=False,
default=None,
)

import_from_aob_parser = subparsers.add_parser(
"import-from-aob", description="[Experimental] Import from AoB"
Expand Down Expand Up @@ -251,6 +258,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
addon_version=args.addon_version,
overwrite=args.overwrite,
add_license=args.add_license,
include_author=args.include_author,
)
if args.command == "import-from-aob":
import_from_aob.import_from_aob(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
},
"author": [
{
{% if include_author -%}
"name": "{{include_author}}",
{%- else -%}
"name": "",
{%- endif %}
"email": null,
"company": null
}
Expand Down
19 changes: 18 additions & 1 deletion splunk_add_on_ucc_framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import shutil
from os import listdir, makedirs, path, remove, sep
from os.path import basename as bn
from os.path import dirname, exists, isdir, join
from os.path import dirname, exists, isdir, join, isfile
from splunk_add_on_ucc_framework.app_manifest import AppManifest
from typing import Any, Dict

import addonfactory_splunk_conf_parser_lib as conf_parser
Expand All @@ -42,6 +43,22 @@ def get_license_path(file_name: str) -> str:
return join(dirname(__file__), "templates", "Licenses", f"{file_name}.txt")


def check_author_name(source: str, app_manifest: AppManifest) -> None:
check_path = join(source, "default", "app.conf")
if isfile(check_path):
app_conf = conf_parser.TABConfigParser()
app_conf.read(check_path)
app_conf_content = app_conf.item_dict()
if (
app_manifest.get_authors()[0]["name"]
!= app_conf_content["launcher"]["author"]
):
logger.warning(
"Conflicting author names are identified between app.manifest and app.conf in the source directory. "
"Please specify the author name in app.manifest."
)


def recursive_overwrite(src: str, dest: str, ui_source_map: bool = False) -> None:
"""
Method to copy from src to dest recursively.
Expand Down
12 changes: 12 additions & 0 deletions tests/smoke/test_ucc_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_ucc_init():
"demo-addon-for-splunk",
overwrite=True,
add_license="MIT License",
include_author="test_author",
)
expected_folder = os.path.join(
os.path.dirname(__file__),
Expand Down Expand Up @@ -67,3 +68,14 @@ def test_ucc_init_if_same_output_then_sys_exit():
"demo_input",
"1.0.0",
)


def test_ucc_init_empty_string_passed_for_author():
with pytest.raises(SystemExit):
init.init(
"test_addon",
"Demo Add-on for Splunk",
"demo_input",
"1.0.0",
include_author="",
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"author": [
{
"name": "",
"name": "test_author",
"email": null,
"company": null
}
Expand Down
Loading

0 comments on commit f656c70

Please sign in to comment.