Skip to content

Commit

Permalink
change service lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
nleach999 committed Jun 3, 2024
1 parent cc16661 commit db704a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 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
4 changes: 4 additions & 0 deletions orchestration/adoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class AzureDevOpsEnterpriseOrchestrator(OrchestratorBase):
def log() -> logging.Logger:
return logging.getLogger("AzureDevOpsEnterpriseOrchestrator")

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

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

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

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

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

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

Expand Down

0 comments on commit db704a6

Please sign in to comment.