From d9a6ef3c650b8d781b038d74a300cedd0affcfe5 Mon Sep 17 00:00:00 2001 From: X <2465124+broferek@users.noreply.github.com> Date: Fri, 14 Mar 2025 11:48:12 +0100 Subject: [PATCH 01/11] Fix payload to match Rocket Chat 7.4 API --- plugins/modules/rocketchat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index ccd683c7865..4573dd3a0d0 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -195,7 +195,7 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon attachment['fallback'] = attachment['text'] payload['attachments'].append(attachment) - payload = "payload=" + module.jsonify(payload) + payload = module.jsonify(payload) return payload From bdab72acb1e89224090ad400d55f6cc71458abdc Mon Sep 17 00:00:00 2001 From: X <2465124+broferek@users.noreply.github.com> Date: Fri, 14 Mar 2025 14:44:53 +0100 Subject: [PATCH 02/11] Add a fallback to send payload argument in case the user still interacts with a Rocket Chat version < 7.4.0 --- plugins/modules/rocketchat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index 4573dd3a0d0..ba1fa22664c 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -206,9 +206,11 @@ def do_notify_rocketchat(module, domain, token, protocol, payload): rocketchat_incoming_webhook = ROCKETCHAT_INCOMING_WEBHOOK % (protocol, domain, token) - response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) + _, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) if info['status'] != 200: - module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) + _, info = fetch_url(module, rocketchat_incoming_webhook, data="payload=" + payload) + if info['status'] != 200: + module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) def main(): From 5e27b45082fb17f8b62866c7e458baf1eabfe7a3 Mon Sep 17 00:00:00 2001 From: X <2465124+broferek@users.noreply.github.com> Date: Fri, 14 Mar 2025 14:56:34 +0100 Subject: [PATCH 03/11] Fix sanity checks --- plugins/modules/rocketchat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index ba1fa22664c..a252e116e46 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -206,11 +206,11 @@ def do_notify_rocketchat(module, domain, token, protocol, payload): rocketchat_incoming_webhook = ROCKETCHAT_INCOMING_WEBHOOK % (protocol, domain, token) - _, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) + response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) if info['status'] != 200: - _, info = fetch_url(module, rocketchat_incoming_webhook, data="payload=" + payload) + response, info = fetch_url(module, rocketchat_incoming_webhook, data="payload=" + payload) if info['status'] != 200: - module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) + module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) def main(): From a1e8a4606cab4cfc572f991e0154c8d03de836d6 Mon Sep 17 00:00:00 2001 From: ludovic Date: Tue, 18 Mar 2025 11:46:36 +0100 Subject: [PATCH 04/11] Add changelog fragment of PR #9882 --- .../9882-fix-payload-to-match-rocketchat-740-requirement.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml diff --git a/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml new file mode 100644 index 00000000000..786b01c0213 --- /dev/null +++ b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml @@ -0,0 +1,4 @@ +deprecated_features: + - > + RocketChat module - attribute ``option_is_pre740`` has been added to match the old payload. The argument default value could be set to false in a few months and then, + removed in a future release when Rocket Chat 7.4.0 is considered as a minimum version to be used (https://github.com/ansible-collections/community.general/pull/9882). From ee2e635ba2f53f32974081942d7c1ca7a6cb5432 Mon Sep 17 00:00:00 2001 From: ludovic Date: Tue, 18 Mar 2025 11:48:03 +0100 Subject: [PATCH 05/11] Add argument option_is_pre740 to keep backward compatibility of the payload --- plugins/modules/rocketchat.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index a252e116e46..9983db85b50 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -165,7 +165,7 @@ ROCKETCHAT_INCOMING_WEBHOOK = '%s://%s/hooks/%s' -def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments): +def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, option_is_pre740): payload = {} if color == "normal" and text is not None: payload = dict(text=text) @@ -196,6 +196,8 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon payload['attachments'].append(attachment) payload = module.jsonify(payload) + if option_is_pre740: + payload = "payload=" + module.jsonify(payload) return payload @@ -208,9 +210,7 @@ def do_notify_rocketchat(module, domain, token, protocol, payload): response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) if info['status'] != 200: - response, info = fetch_url(module, rocketchat_incoming_webhook, data="payload=" + payload) - if info['status'] != 200: - module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) + module.fail_json(msg="failed to send message, return status=%s" % str(info['status'])) def main(): @@ -227,7 +227,8 @@ def main(): link_names=dict(type='int', default=1, choices=[0, 1]), validate_certs=dict(default=True, type='bool'), color=dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']), - attachments=dict(type='list', elements='dict', required=False) + attachments=dict(type='list', elements='dict', required=False), + option_is_pre740=dict(default=True, type='bool') ) ) @@ -242,8 +243,9 @@ def main(): link_names = module.params['link_names'] color = module.params['color'] attachments = module.params['attachments'] + option_is_pre740 = module.params['option_is_pre740'] - payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments) + payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, option_is_pre740) do_notify_rocketchat(module, domain, token, protocol, payload) module.exit_json(msg="OK") From 3a32e46af8b1958fcba5fa6f489cdfdd121db103 Mon Sep 17 00:00:00 2001 From: ludovic Date: Tue, 18 Mar 2025 11:56:39 +0100 Subject: [PATCH 06/11] Add new argument doc --- plugins/modules/rocketchat.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index 9983db85b50..b89afb24888 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -100,6 +100,11 @@ elements: dict description: - Define a list of attachments. + option_is_pre740: + description: + - If V(true), the payload matches Rocket Chat prior to 7.4.0 format + type: bool + default: true """ EXAMPLES = r""" From 539207dfe49f6cbc68d6e0da2bbc77d75c935b92 Mon Sep 17 00:00:00 2001 From: ludovic Date: Wed, 19 Mar 2025 08:56:43 +0100 Subject: [PATCH 07/11] Rename new parameter, add missing pieces of information in parameter doc --- plugins/modules/rocketchat.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index b89afb24888..5fa782a3d64 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -100,11 +100,14 @@ elements: dict description: - Define a list of attachments. - option_is_pre740: + is_pre740: description: - If V(true), the payload matches Rocket Chat prior to 7.4.0 format + - The default value of the parameter can be set to false in a few months' time + - This parameter will be removed in a future release when Rocket Chat 7.4.0 is considered the minimum version to use type: bool default: true + version_added: 10.5.0 """ EXAMPLES = r""" @@ -170,7 +173,7 @@ ROCKETCHAT_INCOMING_WEBHOOK = '%s://%s/hooks/%s' -def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, option_is_pre740): +def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, is_pre740): payload = {} if color == "normal" and text is not None: payload = dict(text=text) @@ -201,7 +204,7 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon payload['attachments'].append(attachment) payload = module.jsonify(payload) - if option_is_pre740: + if is_pre740: payload = "payload=" + module.jsonify(payload) return payload @@ -233,7 +236,7 @@ def main(): validate_certs=dict(default=True, type='bool'), color=dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']), attachments=dict(type='list', elements='dict', required=False), - option_is_pre740=dict(default=True, type='bool') + is_pre740=dict(default=True, type='bool') ) ) @@ -248,9 +251,9 @@ def main(): link_names = module.params['link_names'] color = module.params['color'] attachments = module.params['attachments'] - option_is_pre740 = module.params['option_is_pre740'] + is_pre740 = module.params['is_pre740'] - payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, option_is_pre740) + payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, is_pre740) do_notify_rocketchat(module, domain, token, protocol, payload) module.exit_json(msg="OK") From 33825b791b444105bcc1d6a6e618d5e3d7825be7 Mon Sep 17 00:00:00 2001 From: ludovic Date: Wed, 19 Mar 2025 08:59:43 +0100 Subject: [PATCH 08/11] Use appropriate change label and fix change description. Description about future plans for the parameter is now set at the parameter doc level --- ...9882-fix-payload-to-match-rocketchat-740-requirement.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml index 786b01c0213..d6a820d07ee 100644 --- a/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml +++ b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml @@ -1,4 +1,2 @@ -deprecated_features: - - > - RocketChat module - attribute ``option_is_pre740`` has been added to match the old payload. The argument default value could be set to false in a few months and then, - removed in a future release when Rocket Chat 7.4.0 is considered as a minimum version to be used (https://github.com/ansible-collections/community.general/pull/9882). +minor_changes: + - rocketchat - parameter ``option_is_pre740`` has been added to control the format of the old payload (https://github.com/ansible-collections/community.general/pull/9882) From b620315585e6a5ce44cc909ecaae73dbb5c36ba7 Mon Sep 17 00:00:00 2001 From: ludovic Date: Fri, 21 Mar 2025 09:11:13 +0100 Subject: [PATCH 09/11] Fix missing punctuation in the new parameter doc block --- plugins/modules/rocketchat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index 5fa782a3d64..e39b125cbd0 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -102,9 +102,9 @@ - Define a list of attachments. is_pre740: description: - - If V(true), the payload matches Rocket Chat prior to 7.4.0 format - - The default value of the parameter can be set to false in a few months' time - - This parameter will be removed in a future release when Rocket Chat 7.4.0 is considered the minimum version to use + - If V(true), the payload matches Rocket Chat prior to 7.4.0 format. + - The default value of the parameter can be set to false in a few months' time. + - This parameter will be removed in a future release when Rocket Chat 7.4.0 becomes the minimum supported version. type: bool default: true version_added: 10.5.0 From 183d1fbd33161344b3374b5c11213f39473c9711 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 23 Mar 2025 21:53:36 +0100 Subject: [PATCH 10/11] Improve documentation. --- ...9882-fix-payload-to-match-rocketchat-740-requirement.yml | 2 +- plugins/modules/rocketchat.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml index d6a820d07ee..8d3c76d963d 100644 --- a/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml +++ b/changelogs/fragments/9882-fix-payload-to-match-rocketchat-740-requirement.yml @@ -1,2 +1,2 @@ minor_changes: - - rocketchat - parameter ``option_is_pre740`` has been added to control the format of the old payload (https://github.com/ansible-collections/community.general/pull/9882) + - rocketchat - option ``is_pre740`` has been added to control the format of the payload. For Rocket.Chat 7.4.0 or newer, it must be set to ``false`` (https://github.com/ansible-collections/community.general/pull/9882). diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index e39b125cbd0..eaac847bf50 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -102,9 +102,9 @@ - Define a list of attachments. is_pre740: description: - - If V(true), the payload matches Rocket Chat prior to 7.4.0 format. - - The default value of the parameter can be set to false in a few months' time. - - This parameter will be removed in a future release when Rocket Chat 7.4.0 becomes the minimum supported version. + - If V(true), the payload matches Rocket.Chat prior to 7.4.0 format. This format has been used by the module since its inception, but is no longer supported by Rocket.Chat 7.4.0. + - The default value of the option will change to V(false) eventually. + - This parameter will be removed in a future release when Rocket.Chat 7.4.0 becomes the minimum supported version. type: bool default: true version_added: 10.5.0 From 0c5d9ca16b2c213f80ede0be394358323eeba387 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 23 Mar 2025 22:01:42 +0100 Subject: [PATCH 11/11] Fix line length. --- plugins/modules/rocketchat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/rocketchat.py b/plugins/modules/rocketchat.py index eaac847bf50..91192875dc7 100644 --- a/plugins/modules/rocketchat.py +++ b/plugins/modules/rocketchat.py @@ -102,7 +102,8 @@ - Define a list of attachments. is_pre740: description: - - If V(true), the payload matches Rocket.Chat prior to 7.4.0 format. This format has been used by the module since its inception, but is no longer supported by Rocket.Chat 7.4.0. + - If V(true), the payload matches Rocket.Chat prior to 7.4.0 format. + This format has been used by the module since its inception, but is no longer supported by Rocket.Chat 7.4.0. - The default value of the option will change to V(false) eventually. - This parameter will be removed in a future release when Rocket.Chat 7.4.0 becomes the minimum supported version. type: bool