dbt-platform-helper 13.2.0__py3-none-any.whl → 13.3.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.
- dbt_platform_helper/commands/codebase.py +10 -4
- dbt_platform_helper/commands/config.py +12 -314
- dbt_platform_helper/commands/copilot.py +10 -6
- dbt_platform_helper/commands/database.py +17 -9
- dbt_platform_helper/commands/environment.py +2 -3
- dbt_platform_helper/domain/codebase.py +7 -7
- dbt_platform_helper/domain/config.py +345 -0
- dbt_platform_helper/domain/copilot.py +155 -157
- dbt_platform_helper/domain/versioning.py +48 -7
- dbt_platform_helper/providers/aws/__init__.py +0 -0
- dbt_platform_helper/providers/aws/exceptions.py +10 -0
- dbt_platform_helper/providers/aws/sso_auth.py +61 -0
- dbt_platform_helper/providers/config.py +2 -1
- dbt_platform_helper/providers/config_validator.py +15 -13
- dbt_platform_helper/providers/io.py +2 -2
- dbt_platform_helper/providers/parameter_store.py +47 -0
- dbt_platform_helper/providers/platform_config_schema.py +17 -0
- dbt_platform_helper/providers/semantic_version.py +15 -88
- dbt_platform_helper/providers/terraform_manifest.py +1 -0
- dbt_platform_helper/providers/version.py +82 -24
- dbt_platform_helper/providers/version_status.py +80 -0
- dbt_platform_helper/utils/aws.py +0 -141
- dbt_platform_helper/utils/git.py +3 -1
- dbt_platform_helper/utils/tool_versioning.py +0 -84
- {dbt_platform_helper-13.2.0.dist-info → dbt_platform_helper-13.3.0.dist-info}/METADATA +2 -2
- {dbt_platform_helper-13.2.0.dist-info → dbt_platform_helper-13.3.0.dist-info}/RECORD +30 -30
- {dbt_platform_helper-13.2.0.dist-info → dbt_platform_helper-13.3.0.dist-info}/WHEEL +1 -1
- platform_helper.py +1 -1
- dbt_platform_helper/templates/svc/manifest-backend.yml +0 -69
- dbt_platform_helper/templates/svc/manifest-public.yml +0 -109
- dbt_platform_helper/utils/cloudfoundry.py +0 -14
- dbt_platform_helper/utils/files.py +0 -53
- dbt_platform_helper/utils/manifests.py +0 -18
- {dbt_platform_helper-13.2.0.dist-info → dbt_platform_helper-13.3.0.dist-info}/LICENSE +0 -0
- {dbt_platform_helper-13.2.0.dist-info → dbt_platform_helper-13.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -4,6 +4,8 @@ from dbt_platform_helper.domain.codebase import Codebase
|
|
|
4
4
|
from dbt_platform_helper.domain.versioning import PlatformHelperVersioning
|
|
5
5
|
from dbt_platform_helper.platform_exception import PlatformException
|
|
6
6
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
7
|
+
from dbt_platform_helper.providers.parameter_store import ParameterStore
|
|
8
|
+
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
7
9
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
8
10
|
|
|
9
11
|
|
|
@@ -17,7 +19,7 @@ def codebase():
|
|
|
17
19
|
def prepare():
|
|
18
20
|
"""Sets up an application codebase for use within a DBT platform project."""
|
|
19
21
|
try:
|
|
20
|
-
Codebase().prepare()
|
|
22
|
+
Codebase(ParameterStore(get_aws_session_or_abort().client("ssm"))).prepare()
|
|
21
23
|
except PlatformException as err:
|
|
22
24
|
ClickIOProvider().abort_with_error(str(err))
|
|
23
25
|
|
|
@@ -33,7 +35,7 @@ def prepare():
|
|
|
33
35
|
def list(app, with_images):
|
|
34
36
|
"""List available codebases for the application."""
|
|
35
37
|
try:
|
|
36
|
-
Codebase().list(app, with_images)
|
|
38
|
+
Codebase(ParameterStore(get_aws_session_or_abort().client("ssm"))).list(app, with_images)
|
|
37
39
|
except PlatformException as err:
|
|
38
40
|
ClickIOProvider().abort_with_error(str(err))
|
|
39
41
|
|
|
@@ -49,7 +51,9 @@ def list(app, with_images):
|
|
|
49
51
|
def build(app, codebase, commit):
|
|
50
52
|
"""Trigger a CodePipeline pipeline based build."""
|
|
51
53
|
try:
|
|
52
|
-
Codebase().build(
|
|
54
|
+
Codebase(ParameterStore(get_aws_session_or_abort().client("ssm"))).build(
|
|
55
|
+
app, codebase, commit
|
|
56
|
+
)
|
|
53
57
|
except PlatformException as err:
|
|
54
58
|
ClickIOProvider().abort_with_error(str(err))
|
|
55
59
|
|
|
@@ -65,6 +69,8 @@ def build(app, codebase, commit):
|
|
|
65
69
|
@click.option("--commit", help="GitHub commit hash", required=True)
|
|
66
70
|
def deploy(app, env, codebase, commit):
|
|
67
71
|
try:
|
|
68
|
-
Codebase().deploy(
|
|
72
|
+
Codebase(ParameterStore(get_aws_session_or_abort().client("ssm"))).deploy(
|
|
73
|
+
app, env, codebase, commit
|
|
74
|
+
)
|
|
69
75
|
except PlatformException as err:
|
|
70
76
|
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -1,56 +1,11 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import webbrowser
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Dict
|
|
5
|
-
|
|
6
|
-
import boto3
|
|
7
|
-
import botocore
|
|
8
1
|
import click
|
|
9
|
-
from prettytable import PrettyTable
|
|
10
2
|
|
|
11
|
-
from dbt_platform_helper.
|
|
3
|
+
from dbt_platform_helper.domain.config import Config
|
|
4
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
5
|
+
from dbt_platform_helper.providers.aws.sso_auth import SSOAuthProvider
|
|
12
6
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
13
|
-
from dbt_platform_helper.
|
|
14
|
-
IncompatibleMajorVersionException,
|
|
15
|
-
)
|
|
16
|
-
from dbt_platform_helper.providers.validation import ValidationException
|
|
17
|
-
from dbt_platform_helper.utils import tool_versioning
|
|
7
|
+
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
18
8
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
19
|
-
from dbt_platform_helper.utils.tool_versioning import get_platform_helper_version_status
|
|
20
|
-
|
|
21
|
-
yes = "\033[92m✔\033[0m"
|
|
22
|
-
no = "\033[91m✖\033[0m"
|
|
23
|
-
maybe = "\033[93m?\033[0m"
|
|
24
|
-
|
|
25
|
-
RECOMMENDATIONS = {
|
|
26
|
-
"dbt-platform-helper-upgrade": (
|
|
27
|
-
"Upgrade dbt-platform-helper to version {version} `pip install "
|
|
28
|
-
"--upgrade dbt-platform-helper=={version}`."
|
|
29
|
-
),
|
|
30
|
-
"dbt-platform-helper-upgrade-note": (
|
|
31
|
-
"Post upgrade, run `platform-helper copilot make-addons` to " "update your addon templates."
|
|
32
|
-
),
|
|
33
|
-
"generic-tool-upgrade": "Upgrade {tool} to version {version}.",
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
SSO_START_URL = "https://uktrade.awsapps.com/start"
|
|
37
|
-
|
|
38
|
-
AWS_CONFIG = """
|
|
39
|
-
#
|
|
40
|
-
# uktrade
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
[sso-session uktrade]
|
|
44
|
-
sso_start_url = https://uktrade.awsapps.com/start#/
|
|
45
|
-
sso_region = eu-west-2
|
|
46
|
-
sso_registration_scopes = sso:account:access
|
|
47
|
-
|
|
48
|
-
[default]
|
|
49
|
-
sso_session = uktrade
|
|
50
|
-
region = eu-west-2
|
|
51
|
-
output = json
|
|
52
|
-
|
|
53
|
-
"""
|
|
54
9
|
|
|
55
10
|
|
|
56
11
|
@click.group(cls=ClickDocOptGroup)
|
|
@@ -61,190 +16,10 @@ def config():
|
|
|
61
16
|
@config.command()
|
|
62
17
|
def validate():
|
|
63
18
|
"""Validate deployment or application configuration."""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ran_checks = True
|
|
69
|
-
|
|
70
|
-
if not ran_checks:
|
|
71
|
-
click.secho("Could not find a deployment repository, no checks to run.", fg="red")
|
|
72
|
-
exit(1)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def deployment():
|
|
76
|
-
click.secho()
|
|
77
|
-
|
|
78
|
-
compatible = True
|
|
79
|
-
platform_helper_version_status = get_platform_helper_version_status()
|
|
80
|
-
ClickIOProvider().process_messages(platform_helper_version_status.validate())
|
|
81
|
-
copilot_versions = tool_versioning.get_copilot_versions()
|
|
82
|
-
aws_versions = tool_versioning.get_aws_versions()
|
|
83
|
-
_check_tool_versions(platform_helper_version_status, copilot_versions, aws_versions)
|
|
84
|
-
click.secho("Checking addons templates versions...", fg="blue")
|
|
85
|
-
|
|
86
|
-
local_version = platform_helper_version_status.installed
|
|
87
|
-
latest_release = platform_helper_version_status.latest
|
|
88
|
-
addons_templates_table = PrettyTable()
|
|
89
|
-
addons_templates_table.field_names = [
|
|
90
|
-
"Addons Template File",
|
|
91
|
-
"Generated with",
|
|
92
|
-
"Compatible with local?",
|
|
93
|
-
"Compatible with latest?",
|
|
94
|
-
]
|
|
95
|
-
addons_templates_table.align["Addons Template File"] = "l"
|
|
96
|
-
|
|
97
|
-
addons_templates = list(Path("./copilot").glob("**/addons/*"))
|
|
98
|
-
# Sort by template file path
|
|
99
|
-
addons_templates.sort(key=lambda e: str(e))
|
|
100
|
-
# Bring environment addons to the top
|
|
101
|
-
addons_templates.sort(key=lambda e: "environments/" not in str(e))
|
|
102
|
-
|
|
103
|
-
recommendations = {}
|
|
104
|
-
|
|
105
|
-
ConfigProvider().config_file_check()
|
|
106
|
-
|
|
107
|
-
for template_file in addons_templates:
|
|
108
|
-
generated_with_version = maybe
|
|
109
|
-
local_compatible_symbol = yes
|
|
110
|
-
latest_compatible_symbol = yes
|
|
111
|
-
|
|
112
|
-
try:
|
|
113
|
-
generated_with_version = tool_versioning.get_template_generated_with_version(
|
|
114
|
-
str(template_file.resolve())
|
|
115
|
-
)
|
|
116
|
-
tool_versioning.validate_template_version(local_version, str(template_file.resolve()))
|
|
117
|
-
except IncompatibleMajorVersionException:
|
|
118
|
-
local_compatible_symbol = no
|
|
119
|
-
compatible = False
|
|
120
|
-
recommendations["dbt-platform-helper-upgrade"] = RECOMMENDATIONS[
|
|
121
|
-
"dbt-platform-helper-upgrade"
|
|
122
|
-
].format(version=latest_release)
|
|
123
|
-
recommendations["dbt-platform-helper-upgrade-note"] = RECOMMENDATIONS[
|
|
124
|
-
"dbt-platform-helper-upgrade-note"
|
|
125
|
-
]
|
|
126
|
-
except ValidationException:
|
|
127
|
-
local_compatible_symbol = maybe
|
|
128
|
-
compatible = False
|
|
129
|
-
recommendations["dbt-platform-helper-upgrade"] = RECOMMENDATIONS[
|
|
130
|
-
"dbt-platform-helper-upgrade"
|
|
131
|
-
].format(version=latest_release)
|
|
132
|
-
recommendations["dbt-platform-helper-upgrade-note"] = RECOMMENDATIONS[
|
|
133
|
-
"dbt-platform-helper-upgrade-note"
|
|
134
|
-
]
|
|
135
|
-
|
|
136
|
-
try:
|
|
137
|
-
generated_with_version = tool_versioning.get_template_generated_with_version(
|
|
138
|
-
str(template_file.resolve())
|
|
139
|
-
)
|
|
140
|
-
tool_versioning.validate_template_version(latest_release, str(template_file.resolve()))
|
|
141
|
-
except IncompatibleMajorVersionException:
|
|
142
|
-
latest_compatible_symbol = no
|
|
143
|
-
compatible = False
|
|
144
|
-
except ValidationException:
|
|
145
|
-
latest_compatible_symbol = maybe
|
|
146
|
-
compatible = False
|
|
147
|
-
|
|
148
|
-
addons_templates_table.add_row(
|
|
149
|
-
[
|
|
150
|
-
template_file.relative_to("."),
|
|
151
|
-
(maybe if latest_compatible_symbol is maybe else str(generated_with_version)),
|
|
152
|
-
local_compatible_symbol,
|
|
153
|
-
latest_compatible_symbol,
|
|
154
|
-
]
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
click.secho(addons_templates_table)
|
|
158
|
-
render_recommendations(recommendations)
|
|
159
|
-
|
|
160
|
-
exit(0 if compatible else 1)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def _check_tool_versions(platform_helper_versions, copilot_versions, aws_versions):
|
|
164
|
-
click.secho("Checking tooling versions...", fg="blue")
|
|
165
|
-
recommendations = {}
|
|
166
|
-
|
|
167
|
-
local_copilot_version = copilot_versions.installed
|
|
168
|
-
copilot_latest_release = copilot_versions.latest
|
|
169
|
-
if local_copilot_version is None:
|
|
170
|
-
recommendations["install-copilot"] = (
|
|
171
|
-
"Install AWS Copilot https://aws.github.io/copilot-cli/"
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
if aws_versions.installed is None:
|
|
175
|
-
recommendations["install-aws"] = "Install AWS CLI https://aws.amazon.com/cli/"
|
|
176
|
-
|
|
177
|
-
tool_versions_table = PrettyTable()
|
|
178
|
-
tool_versions_table.field_names = [
|
|
179
|
-
"Tool",
|
|
180
|
-
"Local version",
|
|
181
|
-
"Released version",
|
|
182
|
-
"Running latest?",
|
|
183
|
-
]
|
|
184
|
-
tool_versions_table.align["Tool"] = "l"
|
|
185
|
-
|
|
186
|
-
tool_versions_table.add_row(
|
|
187
|
-
[
|
|
188
|
-
"aws",
|
|
189
|
-
str(aws_versions.installed),
|
|
190
|
-
str(aws_versions.latest),
|
|
191
|
-
no if aws_versions.is_outdated() else yes,
|
|
192
|
-
]
|
|
193
|
-
)
|
|
194
|
-
tool_versions_table.add_row(
|
|
195
|
-
[
|
|
196
|
-
"copilot",
|
|
197
|
-
str(copilot_versions.installed),
|
|
198
|
-
str(copilot_versions.latest),
|
|
199
|
-
no if copilot_versions.is_outdated() else yes,
|
|
200
|
-
]
|
|
201
|
-
)
|
|
202
|
-
tool_versions_table.add_row(
|
|
203
|
-
[
|
|
204
|
-
"dbt-platform-helper",
|
|
205
|
-
str(platform_helper_versions.installed),
|
|
206
|
-
str(platform_helper_versions.latest),
|
|
207
|
-
no if platform_helper_versions.is_outdated() else yes,
|
|
208
|
-
]
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
click.secho(tool_versions_table)
|
|
212
|
-
|
|
213
|
-
if aws_versions.is_outdated() and "install-aws" not in recommendations:
|
|
214
|
-
recommendations["aws-upgrade"] = RECOMMENDATIONS["generic-tool-upgrade"].format(
|
|
215
|
-
tool="AWS CLI",
|
|
216
|
-
version=str(aws_versions.latest),
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
if copilot_versions.is_outdated() and "install-copilot" not in recommendations:
|
|
220
|
-
recommendations["copilot-upgrade"] = RECOMMENDATIONS["generic-tool-upgrade"].format(
|
|
221
|
-
tool="AWS Copilot",
|
|
222
|
-
version=str(copilot_latest_release),
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
if platform_helper_versions.is_outdated():
|
|
226
|
-
recommendations["dbt-platform-helper-upgrade"] = RECOMMENDATIONS[
|
|
227
|
-
"dbt-platform-helper-upgrade"
|
|
228
|
-
].format(version=str(platform_helper_versions.latest))
|
|
229
|
-
recommendations["dbt-platform-helper-upgrade-note"] = RECOMMENDATIONS[
|
|
230
|
-
"dbt-platform-helper-upgrade-note"
|
|
231
|
-
]
|
|
232
|
-
|
|
233
|
-
render_recommendations(recommendations)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def render_recommendations(recommendations: Dict[str, str]):
|
|
237
|
-
if recommendations:
|
|
238
|
-
click.secho("\nRecommendations:\n", bold=True)
|
|
239
|
-
|
|
240
|
-
for name, recommendation in recommendations.items():
|
|
241
|
-
if name.endswith("-note"):
|
|
242
|
-
continue
|
|
243
|
-
click.secho(f" - {recommendation}")
|
|
244
|
-
if recommendations.get(f"{name}-note", False):
|
|
245
|
-
click.secho(f" {recommendations.get(f'{name}-note')}")
|
|
246
|
-
|
|
247
|
-
click.secho()
|
|
19
|
+
try:
|
|
20
|
+
Config().validate()
|
|
21
|
+
except PlatformException as err:
|
|
22
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
248
23
|
|
|
249
24
|
|
|
250
25
|
@config.command()
|
|
@@ -256,85 +31,8 @@ def aws(file_path):
|
|
|
256
31
|
|
|
257
32
|
If no `--file-path` is specified, defaults to `~/.aws/config`.
|
|
258
33
|
"""
|
|
259
|
-
sso_oidc_client = boto3.client("sso-oidc", region_name="eu-west-2")
|
|
260
|
-
sso_client = boto3.client("sso", region_name="eu-west-2")
|
|
261
|
-
oidc_app = create_oidc_application(sso_oidc_client)
|
|
262
|
-
verification_url, device_code = get_device_code(sso_oidc_client, oidc_app, SSO_START_URL)
|
|
263
|
-
|
|
264
|
-
if click.confirm(
|
|
265
|
-
"You are about to be redirected to a verification page. You will need to complete sign-in before returning to the command line. Do you want to continue?",
|
|
266
|
-
abort=True,
|
|
267
|
-
):
|
|
268
|
-
webbrowser.open(verification_url)
|
|
269
|
-
|
|
270
|
-
if click.confirm("Have you completed the sign-in process in your browser?", abort=True):
|
|
271
|
-
access_token = get_access_token(device_code, sso_oidc_client, oidc_app)
|
|
272
|
-
|
|
273
|
-
aws_config_path = os.path.expanduser(file_path)
|
|
274
|
-
|
|
275
|
-
if click.confirm(
|
|
276
|
-
f"This command is destructive and will overwrite file contents at {file_path}. Are you sure you want to continue?",
|
|
277
|
-
abort=True,
|
|
278
|
-
):
|
|
279
|
-
with open(aws_config_path, "w") as config_file:
|
|
280
|
-
config_file.write(AWS_CONFIG)
|
|
281
|
-
|
|
282
|
-
for account in retrieve_aws_accounts(sso_client, access_token):
|
|
283
|
-
config_file.write(f"[profile {account['accountName']}]\n")
|
|
284
|
-
config_file.write("sso_session = uktrade\n")
|
|
285
|
-
config_file.write(f"sso_account_id = {account['accountId']}\n")
|
|
286
|
-
config_file.write("sso_role_name = AdministratorAccess\n")
|
|
287
|
-
config_file.write("region = eu-west-2\n")
|
|
288
|
-
config_file.write("output = json\n")
|
|
289
|
-
config_file.write("\n")
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
def create_oidc_application(sso_oidc_client):
|
|
293
|
-
print("Creating temporary AWS SSO OIDC application")
|
|
294
|
-
client = sso_oidc_client.register_client(
|
|
295
|
-
clientName="platform-helper",
|
|
296
|
-
clientType="public",
|
|
297
|
-
)
|
|
298
|
-
client_id = client.get("clientId")
|
|
299
|
-
client_secret = client.get("clientSecret")
|
|
300
|
-
|
|
301
|
-
return client_id, client_secret
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
def get_device_code(sso_oidc_client, oidc_application, start_url):
|
|
305
|
-
print("Initiating device code flow")
|
|
306
|
-
authz = sso_oidc_client.start_device_authorization(
|
|
307
|
-
clientId=oidc_application[0],
|
|
308
|
-
clientSecret=oidc_application[1],
|
|
309
|
-
startUrl=start_url,
|
|
310
|
-
)
|
|
311
|
-
url = authz.get("verificationUriComplete")
|
|
312
|
-
deviceCode = authz.get("deviceCode")
|
|
313
|
-
|
|
314
|
-
return url, deviceCode
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
def retrieve_aws_accounts(sso_client, aws_sso_token):
|
|
318
|
-
aws_accounts_response = sso_client.list_accounts(
|
|
319
|
-
accessToken=aws_sso_token,
|
|
320
|
-
maxResults=100,
|
|
321
|
-
)
|
|
322
|
-
if len(aws_accounts_response.get("accountList", [])) == 0:
|
|
323
|
-
raise RuntimeError("Unable to retrieve AWS SSO account list\n")
|
|
324
|
-
return aws_accounts_response.get("accountList")
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
def get_access_token(device_code, sso_oidc_client, oidc_app):
|
|
328
34
|
try:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
deviceCode=device_code,
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
return token_response.get("accessToken")
|
|
337
|
-
|
|
338
|
-
except botocore.exceptions.ClientError as e:
|
|
339
|
-
if e.response["Error"]["Code"] != "AuthorizationPendingException":
|
|
340
|
-
raise e
|
|
35
|
+
session = get_aws_session_or_abort()
|
|
36
|
+
Config(sso=SSOAuthProvider(session)).generate_aws(file_path)
|
|
37
|
+
except PlatformException as err:
|
|
38
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -10,13 +10,10 @@ from dbt_platform_helper.providers.config_validator import ConfigValidator
|
|
|
10
10
|
from dbt_platform_helper.providers.files import FileProvider
|
|
11
11
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
12
12
|
from dbt_platform_helper.providers.kms import KMSProvider
|
|
13
|
+
from dbt_platform_helper.providers.parameter_store import ParameterStore
|
|
13
14
|
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
14
15
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
15
16
|
|
|
16
|
-
# TODOs
|
|
17
|
-
# Figure out a pattern for copilot templating and the new copilot domain - probably a lot of overlap here that really belongs in the copilottemplating domain instead (atleast whatever is concerned with "templating")
|
|
18
|
-
# Check for E2E test coverage.
|
|
19
|
-
|
|
20
17
|
|
|
21
18
|
@click.group(chain=True, cls=ClickDocOptGroup)
|
|
22
19
|
def copilot():
|
|
@@ -28,8 +25,15 @@ def make_addons():
|
|
|
28
25
|
"""Generate addons CloudFormation for each environment."""
|
|
29
26
|
try:
|
|
30
27
|
session = get_aws_session_or_abort()
|
|
28
|
+
parameter_provider = ParameterStore(session.client("ssm"))
|
|
31
29
|
config_provider = ConfigProvider(ConfigValidator())
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
Copilot(
|
|
31
|
+
config_provider,
|
|
32
|
+
parameter_provider,
|
|
33
|
+
FileProvider(),
|
|
34
|
+
CopilotTemplating(),
|
|
35
|
+
KMSProvider,
|
|
36
|
+
session,
|
|
37
|
+
).make_addons()
|
|
34
38
|
except Exception as err:
|
|
35
39
|
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -2,6 +2,8 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from dbt_platform_helper.commands.environment import AVAILABLE_TEMPLATES
|
|
4
4
|
from dbt_platform_helper.domain.database_copy import DatabaseCopy
|
|
5
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
6
|
+
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
5
7
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
6
8
|
|
|
7
9
|
|
|
@@ -38,9 +40,11 @@ def database():
|
|
|
38
40
|
)
|
|
39
41
|
def dump(app, from_env, database, from_vpc, filename):
|
|
40
42
|
"""Dump a database into an S3 bucket."""
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
try:
|
|
44
|
+
data_copy = DatabaseCopy(app, database)
|
|
45
|
+
data_copy.dump(from_env, from_vpc, filename)
|
|
46
|
+
except PlatformException as err:
|
|
47
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
44
48
|
|
|
45
49
|
|
|
46
50
|
@database.command(name="load")
|
|
@@ -68,9 +72,11 @@ def dump(app, from_env, database, from_vpc, filename):
|
|
|
68
72
|
)
|
|
69
73
|
def load(app, to_env, database, to_vpc, auto_approve, filename):
|
|
70
74
|
"""Load a database from an S3 bucket."""
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
try:
|
|
76
|
+
data_copy = DatabaseCopy(app, database, auto_approve)
|
|
77
|
+
data_copy.load(to_env, to_vpc, filename)
|
|
78
|
+
except PlatformException as err:
|
|
79
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
74
80
|
|
|
75
81
|
|
|
76
82
|
@database.command(name="copy")
|
|
@@ -120,6 +126,8 @@ def copy(
|
|
|
120
126
|
no_maintenance_page,
|
|
121
127
|
):
|
|
122
128
|
"""Copy a database between environments."""
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
try:
|
|
130
|
+
data_copy = DatabaseCopy(app, database, auto_approve)
|
|
131
|
+
data_copy.copy(from_env, to_env, from_vpc, to_vpc, svc, template, no_maintenance_page)
|
|
132
|
+
except PlatformException as err:
|
|
133
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -94,9 +94,8 @@ def generate(name):
|
|
|
94
94
|
def generate_terraform(name, terraform_platform_modules_version):
|
|
95
95
|
click_io = ClickIOProvider()
|
|
96
96
|
try:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
config_provider = ConfigProvider(ConfigValidator())
|
|
97
|
+
session = get_aws_session_or_abort()
|
|
98
|
+
config_provider = ConfigProvider(ConfigValidator(session=session))
|
|
100
99
|
TerraformEnvironment(config_provider).generate(name, terraform_platform_modules_version)
|
|
101
100
|
except PlatformException as err:
|
|
102
101
|
click_io.abort_with_error(str(err))
|
|
@@ -11,6 +11,7 @@ from boto3 import Session
|
|
|
11
11
|
from dbt_platform_helper.platform_exception import PlatformException
|
|
12
12
|
from dbt_platform_helper.providers.files import FileProvider
|
|
13
13
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
14
|
+
from dbt_platform_helper.providers.parameter_store import ParameterStore
|
|
14
15
|
from dbt_platform_helper.utils.application import Application
|
|
15
16
|
from dbt_platform_helper.utils.application import (
|
|
16
17
|
ApplicationEnvironmentNotFoundException,
|
|
@@ -32,6 +33,7 @@ from dbt_platform_helper.utils.template import setup_templates
|
|
|
32
33
|
class Codebase:
|
|
33
34
|
def __init__(
|
|
34
35
|
self,
|
|
36
|
+
parameter_provider: ParameterStore,
|
|
35
37
|
io: ClickIOProvider = ClickIOProvider(),
|
|
36
38
|
load_application: Callable[[str], Application] = load_application,
|
|
37
39
|
get_aws_session_or_abort: Callable[[str], Session] = get_aws_session_or_abort,
|
|
@@ -50,6 +52,7 @@ class Codebase:
|
|
|
50
52
|
check_if_commit_exists: Callable[[str], str] = check_if_commit_exists,
|
|
51
53
|
run_subprocess: Callable[[str], str] = subprocess.run,
|
|
52
54
|
):
|
|
55
|
+
self.parameter_provider = parameter_provider
|
|
53
56
|
self.io = io
|
|
54
57
|
self.load_application = load_application
|
|
55
58
|
self.get_aws_session_or_abort = get_aws_session_or_abort
|
|
@@ -190,9 +193,8 @@ class Codebase:
|
|
|
190
193
|
"""List available codebases for the application."""
|
|
191
194
|
session = self.get_aws_session_or_abort()
|
|
192
195
|
application = self.load_application(app, session)
|
|
193
|
-
ssm_client = session.client("ssm")
|
|
194
196
|
ecr_client = session.client("ecr")
|
|
195
|
-
codebases = self.__get_codebases(application,
|
|
197
|
+
codebases = self.__get_codebases(application, session.client("ssm"))
|
|
196
198
|
|
|
197
199
|
self.io.info("The following codebases are available:")
|
|
198
200
|
|
|
@@ -209,11 +211,9 @@ class Codebase:
|
|
|
209
211
|
self.io.info("")
|
|
210
212
|
|
|
211
213
|
def __get_codebases(self, application, ssm_client):
|
|
212
|
-
parameters =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)["Parameters"]
|
|
216
|
-
|
|
214
|
+
parameters = self.parameter_provider.get_ssm_parameters_by_path(
|
|
215
|
+
f"/copilot/applications/{application.name}/codebases"
|
|
216
|
+
)
|
|
217
217
|
codebases = [json.loads(p["Value"]) for p in parameters]
|
|
218
218
|
|
|
219
219
|
if not codebases:
|