Skip to content

Commit

Permalink
Merge branch 'main' into 30906_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo authored Sep 16, 2024
2 parents 9d9c5e6 + 23808fa commit 9a063e3
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .config/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ plugins/doc_fragments/
plugins/doc_fragments/eda_controller.py
plugins/doc_fragments/__init__.py
plugins/modules/
plugins/modules/activation.py
plugins/modules/activation_info.py
plugins/modules/controller_token.py
plugins/modules/credential.py
plugins/modules/credential_info.py
Expand All @@ -87,6 +85,8 @@ plugins/modules/event_stream.py
plugins/modules/event_stream_info.py
plugins/modules/project.py
plugins/modules/project_info.py
plugins/modules/rulebook_activation.py
plugins/modules/rulebook_activation_info.py
plugins/modules/rulebook_info.py
plugins/modules/user.py
plugins/modules/__init__.py
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ You can either call modules, rulebooks and playbooks by their Fully Qualified Co
```yaml
---
- name: Create a rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "Example Activation"
description: "Example Activation description"
project: "Example Project"
rulebook_name: "basic_short.yml"
decision_environment_name: "Example Decision Environment"
enabled: False
awx_token_id: 1
awx_token_name: "Example AWX Token"

- name: Get information about the rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "Example Activation"

- name: Delete rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "Example Activation"
state: absent
```
Expand Down
18 changes: 18 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ action_groups:
- project
- project_info
- rulebook_info
- rulebook_activation
- rulebook_activation_info
- user
plugin_routing:
modules:
activation:
redirect: ansible.eda.rulebook_activation
deprecation:
removal_version: 4.0.0
warning_text: >-
activation has been renamed to rulebook_activation.
Please update your tasks.
activation_info:
redirect: ansible.eda.rulebook_activation_info
deprecation:
removal_version: 4.0.0
warning_text: >-
activation_info has been renamed to rulebook_activation_info.
Please update your tasks.
21 changes: 21 additions & 0 deletions plugins/modules/event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
type: str
aliases:
- type
headers:
description:
- Comma separated HTTP header keys that you want to include in the event payload.
To include all headers in the event payload, leave the field empty.
type: str
default: ''
version_added: 2.1.0
forward_events:
description:
- Enable the event stream to forward events to the rulebook activation where it is configured.
type: bool
default: True
version_added: 2.1.0
state:
description:
- Desired state of the resource.
Expand Down Expand Up @@ -104,6 +117,12 @@ def create_params(module: AnsibleModule, controller: Controller) -> dict[str, An
if module.params.get("event_stream_type"):
credential_params["event_stream_type"] = module.params["event_stream_type"]

if module.params.get("forward_events") is not None:
credential_params["test_mode"] = module.params["forward_events"]

if module.params.get("headers"):
credential_params["additional_data_headers"] = module.params["headers"]

credential_id = None
if module.params.get("credential_name"):
credential_id = lookup_resource_id(
Expand Down Expand Up @@ -136,6 +155,8 @@ def main() -> None:
credential_name=dict(type="str", aliases=["credential"]),
organization_name=dict(type="str", aliases=["organization"]),
event_stream_type=dict(type="str", aliases=["type"]),
headers=dict(type="str", default=""),
forward_events=dict(type="bool", default=True),
state=dict(choices=["present", "absent"], default="present"),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DOCUMENTATION = """
---
module: activation
module: rulebook_activation
author:
- "Nikhil Jain (@jainnikhil30)"
- "Alina Buzachis (@alinabuzachis)"
Expand Down Expand Up @@ -145,7 +145,7 @@

EXAMPLES = """
- name: Create a rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "Example Rulebook Activation"
description: "Example Rulebook Activation description"
project_name: "Example Project"
Expand All @@ -155,7 +155,7 @@
awx_token_name: "Example Token"
- name: Create a rulebook activation with event_streams option
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "Example Rulebook Activation"
description: "Example Activation description"
project_name: "Example Project"
Expand All @@ -169,7 +169,7 @@
source_name: "Sample source"
- name: Delete a rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "Example Rulebook Activation"
state: absent
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DOCUMENTATION = """
---
module: activation_info
module: rulebook_activation_info
author:
- Alina Buzachis (@alinabuzachis)
short_description: List rulebook activations in the EDA Controller
Expand All @@ -31,11 +31,11 @@

EXAMPLES = """
- name: Get information about a rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "Example Rulebook Activation"
- name: List all rulebook activations
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
"""


Expand Down
32 changes: 16 additions & 16 deletions tests/integration/targets/activation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
register: decision_environment_creation

- name: Create a new rulebook activation in check mode
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -156,7 +156,7 @@
- _result.changed

- name: Create a new rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -173,7 +173,7 @@
- _result.changed

- name: Create a new rulebook activation again
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -191,19 +191,19 @@
- "'A rulebook activation with name: ' + activation_name + ' already exists. The module does not support modifying a rulebook activation.' in _result.msg"

- name: Get information about the rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "{{ activation_name }}"

- name: List all the rulebook activations
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:

- name: Delete rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name }}"
state: absent

- name: Get information about the rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "{{ activation_name }}"

# Test event_streams option
Expand Down Expand Up @@ -235,7 +235,7 @@
register: _result_rulebook_info

- name: Create a rulebook activation (wrong source_name)
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name_wrong_source }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -257,7 +257,7 @@
- '"The specified source_name Test source name does not exist." in _result.msg'

- name: Create a rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name_source_index }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -277,7 +277,7 @@
- _result.changed

- name: Get information about the rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "{{ activation_name_source_index }}"
register: _result_activation_info

Expand All @@ -291,12 +291,12 @@
- event_stream_name in (source_mappings_dict | map(attribute='event_stream_name') | list)

- name: Delete rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name_source_index }}"
state: absent

- name: Create a new rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name_source_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -316,7 +316,7 @@
- _result.changed

- name: Get information about the rulebook activation
ansible.eda.activation_info:
ansible.eda.rulebook_activation_info:
name: "{{ activation_name_source_name }}"
register: _result_activation_info

Expand Down Expand Up @@ -354,7 +354,7 @@
- credential_deletion is success

- name: Delete rulebook activation
ansible.eda.activation:
ansible.eda.rulebook_activation:
name: "{{ activation_name }}"
state: absent

Expand All @@ -371,8 +371,8 @@
state: absent
ignore_errors: true

- name: Delete rulebook activations
ansible.eda.activation:
- name: Delete rulebook activation
ansible.eda.rulebook_activation:
name: "{{ item }}"
state: absent
loop:
Expand Down
38 changes: 37 additions & 1 deletion tests/integration/targets/event_stream/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
name: "{{ event_stream_name }}"
credential_name: "{{ credential_name }}"
organization_name: Default
forward_events: False
event_stream_type: Basic Event Stream
check_mode: true
register: _result
Expand All @@ -64,7 +65,7 @@
event_stream_type: Basic Event Stream
register: _result

- name: Check event stream is not created again
- name: Check event stream is created
assert:
that:
- _result.changed
Expand Down Expand Up @@ -119,6 +120,40 @@
- name: Get info about event stream
ansible.eda.event_stream_info:
name: "{{ new_event_stream_name }}"
register: _result

- name: Check if event stream name is updated
assert:
that:
- _result.event_streams[0].name == new_event_stream_name

- name: Update event stream headers and forward_events
ansible.eda.event_stream:
state: present
name: "{{ new_event_stream_name }}"
credential_name: "{{ credential_name }}"
organization_name: Default
event_stream_type: "Basic Event Stream"
headers: "Authorization,Custom-Header"
forward_events: False
register: _result

- name: Check event stream is updated
assert:
that:
- _result.changed

- name: Get info about event stream
ansible.eda.event_stream_info:
name: "{{ new_event_stream_name }}"
register: _result

- name: Check if event stream headers and forward_events are updated
assert:
that:
- _result.event_streams[0].name == new_event_stream_name
- _result.event_streams[0].additional_data_headers == "Authorization,Custom-Header"
- _result.event_streams[0].test_mode == False

- name: List all event stream
ansible.eda.event_stream_info:
Expand Down Expand Up @@ -158,6 +193,7 @@
assert:
that:
- _result.changed

always:
- name: Clean up - event stream
ansible.eda.event_stream:
Expand Down

0 comments on commit 9a063e3

Please sign in to comment.