3
0

name_utils.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  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 core
  8. from .resource_name_sanitizer import sanitize_resource_name
  9. def format_aws_resource_name(feature_name: str, project_name: str, env: core.Environment, resource_type: str):
  10. return sanitize_resource_name(f'{project_name}-{feature_name}-{resource_type}-{env.region}', resource_type)
  11. def format_aws_resource_id(feature_name: str, project_name: str, env: core.Environment, resource_type: str):
  12. return f'{project_name}{feature_name}{resource_type}Id{env.region}'
  13. def format_aws_resource_sid(feature_name: str, project_name: str, resource_type: str):
  14. sid = f'{project_name}{feature_name}{resource_type}SId'
  15. # Strip out all chars not valid in a sid
  16. return re.sub(r'[^a-zA-Z0-9]', '', sid)
  17. def format_aws_resource_authenticated_id(feature_name: str, project_name: str, env: core.Environment,
  18. resource_type: str, authenticated: bool):
  19. authenticated_string = 'Authenticated' if authenticated else 'Unauthenticated'
  20. return f'{project_name}{feature_name}{resource_type}Id{authenticated_string}-{env.region}'
  21. def format_aws_resource_authenticated_name(feature_name: str, project_name: str, env: core.Environment,
  22. resource_type: str, authenticated: bool):
  23. authenticated_string = 'Authenticated' if authenticated else 'Unauthenticated'
  24. return sanitize_resource_name(
  25. f'{project_name}{feature_name}{resource_type}{authenticated_string}-{env.region}', resource_type)