From 98d87013b11930cff90e3893e4f4bc1b18e8f721 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 12 Sep 2024 14:31:17 +0200 Subject: [PATCH] event_stream - add support for headers and forward_events options Signed-off-by: Alina Buzachis --- plugins/modules/event_stream.py | 21 ++++++++++ .../targets/event_stream/tasks/main.yml | 38 ++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/plugins/modules/event_stream.py b/plugins/modules/event_stream.py index 1e40e4b8..54b9c2d2 100644 --- a/plugins/modules/event_stream.py +++ b/plugins/modules/event_stream.py @@ -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. @@ -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( @@ -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"), ) diff --git a/tests/integration/targets/event_stream/tasks/main.yml b/tests/integration/targets/event_stream/tasks/main.yml index 15db0ec9..7c418e42 100644 --- a/tests/integration/targets/event_stream/tasks/main.yml +++ b/tests/integration/targets/event_stream/tasks/main.yml @@ -46,6 +46,7 @@ name: "{{ event_stream_name }}" credential_name: "{{ credential_name }}" organization_name: Default + forward_events: False check_mode: true register: _result @@ -62,7 +63,7 @@ organization_name: Default register: _result - - name: Check event stream is not created again + - name: Check event stream is created assert: that: - _result.changed @@ -122,6 +123,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: @@ -161,6 +196,7 @@ assert: that: - _result.changed + always: - name: Clean up - event stream ansible.eda.event_stream: