diff --git a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.py b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.py index 04489eb8db39..cdb89aa4f275 100644 --- a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.py +++ b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.py @@ -698,6 +698,7 @@ def publish_message_command( project_id: str, data: str = None, attributes: str = None, + delim_char_attributes: str = ",", ) -> Tuple[str, dict, dict]: """ Publishes message in the topic @@ -711,9 +712,10 @@ def publish_message_command( :param attributes: message attributes separated by key=val pairs sepearated by ',' :param data: message data str :param client: GoogleClient + :param delim_char_attributes: delimiter character between atrribute pairs :return: list of topics """ - body = get_publish_body(attributes, data) + body = get_publish_body(attributes, data, delim_char_attributes) published_messages = client.publish_message(project_id, topic_id, body) output = [] @@ -740,11 +742,12 @@ def publish_message_command( ) -def get_publish_body(message_attributes, message_data): +def get_publish_body(message_attributes, message_data, delim_char): """ Creates publish messages body from given arguments :param message_attributes: message attributes :param message_data: message data + :param delim_char: delimiter character between atrribute pairs :return: publish message body """ message = {} @@ -752,7 +755,7 @@ def get_publish_body(message_attributes, message_data): # convert to base64 string message["data"] = base64.b64encode(message_data.encode("utf8")).decode('utf8') if message_attributes: - message["attributes"] = attribute_pairs_to_dict(message_attributes) + message["attributes"] = attribute_pairs_to_dict(message_attributes, delim_char) body = {"messages": [message]} return body diff --git a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.yml b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.yml index 22a313d7ccad..48bca2bb61fb 100644 --- a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.yml +++ b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.yml @@ -105,6 +105,10 @@ script: name: attributes - description: Project ID. name: project_id + - description: Set delimiter of attributes split + name: delim_char_attributes + defaultValue: ',' + type: unknown description: Publish a message in a topic. name: gcp-pubsub-topic-publish-message outputs: @@ -526,7 +530,7 @@ script: required: true description: Acknowledge previously pulled message or messages. name: gcp-pubsub-topic-ack-messages - dockerimage: demisto/googleapi-python3:1.0.0.64222 + dockerimage: demisto/googleapi-python3:1.0.0.71902 isfetch: true runonce: false script: '-' diff --git a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub_test.py b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub_test.py index 5a2a84e13b7c..04a393dc6fed 100644 --- a/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub_test.py +++ b/Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub_test.py @@ -169,7 +169,7 @@ def test_get_publish_body__invalid(self): # invalid message_data e_thrown = False try: - get_publish_body("", message_data={"test": "val"}) + get_publish_body("", message_data={"test": "val"}, delim_char=",") except AttributeError: e_thrown = True assert e_thrown @@ -177,7 +177,7 @@ def test_get_publish_body__invalid(self): # invalid message_attributes e_thrown = False try: - get_publish_body(message_attributes={"test": "val"}, message_data="") + get_publish_body(message_attributes={"test": "val"}, message_data="", delim_char=",") except AttributeError: e_thrown = True assert e_thrown @@ -192,7 +192,7 @@ def test_get_publish_body__empty(self): - return a body with no messages """ expected = {"messages": [{}]} - assert expected == get_publish_body("", "") + assert expected == get_publish_body("", "", "") def test_get_publish_body__valid(self): """ @@ -218,7 +218,7 @@ def test_get_publish_body__valid(self): "messages": [{"data": expected_data, "attributes": expected_attributes}] } assert expected == get_publish_body( - attrs_str, TestHelperFunctions.DECODED_B64_MESSAGE + attrs_str, TestHelperFunctions.DECODED_B64_MESSAGE, delim_char=",", ) class TestAttributePairsToDict: diff --git a/Packs/GooglePubSub/Integrations/GooglePubSub/README.md b/Packs/GooglePubSub/Integrations/GooglePubSub/README.md index 71f7be9078af..156e8f6ced28 100644 --- a/Packs/GooglePubSub/Integrations/GooglePubSub/README.md +++ b/Packs/GooglePubSub/Integrations/GooglePubSub/README.md @@ -94,6 +94,7 @@ Publish a message in a topic. | data | The message data field. If this field is empty, the message must contain at least one attribute. | Optional | | attributes | Attributes for this message. If this field is empty, the message must contain non-empty data. Input format: "key=val" pairs sepearated by ",". | Optional | | project_id | Project ID. | Optional | +| delim_char_attributes | Set delimiter of attributes split. | Optional | ##### Context Output @@ -107,7 +108,7 @@ Publish a message in a topic. ##### Command Example -```!gcp-pubsub-topic-publish-message data="42 is the answer" project_id=dmst-integrations topic_id=dmst-topic``` +```!gcp-pubsub-topic-publish-message data="42 is the answer" project_id=dmst-integrations topic_id=dmst-topic delim_char_attributes=","``` ##### Context Example ``` @@ -116,7 +117,8 @@ Publish a message in a topic. "attributes": null, "data": "42 is the answer", "messageId": "874663628353499", - "topic": "dmst-topic" + "topic": "dmst-topic", + "delim_char_attributes": "," } } ``` diff --git a/Packs/GooglePubSub/ReleaseNotes/1_1_0.md b/Packs/GooglePubSub/ReleaseNotes/1_1_0.md new file mode 100644 index 000000000000..ee80d778c3a9 --- /dev/null +++ b/Packs/GooglePubSub/ReleaseNotes/1_1_0.md @@ -0,0 +1,7 @@ + +#### Integrations + +##### Google Cloud Pub/Sub + +- Added a new possibility to choose delimiter of attributes. +- Updated the Docker image to: *demisto/googleapi-python3:1.0.0.71902*. \ No newline at end of file diff --git a/Packs/GooglePubSub/pack_metadata.json b/Packs/GooglePubSub/pack_metadata.json index 6bbb781d1ec1..19374b87ebe0 100644 --- a/Packs/GooglePubSub/pack_metadata.json +++ b/Packs/GooglePubSub/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Google Cloud Pub / Sub", "description": "Google Cloud Pub / Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications.", "support": "xsoar", - "currentVersion": "1.0.27", + "currentVersion": "1.1.0", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",