Skip to content

Commit

Permalink
prep for rabbit config
Browse files Browse the repository at this point in the history
  • Loading branch information
nleach999 committed May 29, 2024
1 parent 3e7abd0 commit 99a4bd4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
28 changes: 25 additions & 3 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from password_strength import PasswordPolicy
from cxoneflow_logging import SecretRegistry

def get_config_path():
if "CONFIG_YAML_PATH" in os.environ.keys():
return os.environ['CONFIG_YAML_PATH']
else:
return "./config.yaml"

class ConfigurationException(Exception):

@staticmethod
Expand Down Expand Up @@ -48,12 +54,24 @@ class RouteNotFoundException(Exception):
pass

class CxOneFlowConfig:

__shared_secret_policy = PasswordPolicy.from_names(length=20, uppercase=3, numbers=3, special=2)

__cxone_service_tuple_index = 1
__scm_service_tuple_index = 2
__rabbit_service_tuple_index = 3

@staticmethod
def log():
return logging.getLogger("CxOneFlowConfig")

@staticmethod
def get_service_monikers():
return list(CxOneFlowConfig.__scm_config_tuples_by_service_moniker.keys())

@staticmethod
def retrieve_services_by_moniker(moniker):
service_tuple = CxOneFlowConfig.__scm_config_tuples_by_service_moniker[moniker]
return service_tuple[CxOneFlowConfig.__cxone_service_tuple_index], service_tuple[CxOneFlowConfig.__scm_service_tuple_index]

@staticmethod
def retrieve_services_by_route(clone_urls):
Expand All @@ -66,7 +84,7 @@ def retrieve_services_by_route(clone_urls):
for url in it_list:
for entry in CxOneFlowConfig.__ordered_scm_config_tuples:
if entry[0].match(url):
return entry[1], entry[2]
return entry[CxOneFlowConfig.__cxone_service_tuple_index], entry[CxOneFlowConfig.__scm_service_tuple_index]

CxOneFlowConfig.log().error(f"No route matched for {clone_urls}")
raise RouteNotFoundException(clone_urls)
Expand Down Expand Up @@ -198,6 +216,7 @@ def __cxone_client_factory(config_path, **kwargs):


__ordered_scm_config_tuples = []
__scm_config_tuples_by_service_moniker = {}

__minimum_api_auth_keys = ['token', 'password']
__basic_auth_keys = ['username', 'password']
Expand Down Expand Up @@ -297,7 +316,10 @@ 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))
scm_tuple = (repo_matcher, cxone_service, scm_service)

CxOneFlowConfig.__ordered_scm_config_tuples.append(scm_tuple)
CxOneFlowConfig.__scm_config_tuples_by_service_moniker[service_moniker] = scm_tuple


__cloner_factories = {
Expand Down
10 changes: 8 additions & 2 deletions rabbit_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import asyncio, aio_pika, logging
import cxoneflow_logging as cof_logging
from config import CxOneFlowConfig, ConfigurationException, get_config_path

cof_logging.bootstrap()

__log = logging.getLogger("RabbitSetup")



async def setup() -> None:
monikers = CxOneFlowConfig.get_service_monikers()

rmq = await aio_pika.connect_robust("amqp://localhost")

async with rmq.channel() as channel:
Expand All @@ -32,4 +34,8 @@ async def setup() -> None:


if __name__ == "__main__":
asyncio.run(setup())
try:
CxOneFlowConfig.bootstrap(get_config_path())
asyncio.run(setup())
except ConfigurationException as ce:
__log.exception(ce)
8 changes: 1 addition & 7 deletions wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask import Flask, request, Response
from orchestration import OrchestrationDispatch, BitBucketDataCenterOrchestrator, AzureDevOpsEnterpriseOrchestrator
import json, logging, asyncio, os
from config import CxOneFlowConfig, ConfigurationException
from config import CxOneFlowConfig, ConfigurationException, get_config_path
from time import perf_counter_ns
from task_management import TaskManager
import cxoneflow_logging as cof_logging
Expand All @@ -19,12 +19,6 @@

__log = logging.getLogger(__app_name__)

def get_config_path():
if "CONFIG_YAML_PATH" in os.environ.keys():
return os.environ['CONFIG_YAML_PATH']
else:
return "./config.yaml"

try:
CxOneFlowConfig.bootstrap(get_config_path())
except ConfigurationException as ce:
Expand Down

0 comments on commit 99a4bd4

Please sign in to comment.