Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: .uccignore file is ignoring files specified #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,24 +572,26 @@ def make_modular_alerts(ta_name, ta_namespace, schema_content, outputdir):
)


def get_ignore_list(ta_name, path):
def get_ignore_list(ta_name: str, uccignore_path: str, output_path: str):
"""
Return path of files/folders to be removed.

Args:
ta_name (str): Name of TA.
path (str): Path of '.uccignore'.
ta_name: Name of TA.
uccignore_path: Path of '.uccignore'.
output_path: Path to output directory.

Returns:
list: List of paths to be removed from output directory.
"""
if not os.path.exists(path):
if not os.path.exists(uccignore_path):
logger.info("No .uccignore specified - nothing to ignore")
return []
else:
with open(path) as ignore_file:
with open(uccignore_path) as ignore_file:
ignore_list = ignore_file.readlines()
ignore_list = [
(os.path.join("output", ta_name, get_os_path(path))).strip()
(os.path.join(output_path, ta_name, get_os_path(path))).strip()
for path in ignore_list
]
return ignore_list
Expand All @@ -606,8 +608,10 @@ def remove_listed_files(ignore_list):
for path in ignore_list:
if os.path.exists(path):
if os.path.isfile(path):
logger.info(f"Removing file {path} because of .uccignore")
os.remove(path)
elif os.path.isdir(path):
logger.info(f"Removing directory {path} because of .uccignore")
shutil.rmtree(path, ignore_errors=True)
else:
logger.info(
Expand Down Expand Up @@ -800,13 +804,13 @@ def _generate(source, config, ta_version, outputdir=None):
logger.info(f"Install add-on requirements into {ucc_lib_target} from {source}")
install_libs(source, ucc_lib_target=ucc_lib_target)

ignore_list = get_ignore_list(
ta_name, os.path.abspath(os.path.join(source, PARENT_DIR, ".uccignore"))
)
remove_listed_files(ignore_list)
logger.info("Copy package directory")
recursive_overwrite(source, os.path.join(outputdir, ta_name))

uccignore_path = os.path.abspath(os.path.join(source, PARENT_DIR, ".uccignore"))
ignore_list = get_ignore_list(ta_name, uccignore_path, outputdir)
remove_listed_files(ignore_list)

default_meta_conf_path = os.path.join(
outputdir, ta_name, "metadata", "default.meta"
)
Expand Down
1 change: 1 addition & 0 deletions tests/data/package_with_dot_uccignore/.uccignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default/pytest-splunk-addon-data.conf
1 change: 1 addition & 0 deletions tests/data/package_with_dot_uccignore/package/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Just a readme
51 changes: 51 additions & 0 deletions tests/data/package_with_dot_uccignore/package/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"schemaVersion": "2.0.0",
"info": {
"title": "Splunk Add-on for UCC Example",
"id": {
"group": null,
"name": "Splunk_TA_UCCExample",
"version": "7.0.1"
},
"author": [
{
"name": "Splunk",
"email": null,
"company": null
}
],
"releaseDate": null,
"description": "Splunk Add-on for UCC Example",
"classification": {
"intendedAudience": null,
"categories": [],
"developmentStatus": null
},
"commonInformationModels": null,
"license": {
"name": null,
"text": "LICENSES/Apache-2.0.txt",
"uri": null
},
"privacyPolicy": {
"name": null,
"text": null,
"uri": null
},
"releaseNotes": {
"name": null,
"text": "./README.txt",
"uri": null
}
},
"dependencies": null,
"tasks": null,
"inputGroups": null,
"incompatibleApps": null,
"platformRequirements": null,
"supportedDeployments": [
"_standalone",
"_distributed"
],
"targetWorkloads": null
}
23 changes: 23 additions & 0 deletions tests/data/package_with_dot_uccignore/package/default/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
######################################################
#
# ${package.name}
#
# ${copyright}
#
######################################################

[install]
build = 0

[launcher]
author = Splunk Inc.
version = 0.1.0
description = Splunk_TA_UCCExample

[ui]
is_visible = true
label = Splunk_TA_UCCExample
docs_section_override=AddOns:released

[package]
id = Splunk_TA_UCCExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[new_eventtype]
search = sourcetype=new_sourcetype
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# props.conf

[new_sourcetype]
EVAL-new_field = if(field2 = "hello", "world")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[stanza]
key = value
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[eventtype=new_eventtype]
new_tag = enabled
21 changes: 21 additions & 0 deletions tests/data/test_ucc_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ def test_ucc_generate_with_configuration_files_only(self):
msg=f"Expected file {expected_file_path} is different from {actual_file_path}",
)

def test_ucc_generate_uccignore(self):
with tempfile.TemporaryDirectory() as temp_dir:
package_folder = path.join(
path.dirname(path.realpath(__file__)),
"package_with_dot_uccignore",
"package",
)
ucc.generate(source=package_folder, outputdir=temp_dir)

ignored_file_exists = path.exists(
path.join(
temp_dir,
"Splunk_TA_UCCExample",
"default",
"pytest-splunk-addon-data.conf",
)
)
self.assertFalse(
ignored_file_exists, "Ignored file still exists after ucc-gen"
)


if __name__ == "__main__":
unittest.main()