Skip to content

Commit

Permalink
[SOAR-17319] Salesforce Task Connection test & SDK Bump (#2706)
Browse files Browse the repository at this point in the history
* Task connection test added & SDK Bump

* Changing logging
  • Loading branch information
rmurray-r7 authored Aug 16, 2024
1 parent 18bcee6 commit 4dd2685
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 12 deletions.
6 changes: 3 additions & 3 deletions plugins/salesforce/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "614111433baf12e2b4c9978da383c358",
"manifest": "f787955b19d27fee238342612ae21af2",
"setup": "b353dce779709f83134551c73df4bb84",
"spec": "c166a47a48becf41d2c88a3753882634",
"manifest": "f0364cb43b4bf407a12631036c01d6d7",
"setup": "eb259279d19b900f538b64c071e204d1",
"schemas": [
{
"identifier": "advanced_search/schema.py",
Expand Down
2 changes: 1 addition & 1 deletion plugins/salesforce/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-plugin:5.4.9
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-plugin:6.1.0

LABEL organization=rapid7
LABEL sdk=python
Expand Down
2 changes: 1 addition & 1 deletion plugins/salesforce/bin/komand_salesforce
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from sys import argv

Name = "Salesforce"
Vendor = "rapid7"
Version = "2.1.8"
Version = "2.1.9"
Description = "The Salesforce plugin allows you to search, update, and manage salesforce records"


Expand Down
3 changes: 2 additions & 1 deletion plugins/salesforce/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,11 @@ Example output:

## Troubleshooting

*There is no troubleshooting for this plugin.*
*This plugin does not contain a troubleshooting.*

# Version History

* 2.1.9 - SDK Bump to 6.1.0 | Task Connection test added
* 2.1.8 - Task Monitor Users: Allow lookback to be 7 days and initial run to be 24 hours & raise PluginException for API errors.
* 2.1.7 - Task Monitor Users: Update connection to accept instance URL and force new token request per execution.
* 2.1.6 - Task Monitor Users: Implement SDK 5.4.4 for custom_config parameter.
Expand Down
47 changes: 47 additions & 0 deletions plugins/salesforce/komand_salesforce/connection/connection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import insightconnect_plugin_runtime

from .schema import ConnectionSchema, Input

# Custom imports below
from komand_salesforce.util.api import SalesforceAPI
from insightconnect_plugin_runtime.exceptions import PluginException, ConnectionTestException
from komand_salesforce.util.exceptions import ApiException
from komand_salesforce.tasks.monitor_users.task import MonitorUsers
from datetime import datetime, timedelta, timezone
from requests.exceptions import ConnectionError as con_err


class Connection(insightconnect_plugin_runtime.Connection):
Expand All @@ -29,3 +34,45 @@ def test(self):
return {"success": True}
except PluginException as error:
raise ConnectionTestException(cause=error.cause, assistance=error.assistance, data=error.data)

def test_task(self):
now = datetime.now(timezone.utc)
start_time = (now - timedelta(minutes=5)).isoformat()
end_time = now.isoformat()

endpoint_mapping = {
"Get Updated Users": [
self.api.query,
MonitorUsers.UPDATED_USERS_QUERY.format(start_timestamp=start_time, end_timestamp=end_time),
],
"Get Users": [self.api.query, MonitorUsers.USERS_QUERY],
"Get User Login History": [
self.api.query,
MonitorUsers.USER_LOGIN_QUERY.format(start_timestamp=start_time, end_timestamp=end_time),
],
}
self.logger.info("Running a connection test to Salesforce")
return_message = "The connection test to Salesforce was successful \n"
error_message = ""
for endpoint, values in endpoint_mapping.items():
try:
self.logger.info(f"Running test for {endpoint}")
return_message += f"Running test for {endpoint} \n"
method_execute, method_params = values[0], values[1]
_ = method_execute(method_params)
return_message += f"{endpoint} has passed \n"
except ApiException as error:
self.logger.info(f"API Exception has been hit. cause = {error.cause}, assistance = {error.assistance}")
error_message += f"An error occurred in the following test: {endpoint}. \nThis can be fixed by: {error.assistance} \n"
except con_err as error:
self.logger.error(error)
error_message += f"The URL provided in the connection for the {endpoint} test is unreachable. Please ensure you are providing a valid URL when trying to connect."
if not error_message:
self.logger.info(return_message)
return {"success": True}, return_message
else:
raise ConnectionTestException(
cause=f"The connection test to Salesforce failed due to: \n {error_message} ",
assistance="The connection test to Salesforce failed. Please ensure all fields are set and have the correct values before attempting again.",
data=error_message,
)
6 changes: 3 additions & 3 deletions plugins/salesforce/komand_salesforce/util/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def query(self, query: str, next_page_id: str = None) -> dict:
next_records_url = response.get("nextRecordsUrl")
return {
"records": response.get("records", []),
"next_page_id": next_records_url[next_records_url.index("query") + len("query") :]
if next_records_url
else None,
"next_page_id": (
next_records_url[next_records_url.index("query") + len("query") :] if next_records_url else None
),
}

def get_updated_users(self, parameters: dict) -> dict:
Expand Down
5 changes: 3 additions & 2 deletions plugins/salesforce/plugin.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ products: [insightconnect]
name: salesforce
title: Salesforce
description: The Salesforce plugin allows you to search, update, and manage salesforce records
version: 2.1.8
version: 2.1.9
connection_version: 2
vendor: rapid7
support: community
Expand All @@ -13,7 +13,7 @@ status: []
supported_versions: ["Salesforce API v58 2023-06-30"]
sdk:
type: full
version: 5.4.9
version: 6.1.0
user: nobody
resources:
source_url: https://github.com/rapid7/insightconnect-plugins/tree/master/plugins/salesforce
Expand All @@ -37,6 +37,7 @@ references:
- "[Connecting your app to the API](https://developer.salesforce.com/docs/atlas.en-us.216.0.api_rest.meta/api_rest/quickstart.htm)"
- "[SOQL](https://developer.salesforce.com/docs/atlas.en-us.216.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm)"
version_history:
- "2.1.9 - SDK Bump to 6.1.0 | Task Connection test added"
- "2.1.8 - Task Monitor Users: Allow lookback to be 7 days and initial run to be 24 hours & raise PluginException for API errors."
- "2.1.7 - Task Monitor Users: Update connection to accept instance URL and force new token request per execution."
- "2.1.6 - Task Monitor Users: Implement SDK 5.4.4 for custom_config parameter."
Expand Down
2 changes: 1 addition & 1 deletion plugins/salesforce/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


setup(name="salesforce-rapid7-plugin",
version="2.1.8",
version="2.1.9",
description="The Salesforce plugin allows you to search, update, and manage salesforce records",
author="rapid7",
author_email="",
Expand Down

0 comments on commit 4dd2685

Please sign in to comment.