3
0

name_utils.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import re
  7. from aws_cdk import (
  8. Environment
  9. )
  10. from .resource_name_sanitizer import sanitize_resource_name
  11. def format_aws_resource_name(feature_name: str, project_name: str, env: Environment, resource_type: str):
  12. return sanitize_resource_name(f'{project_name}-{feature_name}-{resource_type}-{env.region}', resource_type)
  13. def format_aws_resource_id(feature_name: str, project_name: str, env: Environment, resource_type: str):
  14. return f'{project_name}{feature_name}{resource_type}Id{env.region}'
  15. def format_aws_resource_sid(feature_name: str, project_name: str, resource_type: str):
  16. sid = f'{project_name}{feature_name}{resource_type}SId'
  17. # Strip out all chars not valid in a sid
  18. return re.sub(r'[^a-zA-Z0-9]', '', sid)
  19. def format_aws_resource_authenticated_id(feature_name: str, project_name: str, env: Environment,
  20. resource_type: str, authenticated: bool):
  21. authenticated_string = 'Authenticated' if authenticated else 'Unauthenticated'
  22. return f'{project_name}{feature_name}{resource_type}Id{authenticated_string}-{env.region}'
  23. def format_aws_resource_authenticated_name(feature_name: str, project_name: str, env: Environment,
  24. resource_type: str, authenticated: bool):
  25. authenticated_string = 'Authenticated' if authenticated else 'Unauthenticated'
  26. return sanitize_resource_name(
  27. f'{project_name}{feature_name}{resource_type}{authenticated_string}-{env.region}', resource_type)