Skip to content

Commit

Permalink
Merge pull request #2 from splunk-soar-connectors/fix-pipeline
Browse files Browse the repository at this point in the history
Fix linting & semgrep failures
  • Loading branch information
cpangam authored Apr 18, 2022
2 parents 88a788a + 939b98a commit 570bb8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions awsinspector.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"product_name": "Inspector",
"product_version_regex": ".*",
"publisher": "Splunk",
"license": "Copyright (c) 2019-2021 Splunk Inc.",
"license": "Copyright (c) 2019-2022 Splunk Inc.",
"app_version": "2.2.10",
"utctime_updated": "2022-01-07T21:56:46.000000Z",
"package_name": "phantom_awsinspector",
"main_module": "awsinspector_connector.py",
"min_phantom_version": "5.0.0",
"min_phantom_version": "5.2.0",
"fips_compliant": true,
"latest_tested_versions": [
"Cloud tested on July 29th, 2021"
Expand Down
46 changes: 27 additions & 19 deletions awsinspector_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
#
#
# Phantom App imports
import phantom.app as phantom
from phantom.base_connector import BaseConnector
from phantom.action_result import ActionResult
from awsinspector_consts import *
import ast
import datetime
import json
import sys

import phantom.app as phantom
# Usage of the consts file is recommended
import requests
import json
import datetime
from boto3 import client, Session
from boto3 import Session, client
from botocore.config import Config
from dateutil.tz import tzlocal
import ast
from phantom.action_result import ActionResult
from phantom.base_connector import BaseConnector

from awsinspector_consts import *


class RetVal(tuple):
Expand Down Expand Up @@ -247,8 +249,8 @@ def _handle_list_targets(self, param):
else:
failure_code = res.get('failedItems', {}).get(target, {}).get('failureCode')
error_message = failure_code if failure_code else 'Unknown error'
return action_result.set_status(
phantom.APP_ERROR, 'Error occurred while fetching the details of the assessment target: {0}. Error: {1}'.format(target, error_message))
return action_result.set_status(phantom.APP_ERROR,
'Error occurred while fetching the details of the assessment target: {0}. Error: {1}'.format(target, error_message))

for key, value in list(assessment_target.items()):
if isinstance(value, datetime.datetime):
Expand Down Expand Up @@ -309,8 +311,8 @@ def _handle_list_templates(self, param):
else:
failure_code = res.get('failedItems', {}).get(template, {}).get('failureCode')
error_message = failure_code if failure_code else 'Unknown error'
return action_result.set_status(
phantom.APP_ERROR, 'Error occurred while fetching the details of the assessment template: {0}. Error: {1}'.format(template, error_message))
return action_result.set_status(phantom.APP_ERROR,
'Error occurred while fetching the details of the assessment template: {0}. Error: {1}'.format(template, error_message))

for key, value in list(assessment_template.items()):
if isinstance(value, datetime.datetime):
Expand All @@ -324,6 +326,7 @@ def _handle_list_templates(self, param):
summary = action_result.update_summary({})
summary['total_templates'] = action_result.get_data_size()

self.save_progress("Handle list templates succeeded")
return action_result.set_status(phantom.APP_SUCCESS)

def _handle_add_target(self, param):
Expand Down Expand Up @@ -364,6 +367,7 @@ def _handle_add_target(self, param):
summary = action_result.update_summary({})
summary['total_target_arn'] = action_result.get_data_size()

self.save_progress("Handle add target succeeded")
return action_result.set_status(phantom.APP_SUCCESS, "Target successfully added")

def _handle_run_assessment(self, param):
Expand Down Expand Up @@ -409,8 +413,8 @@ def _handle_run_assessment(self, param):
else:
failure_code = res.get('failedItems', {}).get(assessment_run_arn, {}).get('failureCode')
error_message = failure_code if failure_code else 'Unknown error'
return action_result.set_status(
phantom.APP_ERROR, 'Error occurred while fetching the details of the assessment run: {0}. Error: {1}'.format(assessment_run_arn, error_message))
return action_result.set_status(phantom.APP_ERROR,
'Error occurred while fetching the details of the assessment run: {0}. Error: {1}'.format(assessment_run_arn, error_message))

for key, value in list(assessment_run.items()):
if isinstance(value, datetime.datetime):
Expand All @@ -432,6 +436,7 @@ def _handle_run_assessment(self, param):
summary = action_result.update_summary({})
summary['assessment_run_arn'] = assessment_run_arn

self.save_progress("Handle run assessment succeeded")
return action_result.set_status(phantom.APP_SUCCESS)

def _handle_get_findings(self, param):
Expand Down Expand Up @@ -492,8 +497,8 @@ def _handle_get_findings(self, param):
if isinstance(value, datetime.datetime):
finding[key] = str(value)
else:
return action_result.set_status(
phantom.APP_ERROR, 'Error occurred while fetching the details of the findings: {0}'.format(str(list_findings[:min(10, len(list_findings))])))
return action_result.set_status(phantom.APP_ERROR,
'Error occurred while fetching the details of the findings: {0}'.format(str(list_findings[:min(10, len(list_findings))])))

for finding_detail in findings:
action_result.add_data(finding_detail)
Expand All @@ -503,6 +508,7 @@ def _handle_get_findings(self, param):
summary = action_result.update_summary({})
summary['total_findings'] = action_result.get_data_size()

self.save_progress("Handle get findings succeeded")
return action_result.set_status(phantom.APP_SUCCESS)

def _handle_delete_target(self, param):
Expand Down Expand Up @@ -536,6 +542,7 @@ def _handle_delete_target(self, param):

action_result.add_data(response)

self.save_progress("Handle delete target succeeded")
return action_result.set_status(phantom.APP_SUCCESS, "Target is deleted successfully")

def _paginator(self, method_name, limit, action_result, **kwargs):
Expand Down Expand Up @@ -613,9 +620,10 @@ def handle_action(self, param):

if __name__ == '__main__':

import pudb
import argparse

import pudb

pudb.set_trace()

argparser = argparse.ArgumentParser()
Expand Down Expand Up @@ -657,7 +665,7 @@ def handle_action(self, param):
session_id = r2.cookies['sessionid']
except Exception as e:
print("Unable to get session id from the platform. Error: {0}".format(str(e)))
exit(1)
sys.exit(1)

with open(args.input_test_json) as f:
in_json = f.read()
Expand All @@ -674,4 +682,4 @@ def handle_action(self, param):
ret_val = connector._handle_action(json.dumps(in_json), None)
print(json.dumps(json.loads(ret_val), indent=4))

exit(0)
sys.exit(0)
1 change: 1 addition & 0 deletions release_notes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**Unreleased**
* Marked the app as FIPS Compliant [PAPP-21855]

0 comments on commit 570bb8e

Please sign in to comment.