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

[MC-751] - ServiceNow Get Attachments for an Incident #1054

Merged
merged 1 commit into from
Jan 10, 2022
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
8 changes: 4 additions & 4 deletions plugins/servicenow/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "94a012dce3dbe3d18e71a3e6f59bfcce",
"manifest": "a5b5f251a2c5b6cbc83db3db2022d8b5",
"setup": "c876bdc35376c6287e582200ea7e2761",
"spec": "e23584dc8ec1d9ffd6f301de6609b76a",
"manifest": "85a12a5377d2a993c6666fee3b2acd66",
"setup": "d62b866092d8128bde1fb2e858612947",
"schemas": [
{
"identifier": "create_ci/schema.py",
Expand All @@ -21,7 +21,7 @@
},
{
"identifier": "get_attachments_for_an_incident/schema.py",
"hash": "b7931b68a7bf9c09e61c2904b8add4e1"
"hash": "2b92dc73a70dcecb1cc718b9d53f68de"
},
{
"identifier": "get_ci/schema.py",
Expand Down
2 changes: 1 addition & 1 deletion plugins/servicenow/bin/icon_servicenow
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from sys import argv

Name = "ServiceNow"
Vendor = "rapid7"
Version = "5.2.0"
Version = "6.0.0"
Description = "ServiceNow is a tool for managing incidents and configuration management. Using the ServiceNow plugin for Rapid7 InsightConnect, users can manage all aspects of incidents including creation, search, updates, as well as monitor them for changes"


Expand Down
10 changes: 7 additions & 3 deletions plugins/servicenow/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ Example input:

|Name|Type|Required|Description|
|----|----|--------|-----------|
|incident_attachments|[]bytes|False|Attachments for a given incident ID|
|incident_attachments|[]attachment_file|False|List of attachments for a given incident ID|

Example output:

```
{
"incident_attachments": [
"UmFwaWQ3IEluc2lnaHRDb25uZWN0Cg==",
"cmFwaWQ3"
{
"content": "9de5069c5afe602b2ea0a04b66beb2c0",
"content_type": "text/plain",
"file_name": "example.txt"
}
]
}
```
Expand Down Expand Up @@ -856,6 +859,7 @@ _This plugin does not contain any troubleshooting information._

# Version History

* 6.0.0 - Add additional file information in output for Get Attachments for an Incident
* 5.2.0 - Add new action Get Attachments for an Incident | Add unit test for action Get Attachments for an Incident and Get Incident Attachment
* 5.1.1 - Fix output parsing bug in Get Incident Attachment action
* 5.1.0 - Add new Incident URL output for Create Incident action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def run(self, params={}):
attachment = response.get("resource").get("result")
attachments = []
for item in attachment:
attachments.append(RequestHelper.get_attachment(self.connection, item.get("sys_id")))
attachments.append(
{
"file_name": item.get("file_name"),
"content": RequestHelper.get_attachment(self.connection, item.get("sys_id")),
"content_type": item.get("content_type"),
}
)

return {Output.INCIDENT_ATTACHMENTS: attachments}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,38 @@ class GetAttachmentsForAnIncidentOutput(insightconnect_plugin_runtime.Output):
"incident_attachments": {
"type": "array",
"title": "Incident Attachments",
"description": "Attachments for a given incident ID",
"description": "List of attachments for a given incident ID",
"items": {
"type": "string",
"displayType": "bytes",
"format": "bytes"
"$ref": "#/definitions/attachment_file"
},
"order": 1
}
},
"definitions": {
"attachment_file": {
"type": "object",
"title": "attachment_file",
"properties": {
"content": {
"type": "string",
"title": "Content",
"description": "File content encoded with base64",
"order": 2
},
"content_type": {
"type": "string",
"title": "Content Type",
"description": "Content type",
"order": 3
},
"file_name": {
"type": "string",
"title": "File Name",
"description": "File name",
"order": 1
}
}
}
}
}
""")
Expand Down
22 changes: 19 additions & 3 deletions plugins/servicenow/plugin.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ products: ["insightconnect"]
name: servicenow
title: ServiceNow
description: ServiceNow is a tool for managing incidents and configuration management. Using the ServiceNow plugin for Rapid7 InsightConnect, users can manage all aspects of incidents including creation, search, updates, as well as monitor them for changes
version: 5.2.0
version: 6.0.0
supported_versions: ["2020-03-11 Orlando"]
vendor: rapid7
support: rapid7
Expand Down Expand Up @@ -64,6 +64,22 @@ types:
description: Either 'comments' or 'work_notes'
type: string
required: true
attachment_file:
file_name:
title: File Name
description: File name
type: string
required: false
content:
title: Content
description: File content encoded with base64
type: string
required: false
content_type:
title: Content Type
description: Content type
type: string
required: false
connection:
url:
title: ServiceNow URL
Expand Down Expand Up @@ -592,8 +608,8 @@ actions:
output:
incident_attachments:
title: Incident Attachments
description: Attachments for a given incident ID
type: "[]bytes"
description: List of attachments for a given incident ID
type: "[]attachment_file"
required: false
triggers:
incident_changed:
Expand Down
2 changes: 1 addition & 1 deletion plugins/servicenow/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


setup(name="servicenow-rapid7-plugin",
version="5.2.0",
version="6.0.0",
description="ServiceNow is a tool for managing incidents and configuration management. Using the ServiceNow plugin for Rapid7 InsightConnect, users can manage all aspects of incidents including creation, search, updates, as well as monitor them for changes",
author="rapid7",
author_email="",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ def setUpClass(cls) -> None:
def test_get_attachments_for_an_incident(self, mock_post):
actual = self.action.run({Input.INCIDENT_ID: "3072d01d07a552f6d0ea83ef29c936be"})

expected = {"incident_attachments": ["ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI="]}
expected = {
"incident_attachments": [
{
"file_name": "testtattatxt",
"content": "ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI=",
"content_type": "text/plain (.txt)",
}
]
}
self.assertEqual(actual, expected)

@patch("requests.sessions.Session.get", side_effect=Util.mocked_requests)
Expand All @@ -28,8 +36,16 @@ def test_get_attachments_for_an_incident_many(self, mock_post):

expected = {
"incident_attachments": [
"ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI=",
"ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI=",
{
"file_name": "testtattatxt",
"content": "ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI=",
"content_type": "text/plain (.txt)",
},
{
"file_name": "testtattatxt",
"content": "ImNtRndhV1EzWVhSMFlXTm9iV1Z1ZEhSbGN6ZzNOalF6TWpKMCI=",
"content_type": "text/plain (.txt)",
},
]
}
self.assertEqual(actual, expected)
Expand Down