dbt-platform-helper 15.4.2__py3-none-any.whl → 15.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbt-platform-helper might be problematic. Click here for more details.

@@ -27,7 +27,7 @@ def conduit(addon_name: str, app: str, env: str, access: str):
27
27
  """Opens a shell for a given addon_name create a conduit connection to
28
28
  interact with postgres, opensearch or redis."""
29
29
  PlatformHelperVersioning().check_if_needs_update()
30
- application = load_application(app)
30
+ application = load_application(app=app, env=env)
31
31
 
32
32
  try:
33
33
  secrets_provider: Secrets = Secrets(
@@ -68,7 +68,7 @@ class DatabaseCopy:
68
68
  environment = environments.get(env)
69
69
  if not environment:
70
70
  self.io.abort_with_error(
71
- f"No such environment '{env}'. Available environments are: {', '.join(environments.keys())}"
71
+ f"Environment '{env}' cannot be found in your account configuration in parameter store. Available environments are: {', '.join(environments.keys())}. Please check that the Terraform infrastructure for your environment is up to date."
72
72
  )
73
73
 
74
74
  env_session = environment.session
@@ -195,6 +195,12 @@ class PlatformConfigSchema:
195
195
  # TODO: DBTP-1943: requires_approval is no longer relevant since we don't have AWS Copilot manage environment pipelines
196
196
  Optional("requires_approval"): bool,
197
197
  Optional("vpc"): str,
198
+ Optional("service-deployment-mode"): Or(
199
+ "copilot",
200
+ "dual-deploy-copilot-traffic",
201
+ "dual-deploy-platform-traffic",
202
+ "platform",
203
+ ),
198
204
  },
199
205
  )
200
206
  }
@@ -78,11 +78,42 @@ class VpcProvider:
78
78
 
79
79
  def _get_security_groups(self, app: str, env: str, vpc_id: str) -> list:
80
80
  vpc_filter = {"Name": "vpc-id", "Values": [vpc_id]}
81
- # TODO Handle terraformed environment SG https://uktrade.atlassian.net/browse/DBTP-2074
82
- tag_filter = {"Name": f"tag:Name", "Values": [f"copilot-{app}-{env}-env"]}
83
- response = self.ec2_client.describe_security_groups(Filters=[vpc_filter, tag_filter])
84
-
85
- return [sg.get("GroupId") for sg in response.get("SecurityGroups")]
81
+ platform_sg_name = f"platform-{app}-{env}-env-sg"
82
+ copilot_sg_name = f"copilot-{app}-{env}-env"
83
+ tag_filter = {"Name": f"tag:Name", "Values": [copilot_sg_name, platform_sg_name]}
84
+
85
+ filtered_security_groups = self.ec2_client.describe_security_groups(
86
+ Filters=[vpc_filter, tag_filter]
87
+ )
88
+
89
+ platform_security_groups = self._get_matching_security_groups(
90
+ filtered_security_groups, platform_sg_name
91
+ )
92
+
93
+ if platform_security_groups:
94
+ print(
95
+ f"using {platform_security_groups}"
96
+ ) # TODO remove this once decopilotiing has been completed
97
+ return platform_security_groups
98
+
99
+ copilot_security_groups = self._get_matching_security_groups(
100
+ filtered_security_groups, copilot_sg_name
101
+ )
102
+
103
+ print(
104
+ f"using {copilot_security_groups}"
105
+ ) # TODO remove this once decopilotiing has been completed
106
+ return copilot_security_groups
107
+
108
+ def _get_matching_security_groups(
109
+ self, filtered_security_groups: list[dict], security_group_name: str
110
+ ):
111
+ matching_sec_groups = filtered_security_groups.get("SecurityGroups")
112
+ return [
113
+ sg.get("GroupId")
114
+ for sg in matching_sec_groups
115
+ if {"Key": "Name", "Value": security_group_name} in sg.get("Tags", [])
116
+ ]
86
117
 
87
118
  def get_vpc(self, app: str, env: str, vpc_name: str) -> Vpc:
88
119
 
@@ -59,23 +59,11 @@ class Application:
59
59
  return str(self) == str(other)
60
60
 
61
61
 
62
- def load_application(app=None, default_session=None) -> Application:
62
+ def load_application(app=None, default_session=None, env=None) -> Application:
63
63
  application = Application(app if app else get_application_name())
64
64
  current_session = default_session if default_session else get_aws_session_or_abort()
65
65
 
66
66
  ssm_client = current_session.client("ssm")
67
-
68
- try:
69
- ssm_client.get_parameter(
70
- Name=f"/copilot/applications/{application.name}",
71
- WithDecryption=False,
72
- )
73
- except ssm_client.exceptions.ParameterNotFound:
74
- raise ApplicationNotFoundException(application.name)
75
-
76
- path = f"/copilot/applications/{application.name}/environments"
77
- secrets = get_ssm_secrets(app, None, current_session, path)
78
-
79
67
  sts_client = current_session.client("sts")
80
68
  account_id = sts_client.get_caller_identity()["Account"]
81
69
  sessions = {account_id: current_session}
@@ -89,16 +77,58 @@ def load_application(app=None, default_session=None) -> Application:
89
77
  - /copilot/applications/test/environments/my_env will match.
90
78
  - /copilot/applications/test/environments/my_env/addons will not match.
91
79
  """
92
- environment_key_regex = r"^/copilot/applications/{}/environments/[^/]*$".format(
80
+ environment_key_regex = r"^/(copilot|platform)/applications/{}/environments/[^/]*$".format(
93
81
  application.name
94
82
  )
95
83
  return bool(re.match(environment_key_regex, name))
96
84
 
97
- environments = {
85
+ environments_data = []
86
+
87
+ # Try to load the new /platform SSM parameter if present
88
+ platform_env_path = f"/platform/applications/{application.name}/environments"
89
+ secrets = get_ssm_secrets(app, None, current_session, platform_env_path)
90
+
91
+ if secrets:
92
+ for name, value in secrets:
93
+ try:
94
+ data = json.loads(value)
95
+ except json.JSONDecodeError:
96
+ continue
97
+
98
+ # New /platform SSM parameter contains data about all environments
99
+ if "allEnvironments" in data:
100
+ environments_data = data["allEnvironments"]
101
+ break # Only need one
102
+ else:
103
+ try:
104
+ # Check that the Copilot application exists
105
+ ssm_client.get_parameter(
106
+ Name=f"/copilot/applications/{application.name}",
107
+ WithDecryption=False,
108
+ )
109
+ secrets = get_ssm_secrets(
110
+ app, None, current_session, f"/copilot/applications/{application.name}/environments"
111
+ )
112
+
113
+ for name, value in secrets:
114
+ try:
115
+ data = json.loads(value)
116
+ except json.JSONDecodeError:
117
+ continue
118
+
119
+ if is_environment_key(name):
120
+ # Legacy /copilot SSM parameter. An individual SSM param is present per environment - looping through all of them is needed to extract necessary data about each env.
121
+ environments_data.append(data)
122
+
123
+ except ssm_client.exceptions.ParameterNotFound:
124
+ raise ApplicationNotFoundException(
125
+ application_name=application.name, environment_name=env
126
+ )
127
+
128
+ application.environments = {
98
129
  env["name"]: Environment(env["name"], env["accountID"], sessions)
99
- for env in [json.loads(s[1]) for s in secrets if is_environment_key(s[0])]
130
+ for env in environments_data
100
131
  }
101
- application.environments = environments
102
132
 
103
133
  response = ssm_client.get_parameters_by_path(
104
134
  Path=f"/copilot/applications/{application.name}/components",
@@ -142,9 +172,12 @@ class ApplicationException(PlatformException):
142
172
 
143
173
 
144
174
  class ApplicationNotFoundException(ApplicationException):
145
- def __init__(self, application_name: str):
175
+ def __init__(self, application_name: str, environment_name: str):
146
176
  super().__init__(
147
- f"""The account "{os.environ.get("AWS_PROFILE")}" does not contain the application "{application_name}"; ensure you have set the environment variable "AWS_PROFILE" correctly."""
177
+ f"""The account "{os.environ.get("AWS_PROFILE")}" does not contain the application "{application_name}".
178
+ Please ensure that the environment variable "AWS_PROFILE" is set correctly. If the issue persists, verify that one of the following AWS SSM parameters exists:
179
+ - /platform/applications/{application_name}/environments/{environment_name}
180
+ - /copilot/applications/{application_name}"""
148
181
  )
149
182
 
150
183
 
@@ -158,7 +158,17 @@ def get_ssm_secrets(app, env, session=None, path=None):
158
158
  secrets = []
159
159
 
160
160
  while True:
161
- response = client.get_parameters_by_path(**params)
161
+ try:
162
+ response = client.get_parameters_by_path(**params)
163
+ except ClientError as e:
164
+ if e.response["Error"]["Code"] == "AccessDeniedException":
165
+ click.secho(
166
+ "Access denied on SSM, due to missing permissions. Please update your environment infrastructure.",
167
+ fg="magenta",
168
+ )
169
+ break
170
+ else:
171
+ raise e
162
172
 
163
173
  for secret in response["Parameters"]:
164
174
  secrets.append((secret["Name"], secret["Value"]))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dbt-platform-helper
3
- Version: 15.4.2
3
+ Version: 15.6.0
4
4
  Summary: Set of tools to help transfer applications/services from GOV.UK PaaS to DBT PaaS augmenting AWS Copilot.
5
5
  License: MIT
6
6
  Author: Department for Business and Trade Platform Team
@@ -4,7 +4,7 @@ dbt_platform_helper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
4
4
  dbt_platform_helper/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  dbt_platform_helper/commands/application.py,sha256=OUQsahXXHSEKxmXAmK8fSy_bTLNwM_TdLuv6CvffRPk,10126
6
6
  dbt_platform_helper/commands/codebase.py,sha256=oNlZcP2w3XE5YP-JVl0rdqoJuXUrfe1ELZ5xAdgPvBk,3166
7
- dbt_platform_helper/commands/conduit.py,sha256=v5geTJzRHkOnbFfOqmjO6b57HXhs4YxTo_zJgDEYB0A,2300
7
+ dbt_platform_helper/commands/conduit.py,sha256=GVDX2QjeGCxgN0otWOPivo0jyoE0CjnBz3VCDx9s-po,2313
8
8
  dbt_platform_helper/commands/config.py,sha256=4pgGgaH7Mp93UWdVoqZDc2eAmjsP7Yw1jjsviNWXsks,1442
9
9
  dbt_platform_helper/commands/copilot.py,sha256=L9UUuqD62q0aFrTTEUla3A1WJBz-vFBfVi6p455TTgQ,1458
10
10
  dbt_platform_helper/commands/database.py,sha256=2RJZEzaSqcNtDG1M2mZw-nB6agAd3GNAJsg2pjFF7vc,4407
@@ -22,14 +22,14 @@ dbt_platform_helper/domain/conduit.py,sha256=0aX5rhynkkJj8rJUwfyLENyCwlAI67_Vkky
22
22
  dbt_platform_helper/domain/config.py,sha256=Iyf-lV4YDD6BHH-RRaTvp-7qPS8BYeHM_SkSfeU7si4,13802
23
23
  dbt_platform_helper/domain/copilot.py,sha256=g8W2LaskyhOvtNoCoNbwucGTrfdAzj-AJ0J98tgLbhA,15138
24
24
  dbt_platform_helper/domain/copilot_environment.py,sha256=fL3XJCOfO0BJRCrCoBPFCcshrQoX1FeSYNTziOEaH4A,9093
25
- dbt_platform_helper/domain/database_copy.py,sha256=AedcBTfKDod0OlMqVP6zb9c_9VIc3vqro0oUUhh7nwc,9497
25
+ dbt_platform_helper/domain/database_copy.py,sha256=4A84xqj3c_VjYlXb81B8Kt8us8IcCQVVF6GyPAAmwyo,9638
26
26
  dbt_platform_helper/domain/maintenance_page.py,sha256=0_dgM5uZvjVNBKcqScspjutinMh-7Hdm7jBEgUPujrk,14529
27
27
  dbt_platform_helper/domain/notify.py,sha256=_BWj5znDWtrSdJ5xzDBgnao4ukliBA5wiUZGobIDyiI,1894
28
28
  dbt_platform_helper/domain/pipelines.py,sha256=rL_NArksFgmpsIUL3K_xVmTWt10tmlw5eCP140j96bc,7832
29
29
  dbt_platform_helper/domain/plans.py,sha256=X5-jKGiJDVWn0CRH1k5aV74fTH0E41HqFQcCo5kB4hI,1160
30
30
  dbt_platform_helper/domain/terraform_environment.py,sha256=g9PSuZeVXgboGNDXU7OGMiRATd67NU8S92HUGri1fbo,2471
31
31
  dbt_platform_helper/domain/versioning.py,sha256=pIL8VPAJHqX5kJBp3QIxII5vmUo4aIYW_U9u_KxUJd0,5494
32
- dbt_platform_helper/entities/platform_config_schema.py,sha256=yYbTYLnQkM04RoMyjI4-KoZyxfIVrNx1FDq9wmUiw_I,26665
32
+ dbt_platform_helper/entities/platform_config_schema.py,sha256=1T9tKqDV4nsyr-UYhqg6NqRBUF6xgF7SPpdomGGjtMo,26931
33
33
  dbt_platform_helper/entities/semantic_version.py,sha256=VgQ6V6OgSaleuVmMB8Kl_yLoakXl2auapJTDbK00mfc,2679
34
34
  dbt_platform_helper/jinja2_tags.py,sha256=hKG6RS3zlxJHQ-Op9r2U2-MhWp4s3lZir4Ihe24ApJ0,540
35
35
  dbt_platform_helper/platform_exception.py,sha256=HGfCYRD20REsynqMKmyZndTfdkMd5dLSIEB2qGGCeP8,244
@@ -62,7 +62,7 @@ dbt_platform_helper/providers/terraform_manifest.py,sha256=Qst0GwLyOgHgmli3gVciV
62
62
  dbt_platform_helper/providers/validation.py,sha256=i2g-Mrd4hy_fGIfGa6ZQy4vTJ40OM44Fe_XpEifGWxs,126
63
63
  dbt_platform_helper/providers/version.py,sha256=QNGrV5nyJi0JysXowYUU4OrXGDn27WmFezlV8benpdY,4251
64
64
  dbt_platform_helper/providers/version_status.py,sha256=qafnhZrEc9k1cvXJpvJhkGj6WtkzcsoQhqS_Y6JXy48,929
65
- dbt_platform_helper/providers/vpc.py,sha256=V8kXXzy-JuRpuzZhI9xyfcNky-eD42K0v_uM2WejLoo,3048
65
+ dbt_platform_helper/providers/vpc.py,sha256=KdgwyHv2RwNpq16Sa2FtWm7DMJlTNmsPbXkbMNMYiQo,4082
66
66
  dbt_platform_helper/providers/yaml_file.py,sha256=LZ8eCPDQRr1wlck13My5hQa0eE2OVhSomm-pOIuZ9h0,2881
67
67
  dbt_platform_helper/templates/.copilot/config.yml,sha256=J_bA9sCtBdCPBRImpCBRnYvhQd4vpLYIXIU-lq9vbkA,158
68
68
  dbt_platform_helper/templates/.copilot/image_build_run.sh,sha256=adYucYXEB-kAgZNjTQo0T6EIAY8sh_xCEvVhWKKQ8mw,164
@@ -90,9 +90,9 @@ dbt_platform_helper/templates/svc/maintenance_pages/migration.html,sha256=GiQsOi
90
90
  dbt_platform_helper/templates/svc/overrides/cfn.patches.yml,sha256=W7-d017akuUq9kda64DQxazavcRcCPDjaAik6t1EZqM,742
91
91
  dbt_platform_helper/utilities/decorators.py,sha256=rS6ohsuo0bc6fkZP98Qwaeh0c_v2MDqn9hCvqfoz2w8,3548
92
92
  dbt_platform_helper/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
- dbt_platform_helper/utils/application.py,sha256=d7Tg5odZMy9e3o4R0mmU19hrxJuIfS_ATDH4hY8zJvk,5480
93
+ dbt_platform_helper/utils/application.py,sha256=414czQmCUMDohoz38cY8FjoitJolCmRxCqc9TMJTsE4,6951
94
94
  dbt_platform_helper/utils/arn_parser.py,sha256=BaXzIxSOLdFmP_IfAxRq-0j-0Re1iCN7L4j2Zi5-CRQ,1304
95
- dbt_platform_helper/utils/aws.py,sha256=O3L5Lg2idq597WYNe0GQiW9gHfoeL5XiQbtJ1r_1K-o,12710
95
+ dbt_platform_helper/utils/aws.py,sha256=mnffVJzvXojfmYh1waeUWwHYo24jRu95rXg8LiuogtA,13096
96
96
  dbt_platform_helper/utils/click.py,sha256=Fx4y4bbve1zypvog_sgK7tJtCocmzheoEFLBRv1lfdM,2943
97
97
  dbt_platform_helper/utils/git.py,sha256=9jyLhv37KKE6r-_hb3zvjhTbluA81kdrOdNeG6MB-_M,384
98
98
  dbt_platform_helper/utils/messages.py,sha256=nWA7BWLb7ND0WH5TejDN4OQUJSKYBxU4tyCzteCrfT0,142
@@ -102,8 +102,8 @@ platform_helper.py,sha256=_YNNGtMkH5BcpC_mQQYJrmlf2mt7lkxTYeH7ZgflPoA,1925
102
102
  terraform/elasticache-redis/plans.yml,sha256=efJfkLuLC_5TwhLb9DalKHOuZFO79y6iei6Dg_tqKjI,1831
103
103
  terraform/opensearch/plans.yml,sha256=lQbUSNMGfvUeDMcGx8mSwzGQhMJU3EZ4J4tPzPKaq6c,1471
104
104
  terraform/postgres/plans.yml,sha256=plwCklW1VB_tNJFyUduRMZx9UANgiWH_7TGLWUaUEus,2553
105
- dbt_platform_helper-15.4.2.dist-info/LICENSE,sha256=dP79lN73--7LMApnankTGLqDbImXg8iYFqWgnExGkGk,1090
106
- dbt_platform_helper-15.4.2.dist-info/METADATA,sha256=MvtaYEGvyuYj4ZZ-SSK_a9nvEPmMnVS1Ank8efq65_A,3293
107
- dbt_platform_helper-15.4.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
108
- dbt_platform_helper-15.4.2.dist-info/entry_points.txt,sha256=QhbY8F434A-onsg0-FsdMd2U6HKh6Q7yCFFZrGUh5-M,67
109
- dbt_platform_helper-15.4.2.dist-info/RECORD,,
105
+ dbt_platform_helper-15.6.0.dist-info/LICENSE,sha256=dP79lN73--7LMApnankTGLqDbImXg8iYFqWgnExGkGk,1090
106
+ dbt_platform_helper-15.6.0.dist-info/METADATA,sha256=t3DF_0fn1sT4hseK6F1MZ4H-GaMClJKiU2RaS5ZK_Gc,3293
107
+ dbt_platform_helper-15.6.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
108
+ dbt_platform_helper-15.6.0.dist-info/entry_points.txt,sha256=QhbY8F434A-onsg0-FsdMd2U6HKh6Q7yCFFZrGUh5-M,67
109
+ dbt_platform_helper-15.6.0.dist-info/RECORD,,