Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LITE-30645] - HUB CD mapping added #37

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cloudblueconnect/connect-extension-runner:29.4
FROM cloudblueconnect/connect-extension-runner:31.0

COPY pyproject.toml /install_temp/.
COPY poetry.* /install_temp/.
Expand Down
5 changes: 5 additions & 0 deletions connect_ext_datalake/apis/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
get_all_settings,
get_settings,
update_settings,
validate_hub_cd,
)


Expand Down Expand Up @@ -51,6 +52,8 @@ def validate_settings(
pubsub_client = GooglePubsubClient(settings)
pubsub_client.validate()

validate_hub_cd(settings.hub.hub_cd, hub_id)

return settings
except Exception as e:
return self.get_error_response(e)
Expand All @@ -69,6 +72,8 @@ def save_settings(
logger: LoggerAdapter = Depends(get_logger),
):
try:
validate_hub_cd(setting.hub_cd, hub_id)

pubsub_client = GooglePubsubClient(setting)
pubsub_client.validate()

Expand Down
2 changes: 2 additions & 0 deletions connect_ext_datalake/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class Hub(BaseModel):
id: str
name: str
icon: str | None = None
hub_cd: str | None = None


class SettingInput(BaseModel):
account_info: dict
product_topic: str
hub_cd: str | None = None


class Setting(SettingInput):
Expand Down
12 changes: 4 additions & 8 deletions connect_ext_datalake/services/events/fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from connect_ext_datalake.services.client import GooglePubsubClient
from connect_ext_datalake.services.publish import publish_ff_request
from connect_ext_datalake.services.settings import get_settings
from connect_ext_datalake.services.settings import get_settings, validate_hub_cd


class FulfillmentEventsMixin:
Expand All @@ -15,12 +15,14 @@ def __process_ff_request_event(self, ff_request):
if hub_id:
setting = get_settings(self.installation, hub_id)
if setting:
validate_hub_cd(setting.hub.hub_cd, hub_id)
try:
client = GooglePubsubClient(setting)
publish_ff_request(
client,
ff_request,
self.logger,
setting.hub.hub_cd,
)
except Exception as e:
self.logger.exception(
Expand Down Expand Up @@ -48,7 +50,6 @@ def __process_ff_request_event(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_suspend_request_processing(self, ff_request):
Expand All @@ -64,7 +65,6 @@ def handle_asset_suspend_request_processing(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_adjustment_request_processing(self, ff_request):
Expand All @@ -79,7 +79,6 @@ def handle_asset_adjustment_request_processing(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_cancel_request_processing(self, ff_request):
Expand All @@ -106,7 +105,6 @@ def handle_tier_account_update_request_processing(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_purchase_request_processing(self, ff_request):
Expand All @@ -122,7 +120,6 @@ def handle_asset_purchase_request_processing(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_change_request_processing(self, ff_request):
Expand All @@ -137,7 +134,6 @@ def handle_asset_change_request_processing(self, ff_request):
'scheduled',
'revoking',
'revoked',
'tiers_setup',
],
)
def handle_asset_resume_request_processing(self, ff_request):
Expand All @@ -148,7 +144,7 @@ def handle_asset_resume_request_processing(self, ff_request):
[
{
'name': 'FF_REQUEST_PAGE_SIZE',
'initial_value': 100,
'initial_value': '100',
},
],
)
Expand Down
4 changes: 3 additions & 1 deletion connect_ext_datalake/services/events/tier_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from connect_ext_datalake.services.client import GooglePubsubClient
from connect_ext_datalake.services.publish import publish_tc, publish_tc_from_tcr, publish_tcr
from connect_ext_datalake.services.settings import get_settings
from connect_ext_datalake.services.settings import get_settings, validate_hub_cd


class TierConfigEventsMixin:
Expand All @@ -16,6 +16,7 @@ def __process_tcr_event(self, tcr):
hub_id = tcr['configuration']['connection']['hub']['id']
setting = get_settings(self.installation, hub_id)
if setting:
validate_hub_cd(setting.hub.hub_cd, hub_id)
client = GooglePubsubClient(setting)
publish_tc_from_tcr(
self.installation_client,
Expand All @@ -27,6 +28,7 @@ def __process_tcr_event(self, tcr):
client,
tcr,
self.logger,
setting.hub.hub_cd,
)
else:
self.logger.info(
Expand Down
6 changes: 4 additions & 2 deletions connect_ext_datalake/services/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def prepare_tc_data(client: ConnectClient, tc: dict):
}


def prepare_tcr_data(tcr: dict):
def prepare_tcr_data(tcr: dict, hub_cd):
tcr["activation_link"] = tcr.get('activation', {}).get('link', None)
tcr["name"] = f"Tier Configuration Request for {tcr['configuration']['account']['id']}."
tcr['tier_account_id'] = tcr['configuration']['account']['id']
Expand All @@ -295,6 +295,7 @@ def prepare_tcr_data(tcr: dict):
tcr["published_at"] = datetime.now(tz=timezone(timedelta(hours=0))).isoformat(
timespec='seconds'
)
tcr["hub_cd"] = hub_cd
sanitize_tcr(tcr)

return {
Expand All @@ -304,7 +305,7 @@ def prepare_tcr_data(tcr: dict):
}


def prepare_ff_request_data(ff_request: dict):
def prepare_ff_request_data(ff_request: dict, hub_cd):
ff_request["name"] = f"Fulfillment request for asset {ff_request['asset']['id']}."
ff_request["asset_id"] = ff_request['asset']['id']
ff_request['product_id'] = ff_request['asset']['product']['id']
Expand All @@ -314,6 +315,7 @@ def prepare_ff_request_data(ff_request: dict):
ff_request["published_at"] = datetime.now(tz=timezone(timedelta(hours=0))).isoformat(
timespec='seconds'
)
ff_request["hub_cd"] = hub_cd
sanitize_ff_request(ff_request)

return {
Expand Down
6 changes: 4 additions & 2 deletions connect_ext_datalake/services/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def publish_tcr(
pubsub_client: GooglePubsubClient,
tcr,
logger,
hub_cd,
):
payload = prepare_tcr_data(tcr)
payload = prepare_tcr_data(tcr, hub_cd)
logger.info(f"Start publishing Tier Config Request {tcr['id']}. Payload: {payload}")
pubsub_client.publish(payload)
logger.info(f"Publish of Tier Config Request {tcr['id']}" f' is successful.')
Expand All @@ -58,8 +59,9 @@ def publish_ff_request(
pubsub_client: GooglePubsubClient,
ff_request,
logger,
hub_cd,
):
payload = prepare_ff_request_data(ff_request)
payload = prepare_ff_request_data(ff_request, hub_cd)
logger.info(f"Start publishing Fulfillment Request {ff_request['id']}. Payload: {payload}")
pubsub_client.publish(payload)
logger.info(f"Publish of Fulfillment Request {ff_request['id']}" f' is successful.')
Expand Down
19 changes: 15 additions & 4 deletions connect_ext_datalake/services/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from connect_ext_datalake.schemas import Hub, Setting, SettingInput


HUB_CD_LIST = ["NA", "EU", "OC", "SG"]


def get_all_settings(installation: dict):
settings = []

Expand Down Expand Up @@ -51,10 +54,7 @@ def update_settings(

existing_setting['account_info'] = setting.account_info
existing_setting['product_topic'] = setting.product_topic
existing_setting['hub'] = {
'id': hub['id'],
'name': hub['name'],
}
existing_setting['hub'] = {'id': hub['id'], 'name': hub['name'], 'hub_cd': setting.hub_cd}

client('devops').installations[installation['id']].update(
payload={
Expand Down Expand Up @@ -168,3 +168,14 @@ def creating_settings_map_from_product(
installation,
client,
)


def validate_hub_cd(hub_cd=None, hub_id=None):
if not hub_cd:
raise Exception(f"Hub_cd is not set for {hub_id}")
else:
if hub_cd not in HUB_CD_LIST:
raise Exception(
f"Value of hub_cd '{hub_cd}' not in the list of available values: "
+ ", ".join(HUB_CD_LIST)
)
Loading
Loading