From 9fbcacd1a99bded09022fbddf38cc2b6d35682b6 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Thu, 15 Jun 2023 15:12:32 +0100 Subject: [PATCH] Create Amplify domain if specified --- .pre-commit-config.yaml | 2 +- egress_backend/egress_backend_stack.py | 27 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 99e2329..f4a0c82 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: [ "--max-line-length=200", "--ignore=E203,W503", - "--max-cognitive-complexity=17", + "--max-cognitive-complexity=18", "--max-expression-complexity=9", ] additional_dependencies: [ diff --git a/egress_backend/egress_backend_stack.py b/egress_backend/egress_backend_stack.py index 179d2f2..fafeebf 100644 --- a/egress_backend/egress_backend_stack.py +++ b/egress_backend/egress_backend_stack.py @@ -41,7 +41,7 @@ ) -def from_bool_string(s, rtype): +def convert_bool(s, rtype): """ Returns: rtype=str: 'true' or 'false' @@ -49,11 +49,11 @@ def from_bool_string(s, rtype): """ if rtype not in (str, bool): raise ValueError(f"Invalid return type: {rtype}") - if s.lower() == "true": + if (isinstance(s, str) and s.lower() == "true") or s is True: if rtype == str: return "true" return True - if s.lower() == "false": + if (isinstance(s, str) and s.lower() == "false") or s is False: if rtype == str: return "false" return False @@ -137,7 +137,7 @@ def __init__( ) # Customised SWB with access points - use_s3_access_points = from_bool_string( + use_s3_access_points = convert_bool( self.node.try_get_context(env_id).get("use_s3_access_points"), bool ) @@ -524,6 +524,21 @@ def __init__( branch_name=amplify_branch_name, ) + if convert_bool(custom_domain_config.get("is_enabled"), bool): + amplify.CfnDomain( + self, + "EgressFrontendAppDomain", + app_id=amplify_app.attr_app_id, + domain_name=custom_domain_config.get("domain_name"), + sub_domain_settings=[ + amplify.CfnDomain.SubDomainSettingProperty( + prefix="", + branch_name=amplify_branch_name, + ) + ], + enable_auto_sub_domain=False, + ) + egress_app_url = ( f"https://{amplify_branch_name}.{amplify_app.attr_app_id}.amplifyapp.com" ) @@ -1242,7 +1257,7 @@ def __init__( logout_ur_ls.append( f"https://{custom_amplify_distribution.amplify_app_distribution.distribution_domain_name}" ) - if custom_domain_config.get("is_enabled"): + if convert_bool(custom_domain_config.get("is_enabled"), bool): callback_ur_ls.append(f"https://{custom_domain_config.get('domain_name')}") logout_ur_ls.append(f"https://{custom_domain_config.get('domain_name')}") @@ -1961,7 +1976,7 @@ def __init__( self, "EgressAppURL", value=f"https://{custom_domain_config.get('domain_name')}" - if custom_domain_config.get("is_enabled") + if convert_bool(custom_domain_config.get("is_enabled"), bool) else egress_app_url, description="The URL for the Egress App.", )