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

feat: Updated tenant-config API #52

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
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
52 changes: 46 additions & 6 deletions resources/functions/tenant-config/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
tenant_details_table_handler = dynamodb.Table(tenant_details_table)


def _get_tenant_config(name):
def _get_tenant_config_by_name(name):
response = tenant_details_table_handler.query(
IndexName=tenant_config_index_name,
KeyConditionExpression=Key(tenant_name_column).eq(name),
Expand All @@ -41,10 +41,23 @@ def _get_tenant_config(name):
tenant_config = response["Items"][0]
return tenant_config.get(tenant_config_column, None)

def _get_tenant_config_by_id(id):
logger.info(f"id: {id}")
response = tenant_details_table_handler.get_item(
Key={
'tenantId': id
},
)
if "Item" not in response or len(response["Item"]) < 1:
return None

tenant_config = response["Item"]
return tenant_config.get(tenant_config_column, None)


def _get_tenant_config_for_tenant(name):
def _get_tenant_config_for_tenant_name(name):
try:
tenant_config = _get_tenant_config(name)
tenant_config = _get_tenant_config_by_name(name)
logger.info(f"tenant_config: {tenant_config}")
if tenant_config is None:
logger.error(f"No tenant details found for {name}")
Expand All @@ -57,6 +70,21 @@ def _get_tenant_config_for_tenant(name):
logger.error(error)
raise InternalServerError("Unknown error during processing!")

def _get_tenant_config_for_tenant_id(id):
try:
tenant_config = _get_tenant_config_by_id(id)
logger.info(f"tenant_config: {tenant_config}")
if tenant_config is None:
logger.error(f"No tenant details found for {id}")
raise NotFoundError(f"No tenant details found for {id}")
logger.info(
f"Tenant config found for {id} - {tenant_config}")

return tenant_config, HTTPStatus.OK.value
except botocore.exceptions.ClientError as error:
logger.error(error)
raise InternalServerError("Unknown error during processing!")


@app.get("/tenant-config/<tenant_name>")
@tracer.capture_method
Expand All @@ -66,12 +94,24 @@ def get_tenant_config_via_req_param(tenant_name):
logger.error(f"Tenant name not found in path!")
raise BadRequestError(f"Tenant name not found in path!")

return _get_tenant_config_for_tenant(tenant_name)
return _get_tenant_config_for_tenant_name(tenant_name)


@app.get("/tenant-config")
@tracer.capture_method
def get_tenant_config_via_header():
def get_tenant_config_via_param_or_header():
tenant_id: str = app.current_event.get_query_string_value(name="tenantId", default_value="")
tenant_name: str = ''
logger.info(f"tenant_id: {tenant_id}")
if tenant_id is None:
logger.info(f"No tenantId query parameter found. Looking for tenantName.")
else:
return _get_tenant_config_for_tenant_id(tenant_id)

tenant_name = app.current_event.get_query_string_value(name="tenantName", default_value="")
if tenant_name is None:
suhussai marked this conversation as resolved.
Show resolved Hide resolved
logger.info(f"No tenantName query parameter found. Looking at headers.")

origin_header = app.current_event.get_header_value(name="Origin")
logger.info(f"origin_header: {origin_header}")
if origin_header is None:
Expand All @@ -86,7 +126,7 @@ def get_tenant_config_via_header():
logger.error(f"Unable to parse tenant name!")
raise BadRequestError(f"Unable to parse tenant name!")

return _get_tenant_config_for_tenant(tenant_name)
return _get_tenant_config_for_tenant_name(tenant_name)


@logger.inject_lambda_context(
Expand Down
Loading