Skip to content

Commit

Permalink
event_stream - add support for headers and forward_events options (#321)
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
Co-authored-by: Alex <[email protected]>
  • Loading branch information
alinabuzachis and Alex-Izquierdo authored Sep 16, 2024
1 parent 642898d commit 3305b75
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
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
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 @@ -125,6 +126,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 @@ -164,6 +199,7 @@
assert:
that:
- _result.changed

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

0 comments on commit 3305b75

Please sign in to comment.