Skip to content

Commit

Permalink
Merge pull request #1 from checkmarx-ts/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
nleach999 authored Jun 3, 2024
2 parents 55462d0 + 3bc3b0b commit 5875a49
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
18 changes: 13 additions & 5 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def log():
return logging.getLogger("CxOneFlowConfig")

@staticmethod
def retrieve_services_by_route(clone_urls):
def retrieve_services_by_route(clone_urls, scm_config_key):

if type(clone_urls) is list:
it_list = clone_urls
else:
it_list = [clone_urls]

for url in it_list:
for entry in CxOneFlowConfig.__ordered_scm_config_tuples:
for entry in CxOneFlowConfig.__ordered_scm_config_tuples[scm_config_key]:
if entry[0].match(url):
return entry[1], entry[2]

Expand Down Expand Up @@ -93,7 +93,15 @@ def bootstrap(config_file_path = "./config.yaml"):
if scm in CxOneFlowConfig.__raw.keys():
index = 0
for repo_config_dict in CxOneFlowConfig.__raw[scm]:
CxOneFlowConfig.__setup_scm(CxOneFlowConfig.__cloner_factories[scm], CxOneFlowConfig.__auth_factories[scm], repo_config_dict, f"/{scm}[{index}]")

repo_matcher, cxone_service, scm_service = CxOneFlowConfig.__setup_scm(CxOneFlowConfig.__cloner_factories[scm],
CxOneFlowConfig.__auth_factories[scm], repo_config_dict, f"/{scm}[{index}]")

if not scm in CxOneFlowConfig.__ordered_scm_config_tuples:
CxOneFlowConfig.__ordered_scm_config_tuples[scm] = [(repo_matcher, cxone_service, scm_service)]
else:
CxOneFlowConfig.__ordered_scm_config_tuples[scm].append((repo_matcher, cxone_service, scm_service))

index += 1
except Exception as ex:
CxOneFlowConfig.log().exception(ex)
Expand Down Expand Up @@ -197,7 +205,7 @@ def __cxone_client_factory(config_path, **kwargs):
return None


__ordered_scm_config_tuples = []
__ordered_scm_config_tuples = {}

__minimum_api_auth_keys = ['token', 'password']
__basic_auth_keys = ['username', 'password']
Expand Down Expand Up @@ -297,7 +305,7 @@ def __setup_scm(cloner_factory, api_auth_factory, config_dict, config_path):

scm_service = SCMService(service_moniker, api_session, scm_shared_secret, CxOneFlowConfig.__cloner_factory(cloner_factory, clone_auth_dict, clone_config_path))

CxOneFlowConfig.__ordered_scm_config_tuples.append((repo_matcher, cxone_service, scm_service))
return repo_matcher, cxone_service, scm_service


__cloner_factories = {
Expand Down
2 changes: 1 addition & 1 deletion orchestration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def execute(orchestrator):
return 204

OrchestrationDispatch.log().debug(f"Service lookup: {orchestrator.route_urls}")
cxone_service, scm_service = CxOneFlowConfig.retrieve_services_by_route(orchestrator.route_urls)
cxone_service, scm_service = CxOneFlowConfig.retrieve_services_by_route(orchestrator.route_urls, orchestrator.config_key)
OrchestrationDispatch.log().debug(f"Service lookup success: {orchestrator.route_urls}")

if await orchestrator.is_signature_valid(scm_service.shared_secret):
Expand Down
9 changes: 6 additions & 3 deletions orchestration/adoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class AzureDevOpsEnterpriseOrchestrator(OrchestratorBase):

__diag_subid = "00000000-0000-0000-0000-000000000000"
__subid_query = parse("$.subscriptionId")
__diag_id = "f844ec47-a9db-4511-8281-8b63f4eaf94e"
__diagid_query = parse("$.resourceContainers.account.id")
__remoteurl_query = parse("$.resource.repository.remoteUrl")
__repo_project_key_query = parse("$.resource.repository.project.name")
__repo_slug_query = parse("$.resource.repository.name")
Expand Down Expand Up @@ -39,13 +39,16 @@ class AzureDevOpsEnterpriseOrchestrator(OrchestratorBase):
def log() -> logging.Logger:
return logging.getLogger("AzureDevOpsEnterpriseOrchestrator")

@property
def config_key(self):
return "adoe"

def __init__(self, headers, webhook_payload):
OrchestratorBase.__init__(self, headers, webhook_payload)

self.__json = json.loads(webhook_payload)

self.__isdiagnostic = AzureDevOpsEnterpriseOrchestrator.__diag_subid in [x.value for x in list(AzureDevOpsEnterpriseOrchestrator.__subid_query.find(self.__json))]
self.__isdiagnostic = AzureDevOpsEnterpriseOrchestrator.__diag_id in [x.value for x in list(AzureDevOpsEnterpriseOrchestrator.__diagid_query.find(self.__json))]
if self.__isdiagnostic:
return

Expand Down
4 changes: 4 additions & 0 deletions orchestration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def __init__(self, headers, webhook_payload):
self.__webhook_payload = webhook_payload
self.__headers = headers

@property
def config_key(self):
raise NotImplementedError("config_key")

@property
def _headers(self) -> dict:
return self.__headers
Expand Down
4 changes: 4 additions & 0 deletions orchestration/bbdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class BitBucketDataCenterOrchestrator(OrchestratorBase):
def log():
return logging.getLogger("BitBucketDataCenterOrchestrator")

@property
def config_key(self):
return "bbdc"

def __init__(self, headers : dict, webhook_payload : dict):
OrchestratorBase.__init__(self, headers, webhook_payload)

Expand Down

0 comments on commit 5875a49

Please sign in to comment.