From 30ad952c4453bb8f9b8b95efe1a23402dfd1ff85 Mon Sep 17 00:00:00 2001 From: Md Azam <39527649+mdazam1942@users.noreply.github.com> Date: Tue, 26 Nov 2019 19:34:54 -0400 Subject: [PATCH] Fix module not found error for utils (#213) --- requirements.txt | 2 +- setup.py | 2 +- .../src/modules/security_advisor/__init__.py | 0 .../modules/security_advisor/security_advisor_auth.py | 2 +- .../security_advisor/security_advisor_connector.py | 4 ---- .../modules/security_advisor/security_advisor_ping.py | 10 +++++++--- .../security_advisor_results_connector.py | 11 +++++++---- .../src/modules/security_advisor/utils/__init__.py | 0 8 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 stix_shifter/stix_translation/src/modules/security_advisor/__init__.py create mode 100644 stix_shifter/stix_transmission/src/modules/security_advisor/utils/__init__.py diff --git a/requirements.txt b/requirements.txt index 1900b7c3e..71eec4d5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -stix2-patterns==1.1.0 +stix2-patterns>=1.1.0 stix2-validator>=0.5.0 python-dateutil>=2.7.3 antlr4-python3-runtime==4.7 diff --git a/setup.py b/setup.py index f45a4faf3..f4736eb44 100644 --- a/setup.py +++ b/setup.py @@ -134,7 +134,7 @@ # # For an analysis of "install_requires" vs pip's requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=['stix2-patterns==1.1.0', 'stix2-validator>=0.5.0', + install_requires=['stix2-patterns>=1.1.0', 'stix2-validator>=0.5.0', 'antlr4-python3-runtime==4.7', 'python-dateutil>=2.7.3', 'xmltodict>=0.11.0', 'requests_toolbelt==0.9.1', 'adal>=1.2.2', 'flatten_json==0.1.7' # ,'stix2-matcher@https://github.com/oasis-open/cti-pattern-matcher/archive/v0.1.0.zip#egg=stix2-matcher' # uncomment when running setup.py locally diff --git a/stix_shifter/stix_translation/src/modules/security_advisor/__init__.py b/stix_shifter/stix_translation/src/modules/security_advisor/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_auth.py b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_auth.py index 23ff2592b..cbba63d92 100644 --- a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_auth.py +++ b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_auth.py @@ -10,7 +10,7 @@ def obtainAccessToken(self): raise Exception("Authorizaion Failed") iamTokenURL = 'https://iam.cloud.ibm.com/identity/token' - requestBody = "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey="+ self.apiKey +"&response_type=cloud_iam" + requestBody = "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey={}&response_type=cloud_iam".format(self.apiKey) header = { 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_connector.py b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_connector.py index 7084caaf7..19d569911 100644 --- a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_connector.py +++ b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_connector.py @@ -4,16 +4,12 @@ from .security_advisor_status_connector import SecurityAdvisorStatusConnector from .security_advisor_results_connector import SecurityAdvisorResultsConnector from .security_advisor_delete_connector import SecurityAdvisorDeleteConnector -from .security_advisor_auth import SecurityAdvisorAuth class Connector(BaseConnector): def __init__(self, connection, configuration): auth = configuration.get("auth") - api_key = auth.get("apiKey") host = connection.get("host") - auth_token = SecurityAdvisorAuth(api_key) - auth["authToken"] = auth_token self.query_connector = SecurityAdvisorQueryConnector(host, auth) self.status_connector = SecurityAdvisorStatusConnector(host, auth) diff --git a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_ping.py b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_ping.py index 53ea075e0..12e055efb 100644 --- a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_ping.py +++ b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_ping.py @@ -1,11 +1,15 @@ from ..base.base_ping import BasePing import requests from .....utils.error_response import ErrorResponder +from .security_advisor_auth import SecurityAdvisorAuth + class SecurityAdvisorPing(BasePing): def __init__(self, host, auth): self.host = host self.auth = auth + api_key = auth.get("apiKey") + self.auth_token = SecurityAdvisorAuth(api_key) def ping(self): return_obj = {} @@ -14,12 +18,12 @@ def ping(self): 'Accept': 'application/json' } url = self.host + self.auth["accountID"] + "/providers" - try : - authorization ='Bearer ' + self.auth["authToken"].obtainAccessToken() + try: + authorization = "Bearer {}".format(self.auth_token.obtainAccessToken()) header["Authorization"] = authorization except Exception as e: - ErrorResponder.fill_error(return_obj, {'code':"Authorizaion Failed"}, message= str(e)) + ErrorResponder.fill_error(return_obj, {'code':"Authorizaion Failed"}, message=str(e)) return return_obj try: diff --git a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_results_connector.py b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_results_connector.py index 5294a25f2..b7bbb0531 100644 --- a/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_results_connector.py +++ b/stix_shifter/stix_transmission/src/modules/security_advisor/security_advisor_results_connector.py @@ -1,12 +1,15 @@ from ..base.base_results_connector import BaseResultsConnector from .utils.stix_pattern_processor import StixPatternProcessor from .....utils.error_response import ErrorResponder +from .security_advisor_auth import SecurityAdvisorAuth class SecurityAdvisorResultsConnector(BaseResultsConnector): def __init__(self, host, auth ): self.host = host self.auth = auth + api_key = auth.get("apiKey") + self.auth_token = SecurityAdvisorAuth(api_key) self.StixPatternProcessor = StixPatternProcessor() def create_results_connection(self, searchID , offset , length): @@ -16,15 +19,15 @@ def create_results_connection(self, searchID , offset , length): params["accountID"] = self.auth.get("accountID") params["host"] = self.host - try : - params["accessToken"] = self.auth["authToken"].obtainAccessToken() + try: + params["accessToken"] = self.auth_token.obtainAccessToken() except Exception as e: ErrorResponder.fill_error(return_obj, {'code':"Authorizaion Failed"}, message= str(e)) return return_obj - try : - data = self.StixPatternProcessor.process(searchID,params) + try: + data = self.StixPatternProcessor.process(searchID, params) return_obj["success"] = True return_obj["data"] = data return return_obj diff --git a/stix_shifter/stix_transmission/src/modules/security_advisor/utils/__init__.py b/stix_shifter/stix_transmission/src/modules/security_advisor/utils/__init__.py new file mode 100644 index 000000000..e69de29bb