Skip to content

Commit

Permalink
run black linter, fix unit tests and validators (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
llaszuk-r7 authored and joneill-r7 committed Nov 14, 2024
1 parent d53b0b0 commit 2dbae4d
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 78 deletions.
6 changes: 3 additions & 3 deletions plugins/armorblox/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"spec": "406fd799fb05d81464ed8cb863ea1f56",
"spec": "cdf4d5d0aa4fb40b0a8d9ee3761ad09b",
"manifest": "433b5ba19020a0a518c333be03af4eab",
"setup": "67d906e679bb88b8e56aa98bc008d58b",
"schemas": [
Expand All @@ -13,7 +13,7 @@
},
{
"identifier": "get_incidents/schema.py",
"hash": "cc8737d06f9995ac1c317d6e0093cef6"
"hash": "af802290919168df0cbffcb432629043"
}
]
}
}
12 changes: 6 additions & 6 deletions plugins/armorblox/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Example input:

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|remediation_details|string|True|Remediation action of the requested incident identified by Armorblox|
|Name|Type|Required|Description|Example|
|----|----|--------|-----------|-------|
|remediation_details|string|True|Remediation action of the requested incident identified by Armorblox|ALERT|

Example output:
```
Expand Down Expand Up @@ -91,9 +91,9 @@ Example input:

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|incidents|[]incident|True|A list of incidents identified by Armorblox|
|Name|Type|Required|Description|Example|
|----|----|--------|-----------|-------|
|incidents|[]incident|True|A list of incidents identified by Armorblox|{"incidents": "some incidents"}|

Example output:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import insightconnect_plugin_runtime
from .schema import GetRemediationActionInput, GetRemediationActionOutput, Input, Output, Component

# Custom imports below


class GetRemediationAction(insightconnect_plugin_runtime.Action):

def __init__(self):
super(self.__class__, self).__init__(
name='get_remediation_action',
description=Component.DESCRIPTION,
input=GetRemediationActionInput(),
output=GetRemediationActionOutput())
name="get_remediation_action",
description=Component.DESCRIPTION,
input=GetRemediationActionInput(),
output=GetRemediationActionOutput(),
)

def run(self, params={}):
remediation_details = self.connection.api.get_remediation_action(params.get(Input.INCIDENT_ID))
return {Output.REMEDIATION_DETAILS: remediation_details}

8 changes: 3 additions & 5 deletions plugins/armorblox/icon_armorblox/connection/connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import insightconnect_plugin_runtime
from .schema import ConnectionSchema, Input
from insightconnect_plugin_runtime.exceptions import PluginException, ConnectionTestException

# Custom imports below
from icon_armorblox.util.api import ArmorbloxAPI


class Connection(insightconnect_plugin_runtime.Connection):

def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())
self.api = None
Expand All @@ -15,13 +15,11 @@ def connect(self, params):
self.logger.info("Connect: Connecting...")
api_key = params.get(Input.API_KEY, {}).get("secretKey")
tenant_name = params.get(Input.TENANT_NAME)
self.api = ArmorbloxAPI(api_key = api_key, tenant_name = tenant_name, logger=self.logger)
self.api = ArmorbloxAPI(api_key=api_key, tenant_name=tenant_name, logger=self.logger)

def test(self):
try:
self.api.test_api()
return {"success": True}
except PluginException as error:
raise ConnectionTestException(
cause=error.cause, assistance=error.assistance, data=error.data
)
raise ConnectionTestException(cause=error.cause, assistance=error.assistance, data=error.data)
32 changes: 16 additions & 16 deletions plugins/armorblox/icon_armorblox/triggers/get_incidents/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
"properties": {
"detection_tag_id": {
"type": "string",
"title": "Detection tag ID",
"title": "Detection Tag ID",
"description": "Detection tag ID",
"order": 1
},
"detection_tag_name": {
"type": "string",
"title": "Detection tag name",
"title": "Detection Tag name",
"description": "Detection tag name",
"order": 2
}
Expand Down Expand Up @@ -120,7 +120,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"external_senders": {
"type": "array",
"title": "External senders",
"title": "External Senders",
"description": "List of external senders",
"items": {
"type": "string"
Expand All @@ -129,7 +129,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"external_users": {
"type": "array",
"title": "External users",
"title": "External Users",
"description": "List of external users",
"items": {
"$ref": "#/definitions/user"
Expand All @@ -138,7 +138,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"final_detection_tags": {
"type": "array",
"title": "Detection tags",
"title": "Detection Tags",
"description": "Detection tags",
"items": {
"$ref": "#/definitions/final_detection_tag"
Expand All @@ -147,7 +147,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"folder_categories": {
"type": "array",
"title": "Folder categories",
"title": "Folder Categories",
"description": "Folder categories",
"items": {
"type": "string"
Expand All @@ -174,7 +174,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"policy_names": {
"type": "array",
"title": "policy_names",
"title": "policy Names",
"description": "List of policies",
"items": {
"type": "string"
Expand All @@ -198,7 +198,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"resolution_state": {
"type": "string",
"title": "resolution_state",
"title": "Resolution State",
"description": "Incident resolution state",
"order": 6
},
Expand All @@ -215,13 +215,13 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"title": {
"type": "string",
"title": "Subject",
"title": "Title",
"description": "Mail subject",
"order": 5
},
"users": {
"type": "array",
"title": "users",
"title": "Users",
"description": "List of users",
"items": {
"$ref": "#/definitions/user"
Expand Down Expand Up @@ -254,13 +254,13 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
"properties": {
"detection_tag_id": {
"type": "string",
"title": "Detection tag ID",
"title": "Detection Tag ID",
"description": "Detection tag ID",
"order": 1
},
"detection_tag_name": {
"type": "string",
"title": "Detection tag name",
"title": "Detection Tag name",
"description": "Detection tag name",
"order": 2
}
Expand All @@ -272,7 +272,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
"properties": {
"email": {
"type": "string",
"title": "User email",
"title": "User Email",
"description": "Email of the user",
"order": 2
},
Expand All @@ -284,7 +284,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"name": {
"type": "string",
"title": "User name",
"title": "User Name",
"description": "Name of the user",
"order": 1
}
Expand All @@ -298,7 +298,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
"properties": {
"email": {
"type": "string",
"title": "User email",
"title": "User Email",
"description": "Email of the user",
"order": 2
},
Expand All @@ -310,7 +310,7 @@ class GetIncidentsOutput(insightconnect_plugin_runtime.Output):
},
"name": {
"type": "string",
"title": "User name",
"title": "User Name",
"description": "Name of the user",
"order": 1
}
Expand Down
21 changes: 14 additions & 7 deletions plugins/armorblox/icon_armorblox/triggers/get_incidents/trigger.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import insightconnect_plugin_runtime
import time
from datetime import datetime, timedelta
from icon_armorblox.util.constants import ARMORBLOX_INCIDENT_API_TIME_FORMAT, ARMORBLOX_INCIDENT_API_TIME_DELTA_IN_DAYS, DEFAULT_INTERVAL_VALUE
from icon_armorblox.util.constants import (
ARMORBLOX_INCIDENT_API_TIME_FORMAT,
ARMORBLOX_INCIDENT_API_TIME_DELTA_IN_DAYS,
DEFAULT_INTERVAL_VALUE,
)
from .schema import GetIncidentsInput, GetIncidentsOutput, Input, Output, Component

# Custom imports below

class GetIncidents(insightconnect_plugin_runtime.Trigger):

class GetIncidents(insightconnect_plugin_runtime.Trigger):
def __init__(self):
super(self.__class__, self).__init__(
name='get_incidents',
description=Component.DESCRIPTION,
input=GetIncidentsInput(),
output=GetIncidentsOutput())
name="get_incidents",
description=Component.DESCRIPTION,
input=GetIncidentsInput(),
output=GetIncidentsOutput(),
)

def run(self, params={}):
"""Run the trigger"""
fetch_interval = params.get(Input.INTERVAL, DEFAULT_INTERVAL_VALUE)
# First fetch
last_fetch_time = (datetime.utcnow() - timedelta(days={ARMORBLOX_INCIDENT_API_TIME_DELTA_IN_DAYS})).strftime(
{ARMORBLOX_INCIDENT_API_TIME_FORMAT})
{ARMORBLOX_INCIDENT_API_TIME_FORMAT}
)
while True:
current_time = datetime.utcnow().replace(second=0).strftime({ARMORBLOX_INCIDENT_API_TIME_FORMAT})
events = self.connection.api.get_incidents(from_date=last_fetch_time, to_date=current_time)
Expand Down
25 changes: 10 additions & 15 deletions plugins/armorblox/icon_armorblox/util/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,33 @@


class ArmorbloxAPI(Client):

def __init__(self, api_key: str, tenant_name: str, logger = Logger):
def __init__(self, api_key: str, tenant_name: str, logger=Logger):
super().__init__(api_key=api_key, instance_name=tenant_name)
self.logger = logger
self.incidents_list = []

def process_incidents(self, params):
self.incidents_list = []
try:
response_json, next_page_token, total_count = self.incidents.list(params=params)
response_json, next_page_token, _ = self.incidents.list(params=params)
self.incidents_list.extend(response_json)
while next_page_token:
params["page_token"] = next_page_token
response_json, next_page_token, total_count = self.incidents.list(params=params)
response_json, next_page_token, _ = self.incidents.list(params=params)
self.incidents_list.extend(response_json)
except Exception as credentials_exp:
PluginException('Incorrect Credentials. ' + str(credentials_exp))
PluginException("Incorrect Credentials. " + str(credentials_exp))

def get_incidents(self, from_date: str = None, to_date: str = None):
"""
Hits the Armorblox API and fetch incidents.
:param from_date: Custom time filter parameter
:param to_date: Custom time filter parameter
:return: List of incidents
"""
params = {
"from_date": from_date,
"to_date": to_date,
"orderBy": "ASC"
}
params = {"from_date": from_date, "to_date": to_date, "orderBy": "ASC"}
self.process_incidents(params)
return self.incidents_list

Expand All @@ -46,10 +41,10 @@ def get_remediation_action(self, incident_id):
Returns the remediation action(s) for the input incident.
"""
rm_action_response = self.incidents.get(incident_id)
if 'remediation_actions' in rm_action_response.keys():
remediation_actions = rm_action_response['remediation_actions'][0]
if "remediation_actions" in rm_action_response.keys():
remediation_actions = rm_action_response["remediation_actions"][0]
else:
remediation_actions = ''
remediation_actions = ""
return remediation_actions

def test_api(self):
Expand Down
3 changes: 2 additions & 1 deletion plugins/armorblox/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# List third-party dependencies here, separated by newlines.
# All dependencies must be version-pinned, eg. requests==1.2.0
# See: https://pip.pypa.io/en/stable/user_guide/#requirements-files
armorblox-sdk==0.1.4
armorblox-sdk==0.1.4
parameterized==0.8.1
7 changes: 3 additions & 4 deletions plugins/armorblox/unit_test/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

sys.path.append(os.path.abspath("../"))
import logging
from unittest import TestCase, mock
from unittest import TestCase

from insightconnect_plugin_runtime.exceptions import ConnectionTestException

from icon_armorblox.connection.connection import Connection
from icon_armorblox.connection.schema import Input
Expand All @@ -19,10 +18,10 @@ def setUp(self) -> None:
def test_connection_ok(self):
self.connection.connect(
{
Input.API_KEY: "any-api-key",
Input.API_KEY: {"secretKey": "any-api-key"},
Input.TENANT_NAME: "my-tenant-name",
}
)
response = self.connection.test()
expected_response = []
expected_response = {"success": True}
self.assertEqual(response, expected_response)
Loading

0 comments on commit 2dbae4d

Please sign in to comment.