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

add changes to set delimiter for attributes split #29010

9 changes: 6 additions & 3 deletions Packs/GooglePubSub/Integrations/GooglePubSub/GooglePubSub.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ def publish_message_command(
project_id: str,
data: str = None,
attributes: str = None,
delim_char_attributes: str = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to be default ',' if possible. Shouldn't make a difference as the default in yml is ',' but in case that is not the case this None could ovveride the next default in attribute_pairs_to_dict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

) -> Tuple[str, dict, dict]:
"""
Publishes message in the topic
Expand All @@ -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 = []
Expand All @@ -740,19 +742,20 @@ 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 = {}
if 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: '-'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ 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

# 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
Expand All @@ -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):
"""
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions Packs/GooglePubSub/Integrations/GooglePubSub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand All @@ -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": ","
}
}
```
Expand Down
7 changes: 7 additions & 0 deletions Packs/GooglePubSub/ReleaseNotes/1_1_0.md
Original file line number Diff line number Diff line change
@@ -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*.
2 changes: 1 addition & 1 deletion Packs/GooglePubSub/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down