Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 16, 2024
1 parent 3245e0f commit 4674767
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions plugins/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@
"""


import yaml
from typing import Any, Dict, List, Union
from typing import Any, Dict, List

import yaml
from ansible.module_utils.basic import AnsibleModule

from ..module_utils.arguments import AUTH_ARGSPEC
Expand All @@ -196,7 +196,9 @@
from ..module_utils.errors import EDAError


def find_matching_source(event: Dict[str, Any], sources: List[Dict[str, Any]], module: AnsibleModule) -> Dict[str, Any]:
def find_matching_source(
event: Dict[str, Any], sources: List[Dict[str, Any]], module: AnsibleModule
) -> Dict[str, Any]:
"""
Finds a matching source based on the source_name in the event.
Raises an error if no match is found.
Expand All @@ -210,9 +212,7 @@ def find_matching_source(event: Dict[str, Any], sources: List[Dict[str, Any]], m
return source # Return the matching source if found

# If no match is found, raise an error
module.fail_json(
msg=f"The specified source_name {source_name} does not exist."
)
module.fail_json(msg=f"The specified source_name {source_name} does not exist.")

return {} # Explicit return to satisfy mypy

Expand Down Expand Up @@ -261,8 +261,12 @@ def process_event_streams(
# Handle source_index
if event.get("source_index") is not None:
try:
source_mapping["source_name"] = sources[event["source_index"]].get("name")
source_mapping["rulebook_hash"] = sources[event["source_index"]].get("rulebook_hash")
source_mapping["source_name"] = sources[event["source_index"]].get(
"name"
)
source_mapping["rulebook_hash"] = sources[event["source_index"]].get(
"rulebook_hash"
)
except IndexError as e:
module.fail_json(
msg=f"The specified source_index {event['source_index']} is out of range: {e}"
Expand All @@ -275,9 +279,7 @@ def process_event_streams(
source_mapping["rulebook_hash"] = matching_source.get("rulebook_hash")

if event.get("event_stream") is None:
module.fail_json(
msg="You must specify an event stream name."
)
module.fail_json(msg="You must specify an event stream name.")

# Lookup event_stream_id
event_stream_id = lookup_resource_id(
Expand Down Expand Up @@ -389,11 +391,13 @@ def create_params(

if not is_aap_24 and module.params.get("event_streams"):
# Process event streams and source mappings
activation_params["source_mappings"] = yaml.dump(process_event_streams(
rulebook_id=rulebook_id,
controller=controller,
module=module,
))
activation_params["source_mappings"] = yaml.dump(
process_event_streams(
rulebook_id=rulebook_id,
controller=controller,
module=module,
)
)

if not is_aap_24 and module.params.get("log_level"):
activation_params["log_level"] = module.params["log_level"]
Expand Down

0 comments on commit 4674767

Please sign in to comment.