Skip to content

Commit

Permalink
Input handler import fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
VatsalJagani committed Nov 15, 2024
1 parent e3e036d commit 6fb885a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ Example-2
* This will handle checkpoint removal when user deletes the input.
* This will avoid checkpoint conflicts when user deletes the input and re-create with the same name.
* Remove the `input.py` file as that will be auto-generated by UCC in the final build. You make changes only in the `input_handler.py` file.
```
- uses: VatsalJagani/splunk-app-action@v4
with:
Expand Down
19 changes: 11 additions & 8 deletions src/utilities/ucc_additional_packaging/additional_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ def modify_original_input_py_file(addon_name, input_name):
file_path = os.path.join('output', addon_name, 'bin', f'{input_name}.py')
with open(file_path, "r") as f:
file_content = f.read()

input_class_name = _util_generate_input_class_name(input_name)

# Insert import statement for your modular input
file_content = re.sub(
r"(?m)^(import[^\n]*)$(?!.*^import[^\n]*)",
r"\1\from " + input_name + "_handler import " + input_class_name,
file_content,
flags=re.DOTALL
)
input_class_import_statement = f"from {input_name}_handler import {input_class_name}"

if input_class_import_statement not in file_content:
# Only add import if not present already
file_content = re.sub(
r"^(import\s+import_declare_test.*)$",
r"\1\n" + input_class_import_statement,
file_content,
flags=re.MULTILINE
)

# Update validate_input method
pattern_validate_input_fun = r"def validate_input[\w\W]*return\n"
Expand Down

0 comments on commit 6fb885a

Please sign in to comment.