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

event_stream - add support for headers and forward_events options #321

Merged
merged 3 commits into from
Sep 16, 2024
Merged
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
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.
Akasurde marked this conversation as resolved.
Show resolved Hide resolved
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