dbt-platform-helper 12.3.0__py3-none-any.whl → 12.4.1__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.
- dbt_platform_helper/COMMANDS.md +6 -1
- dbt_platform_helper/commands/codebase.py +1 -1
- dbt_platform_helper/commands/conduit.py +2 -2
- dbt_platform_helper/commands/config.py +4 -4
- dbt_platform_helper/commands/copilot.py +13 -15
- dbt_platform_helper/commands/database.py +17 -4
- dbt_platform_helper/commands/environment.py +3 -2
- dbt_platform_helper/commands/pipeline.py +1 -29
- dbt_platform_helper/constants.py +3 -1
- dbt_platform_helper/domain/codebase.py +23 -5
- dbt_platform_helper/domain/conduit.py +0 -6
- dbt_platform_helper/domain/database_copy.py +14 -13
- dbt_platform_helper/domain/maintenance_page.py +9 -9
- dbt_platform_helper/platform_exception.py +5 -0
- dbt_platform_helper/providers/aws.py +32 -0
- dbt_platform_helper/providers/cache.py +83 -0
- dbt_platform_helper/providers/cloudformation.py +8 -1
- dbt_platform_helper/providers/copilot.py +2 -5
- dbt_platform_helper/providers/ecs.py +19 -4
- dbt_platform_helper/providers/load_balancers.py +11 -5
- dbt_platform_helper/providers/platform_config_schema.py +605 -0
- dbt_platform_helper/providers/secrets.py +51 -10
- dbt_platform_helper/providers/validation.py +19 -0
- dbt_platform_helper/utils/application.py +14 -2
- dbt_platform_helper/utils/arn_parser.py +1 -1
- dbt_platform_helper/utils/aws.py +22 -21
- dbt_platform_helper/utils/files.py +0 -70
- dbt_platform_helper/utils/git.py +2 -2
- dbt_platform_helper/utils/validation.py +3 -551
- dbt_platform_helper/utils/versioning.py +8 -8
- {dbt_platform_helper-12.3.0.dist-info → dbt_platform_helper-12.4.1.dist-info}/METADATA +1 -1
- {dbt_platform_helper-12.3.0.dist-info → dbt_platform_helper-12.4.1.dist-info}/RECORD +35 -35
- dbt_platform_helper/addons-template-map.yml +0 -29
- dbt_platform_helper/exceptions.py +0 -147
- dbt_platform_helper/templates/pipelines/environments/buildspec.yml +0 -80
- dbt_platform_helper/templates/pipelines/environments/manifest.yml +0 -48
- dbt_platform_helper/templates/pipelines/environments/overrides/cfn.patches.yml +0 -21
- {dbt_platform_helper-12.3.0.dist-info → dbt_platform_helper-12.4.1.dist-info}/LICENSE +0 -0
- {dbt_platform_helper-12.3.0.dist-info → dbt_platform_helper-12.4.1.dist-info}/WHEEL +0 -0
- {dbt_platform_helper-12.3.0.dist-info → dbt_platform_helper-12.4.1.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ValidationException(PlatformException):
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IncompatibleMajorVersionException(ValidationException):
|
|
9
|
+
def __init__(self, app_version: str, check_version: str):
|
|
10
|
+
super().__init__()
|
|
11
|
+
self.app_version = app_version
|
|
12
|
+
self.check_version = check_version
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class IncompatibleMinorVersionException(ValidationException):
|
|
16
|
+
def __init__(self, app_version: str, check_version: str):
|
|
17
|
+
super().__init__()
|
|
18
|
+
self.app_version = app_version
|
|
19
|
+
self.check_version = check_version
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import os
|
|
2
3
|
import re
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from typing import Dict
|
|
@@ -8,7 +9,7 @@ import yaml
|
|
|
8
9
|
from boto3 import Session
|
|
9
10
|
from yaml.parser import ParserError
|
|
10
11
|
|
|
11
|
-
from dbt_platform_helper.
|
|
12
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
12
13
|
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
13
14
|
from dbt_platform_helper.utils.aws import get_profile_name_from_account_id
|
|
14
15
|
from dbt_platform_helper.utils.aws import get_ssm_secrets
|
|
@@ -80,7 +81,7 @@ def load_application(app: str = None, default_session: Session = None) -> Applic
|
|
|
80
81
|
WithDecryption=False,
|
|
81
82
|
)
|
|
82
83
|
except ssm_client.exceptions.ParameterNotFound:
|
|
83
|
-
raise
|
|
84
|
+
raise ApplicationNotFoundException(app)
|
|
84
85
|
|
|
85
86
|
path = f"/copilot/applications/{application.name}/environments"
|
|
86
87
|
secrets = get_ssm_secrets(app, None, current_session, path)
|
|
@@ -135,3 +136,14 @@ def get_application_name():
|
|
|
135
136
|
abort_with_error("Cannot get application name. No copilot/.workspace file found")
|
|
136
137
|
|
|
137
138
|
return app_name
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class ApplicationException(PlatformException):
|
|
142
|
+
pass
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class ApplicationNotFoundException(ApplicationException):
|
|
146
|
+
def __init__(self, application_name: str):
|
|
147
|
+
super().__init__(
|
|
148
|
+
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."""
|
|
149
|
+
)
|
dbt_platform_helper/utils/aws.py
CHANGED
|
@@ -13,14 +13,13 @@ import click
|
|
|
13
13
|
import yaml
|
|
14
14
|
from boto3 import Session
|
|
15
15
|
|
|
16
|
-
from dbt_platform_helper.
|
|
17
|
-
from dbt_platform_helper.
|
|
18
|
-
from dbt_platform_helper.
|
|
19
|
-
from dbt_platform_helper.
|
|
20
|
-
from dbt_platform_helper.
|
|
21
|
-
from dbt_platform_helper.
|
|
22
|
-
from dbt_platform_helper.
|
|
23
|
-
from dbt_platform_helper.utils.files import write_to_cache
|
|
16
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
17
|
+
from dbt_platform_helper.providers.aws import AWSException
|
|
18
|
+
from dbt_platform_helper.providers.aws import CopilotCodebaseNotFoundException
|
|
19
|
+
from dbt_platform_helper.providers.aws import ImageNotFoundException
|
|
20
|
+
from dbt_platform_helper.providers.aws import LogGroupNotFoundException
|
|
21
|
+
from dbt_platform_helper.providers.cache import CacheProvider
|
|
22
|
+
from dbt_platform_helper.providers.validation import ValidationException
|
|
24
23
|
|
|
25
24
|
SSM_BASE_PATH = "/copilot/{app}/{env}/secrets/"
|
|
26
25
|
SSM_PATH = "/copilot/{app}/{env}/secrets/{name}"
|
|
@@ -95,7 +94,7 @@ def _log_account_info(account_name: list, account_id: str) -> None:
|
|
|
95
94
|
)
|
|
96
95
|
|
|
97
96
|
|
|
98
|
-
class
|
|
97
|
+
class NoProfileForAccountIdException(PlatformException):
|
|
99
98
|
def __init__(self, account_id):
|
|
100
99
|
super().__init__(f"No profile found for account {account_id}")
|
|
101
100
|
|
|
@@ -110,7 +109,7 @@ def get_profile_name_from_account_id(account_id: str):
|
|
|
110
109
|
if account_id == found_account_id:
|
|
111
110
|
return section.removeprefix("profile ")
|
|
112
111
|
|
|
113
|
-
raise
|
|
112
|
+
raise NoProfileForAccountIdException(account_id)
|
|
114
113
|
|
|
115
114
|
|
|
116
115
|
def get_ssm_secret_names(app, env):
|
|
@@ -361,9 +360,9 @@ def get_postgres_connection_data_updated_with_master_secret(session, parameter_n
|
|
|
361
360
|
|
|
362
361
|
def get_supported_redis_versions():
|
|
363
362
|
|
|
364
|
-
|
|
363
|
+
cache_provider = CacheProvider()
|
|
365
364
|
|
|
366
|
-
|
|
365
|
+
if cache_provider.cache_refresh_required("redis"):
|
|
367
366
|
|
|
368
367
|
session = get_aws_session_or_abort()
|
|
369
368
|
elasticache_client = session.client("elasticache")
|
|
@@ -377,19 +376,19 @@ def get_supported_redis_versions():
|
|
|
377
376
|
for version in supported_versions_response["CacheEngineVersions"]
|
|
378
377
|
]
|
|
379
378
|
|
|
380
|
-
|
|
379
|
+
cache_provider.update_cache("redis", supported_versions)
|
|
381
380
|
|
|
382
381
|
return supported_versions
|
|
383
382
|
|
|
384
383
|
else:
|
|
385
|
-
return read_supported_versions_from_cache("redis")
|
|
384
|
+
return cache_provider.read_supported_versions_from_cache("redis")
|
|
386
385
|
|
|
387
386
|
|
|
388
387
|
def get_supported_opensearch_versions():
|
|
389
388
|
|
|
390
|
-
|
|
389
|
+
cache_provider = CacheProvider()
|
|
391
390
|
|
|
392
|
-
|
|
391
|
+
if cache_provider.cache_refresh_required("opensearch"):
|
|
393
392
|
|
|
394
393
|
session = get_aws_session_or_abort()
|
|
395
394
|
opensearch_client = session.client("opensearch")
|
|
@@ -404,12 +403,12 @@ def get_supported_opensearch_versions():
|
|
|
404
403
|
version.removeprefix("OpenSearch_") for version in opensearch_versions
|
|
405
404
|
]
|
|
406
405
|
|
|
407
|
-
|
|
406
|
+
cache_provider.update_cache("opensearch", supported_versions)
|
|
408
407
|
|
|
409
408
|
return supported_versions
|
|
410
409
|
|
|
411
410
|
else:
|
|
412
|
-
return read_supported_versions_from_cache("opensearch")
|
|
411
|
+
return cache_provider.read_supported_versions_from_cache("opensearch")
|
|
413
412
|
|
|
414
413
|
|
|
415
414
|
def get_connection_string(
|
|
@@ -488,8 +487,10 @@ def start_build_extraction(codebuild_client, build_options):
|
|
|
488
487
|
return response["build"]["arn"]
|
|
489
488
|
|
|
490
489
|
|
|
490
|
+
# Todo: This should probably be in the AWS Copilot provider
|
|
491
491
|
def check_codebase_exists(session: Session, application, codebase: str):
|
|
492
492
|
try:
|
|
493
|
+
# Todo: Can this leverage dbt_platform_helper.providers.secrets.Secrets.get_connection_secret_arn?
|
|
493
494
|
ssm_client = session.client("ssm")
|
|
494
495
|
json.loads(
|
|
495
496
|
ssm_client.get_parameter(
|
|
@@ -502,7 +503,7 @@ def check_codebase_exists(session: Session, application, codebase: str):
|
|
|
502
503
|
ssm_client.exceptions.ParameterNotFound,
|
|
503
504
|
json.JSONDecodeError,
|
|
504
505
|
):
|
|
505
|
-
raise
|
|
506
|
+
raise CopilotCodebaseNotFoundException(codebase)
|
|
506
507
|
|
|
507
508
|
|
|
508
509
|
def check_image_exists(session, application, codebase, commit):
|
|
@@ -516,7 +517,7 @@ def check_image_exists(session, application, codebase, commit):
|
|
|
516
517
|
ecr_client.exceptions.RepositoryNotFoundException,
|
|
517
518
|
ecr_client.exceptions.ImageNotFoundException,
|
|
518
519
|
):
|
|
519
|
-
raise
|
|
520
|
+
raise ImageNotFoundException(commit)
|
|
520
521
|
|
|
521
522
|
|
|
522
523
|
def get_build_url_from_arn(build_arn: str) -> str:
|
|
@@ -577,4 +578,4 @@ def wait_for_log_group_to_exist(log_client, log_group_name, attempts=30):
|
|
|
577
578
|
time.sleep(1)
|
|
578
579
|
|
|
579
580
|
if not log_group_exists:
|
|
580
|
-
raise
|
|
581
|
+
raise LogGroupNotFoundException(log_group_name)
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import os
|
|
2
1
|
from copy import deepcopy
|
|
3
|
-
from datetime import datetime
|
|
4
2
|
from os import makedirs
|
|
5
3
|
from pathlib import Path
|
|
6
4
|
|
|
@@ -9,8 +7,6 @@ import yaml
|
|
|
9
7
|
from jinja2 import Environment
|
|
10
8
|
from jinja2 import FileSystemLoader
|
|
11
9
|
|
|
12
|
-
from dbt_platform_helper.constants import PLATFORM_HELPER_CACHE_FILE
|
|
13
|
-
|
|
14
10
|
|
|
15
11
|
def to_yaml(value):
|
|
16
12
|
return yaml.dump(value, sort_keys=False)
|
|
@@ -106,69 +102,3 @@ def apply_environment_defaults(config):
|
|
|
106
102
|
enriched_config["environments"] = defaulted_envs
|
|
107
103
|
|
|
108
104
|
return enriched_config
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def read_supported_versions_from_cache(resource_name):
|
|
112
|
-
|
|
113
|
-
platform_helper_config = read_file_as_yaml(PLATFORM_HELPER_CACHE_FILE)
|
|
114
|
-
|
|
115
|
-
return platform_helper_config.get(resource_name).get("versions")
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def write_to_cache(resource_name, supported_versions):
|
|
119
|
-
|
|
120
|
-
platform_helper_config = {}
|
|
121
|
-
|
|
122
|
-
if os.path.exists(PLATFORM_HELPER_CACHE_FILE):
|
|
123
|
-
platform_helper_config = read_file_as_yaml(PLATFORM_HELPER_CACHE_FILE)
|
|
124
|
-
|
|
125
|
-
cache_dict = {
|
|
126
|
-
resource_name: {
|
|
127
|
-
"versions": supported_versions,
|
|
128
|
-
"date-retrieved": datetime.now().strftime("%d-%m-%y %H:%M:%S"),
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
platform_helper_config.update(cache_dict)
|
|
133
|
-
|
|
134
|
-
with open(PLATFORM_HELPER_CACHE_FILE, "w") as file:
|
|
135
|
-
file.write("# [!] This file is autogenerated via the platform-helper. Do not edit.\n")
|
|
136
|
-
yaml.dump(platform_helper_config, file)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def cache_refresh_required(resource_name) -> bool:
|
|
140
|
-
"""
|
|
141
|
-
Checks if the platform-helper should reach out to AWS to 'refresh' its
|
|
142
|
-
cached values.
|
|
143
|
-
|
|
144
|
-
An API call is needed if any of the following conditions are met:
|
|
145
|
-
1. No cache file (.platform-helper-config.yml) exists.
|
|
146
|
-
2. The resource name (e.g. redis, opensearch) does not exist within the cache file.
|
|
147
|
-
3. The date-retrieved value of the cached data is > than a time interval. In this case 1 day.
|
|
148
|
-
"""
|
|
149
|
-
|
|
150
|
-
if not os.path.exists(PLATFORM_HELPER_CACHE_FILE):
|
|
151
|
-
return True
|
|
152
|
-
|
|
153
|
-
platform_helper_config = read_file_as_yaml(PLATFORM_HELPER_CACHE_FILE)
|
|
154
|
-
|
|
155
|
-
if platform_helper_config.get(resource_name):
|
|
156
|
-
return check_if_cached_datetime_is_greater_than_interval(
|
|
157
|
-
platform_helper_config[resource_name].get("date-retrieved"), 1
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
return True
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def check_if_cached_datetime_is_greater_than_interval(date_retrieved, interval_in_days):
|
|
164
|
-
|
|
165
|
-
current_datetime = datetime.now()
|
|
166
|
-
cached_datetime = datetime.strptime(date_retrieved, "%d-%m-%y %H:%M:%S")
|
|
167
|
-
delta = current_datetime - cached_datetime
|
|
168
|
-
|
|
169
|
-
return delta.days > interval_in_days
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def read_file_as_yaml(file_name):
|
|
173
|
-
|
|
174
|
-
return yaml.safe_load(Path(file_name).read_text())
|
dbt_platform_helper/utils/git.py
CHANGED
|
@@ -2,7 +2,7 @@ import re
|
|
|
2
2
|
import subprocess
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class CommitNotFoundException(Exception):
|
|
6
6
|
pass
|
|
7
7
|
|
|
8
8
|
|
|
@@ -26,4 +26,4 @@ def check_if_commit_exists(commit):
|
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
if branches_containing_commit.stderr:
|
|
29
|
-
raise
|
|
29
|
+
raise CommitNotFoundException()
|