apx-aws-lambda 0.3.6__tar.gz → 0.3.7__tar.gz
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.
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/PKG-INFO +2 -2
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/README.md +1 -1
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/lambda_.py +34 -7
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/proxy.py +2 -2
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/PKG-INFO +2 -2
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/pyproject.toml +1 -1
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/tests/test_proxy.py +93 -1
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/LICENSE +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/__init__.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/cli.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/lambda_handler.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/overlays/index.json +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/plugin.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/shell.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda/tools.py +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/SOURCES.txt +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/requires.txt +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/apx_aws_lambda.egg-info/top_level.txt +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/setup.cfg +0 -0
- {apx_aws_lambda-0.3.6 → apx_aws_lambda-0.3.7}/tests/test_targets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
4
4
|
Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -51,7 +51,7 @@ action-platform diagnose
|
|
|
51
51
|
| Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
|
|
52
52
|
| Rollback | CloudFormation `rollback-stack` — previous stack state |
|
|
53
53
|
| Diagnose | stack status and the HTTP API url |
|
|
54
|
-
| Destroy | `sam delete` |
|
|
54
|
+
| Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
|
|
55
55
|
| Tools | `aws_lambda_stacks`, `aws_lambda_functions` |
|
|
56
56
|
| Commands | `action-platform aws-lambda stacks\|functions`, `action-platform aws-lambda proxy …` |
|
|
57
57
|
|
|
@@ -31,7 +31,7 @@ action-platform diagnose
|
|
|
31
31
|
| Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
|
|
32
32
|
| Rollback | CloudFormation `rollback-stack` — previous stack state |
|
|
33
33
|
| Diagnose | stack status and the HTTP API url |
|
|
34
|
-
| Destroy | `sam delete` |
|
|
34
|
+
| Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
|
|
35
35
|
| Tools | `aws_lambda_stacks`, `aws_lambda_functions` |
|
|
36
36
|
| Commands | `action-platform aws-lambda stacks\|functions`, `action-platform aws-lambda proxy …` |
|
|
37
37
|
|
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import os
|
|
8
8
|
import tomllib
|
|
9
|
+
from dataclasses import replace
|
|
9
10
|
|
|
10
11
|
from action_platform.abc import DeployTarget
|
|
11
12
|
from action_platform.core.context import Context, DeployResult, Diagnosis
|
|
@@ -13,7 +14,7 @@ from action_platform.core.exception import ActionPlatformError, DeployError
|
|
|
13
14
|
from action_platform.remote.client import Remote
|
|
14
15
|
|
|
15
16
|
from apx_aws_lambda import shell
|
|
16
|
-
from apx_aws_lambda.proxy import ProxyClient
|
|
17
|
+
from apx_aws_lambda.proxy import ProxyClient, ProxyRefused
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class LambdaTarget(DeployTarget):
|
|
@@ -233,14 +234,40 @@ class LambdaTarget(DeployTarget):
|
|
|
233
234
|
)
|
|
234
235
|
|
|
235
236
|
def delete(self, ctx: Context) -> None:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
"""The stage's stack goes; once no stage is left, the app leaves the proxy too — its roles and grant — when the token may (`org.manage`)."""
|
|
238
|
+
if self.diagnose(ctx).status != "missing":
|
|
239
|
+
sam = shell.require("sam", "pip install aws-sam-cli")
|
|
240
|
+
args = [*sam, "delete", "--no-prompts", "--stack-name", self._stack(ctx)]
|
|
241
|
+
region = self._region(ctx)
|
|
242
|
+
|
|
243
|
+
if region:
|
|
244
|
+
args += ["--region", region]
|
|
245
|
+
|
|
246
|
+
shell.run(args, cwd=ctx.repo_root, env=self.env(ctx))
|
|
247
|
+
|
|
248
|
+
proxy = self.proxy(ctx)
|
|
249
|
+
|
|
250
|
+
if proxy is None or self._other_stage_lives(ctx):
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
try:
|
|
254
|
+
proxy.delete(token=proxy.token(ctx))
|
|
255
|
+
except ProxyRefused as e:
|
|
256
|
+
if e.status == 404:
|
|
257
|
+
return
|
|
258
|
+
|
|
259
|
+
if e.status == 403:
|
|
260
|
+
raise DeployError(
|
|
261
|
+
f"the stacks are gone but the proxy still knows {proxy.app} ({e.detail}): "
|
|
262
|
+
"delete as an organization manager, or run `action-platform aws-lambda proxy delete`"
|
|
263
|
+
) from e
|
|
264
|
+
|
|
265
|
+
raise
|
|
239
266
|
|
|
240
|
-
|
|
241
|
-
|
|
267
|
+
def _other_stage_lives(self, ctx: Context) -> bool:
|
|
268
|
+
other = replace(ctx, stage="dev" if ctx.stage == "prod" else "prod")
|
|
242
269
|
|
|
243
|
-
|
|
270
|
+
return self.diagnose(other).status != "missing"
|
|
244
271
|
|
|
245
272
|
def _url(self, ctx: Context) -> str | None:
|
|
246
273
|
try:
|
|
@@ -100,8 +100,8 @@ class ProxyClient:
|
|
|
100
100
|
def show(self) -> dict:
|
|
101
101
|
return self._call("GET", f"/apps/{self.app}", token=self.token())
|
|
102
102
|
|
|
103
|
-
def delete(self) -> dict:
|
|
104
|
-
return self._call("DELETE", f"/apps/{self.app}", token=self.token())
|
|
103
|
+
def delete(self, token: str | None = None) -> dict:
|
|
104
|
+
return self._call("DELETE", f"/apps/{self.app}", token=token or self.token())
|
|
105
105
|
|
|
106
106
|
def grant(self, subjects: list[str]) -> dict:
|
|
107
107
|
return self._call(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
4
4
|
Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -51,7 +51,7 @@ action-platform diagnose
|
|
|
51
51
|
| Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
|
|
52
52
|
| Rollback | CloudFormation `rollback-stack` — previous stack state |
|
|
53
53
|
| Diagnose | stack status and the HTTP API url |
|
|
54
|
-
| Destroy | `sam delete` |
|
|
54
|
+
| Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
|
|
55
55
|
| Tools | `aws_lambda_stacks`, `aws_lambda_functions` |
|
|
56
56
|
| Commands | `action-platform aws-lambda stacks\|functions`, `action-platform aws-lambda proxy …` |
|
|
57
57
|
|
|
@@ -58,7 +58,7 @@ class FakeProxy:
|
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
class
|
|
61
|
+
class ProxyCase(unittest.TestCase):
|
|
62
62
|
def setUp(self):
|
|
63
63
|
self.tmp = TemporaryDirectory()
|
|
64
64
|
self.root = Path(self.tmp.name)
|
|
@@ -72,6 +72,8 @@ class ProxyClientTest(unittest.TestCase):
|
|
|
72
72
|
identity=(lambda audience: f"{token}:{audience}") if token else None,
|
|
73
73
|
)
|
|
74
74
|
|
|
75
|
+
|
|
76
|
+
class ProxyClientTest(ProxyCase):
|
|
75
77
|
def test_env_carries_credentials_from_the_grant(self):
|
|
76
78
|
fake = FakeProxy({"POST /apps/acme/shop/orders/credentials": GRANTED})
|
|
77
79
|
|
|
@@ -268,3 +270,93 @@ class ProxyClientTest(unittest.TestCase):
|
|
|
268
270
|
"ExecutionRoleArn=arn:aws:iam::1:role/action-platform/ap-exec-acme-shop-orders",
|
|
269
271
|
],
|
|
270
272
|
)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class DeleteTest(ProxyCase):
|
|
276
|
+
def run_with(self, live: set[str]):
|
|
277
|
+
calls: list[list[str]] = []
|
|
278
|
+
|
|
279
|
+
def run(args, cwd=None, env=None):
|
|
280
|
+
calls.append(args)
|
|
281
|
+
|
|
282
|
+
if args[1:3] == ["cloudformation", "describe-stacks"]:
|
|
283
|
+
stack = args[args.index("--stack-name") + 1]
|
|
284
|
+
|
|
285
|
+
if stack not in live:
|
|
286
|
+
raise DeployError("does not exist")
|
|
287
|
+
|
|
288
|
+
return json.dumps({"Stacks": [{"StackStatus": "UPDATE_COMPLETE"}]})
|
|
289
|
+
|
|
290
|
+
if args[1] == "delete":
|
|
291
|
+
live.discard(args[args.index("--stack-name") + 1])
|
|
292
|
+
|
|
293
|
+
return "{}"
|
|
294
|
+
|
|
295
|
+
return calls, run
|
|
296
|
+
|
|
297
|
+
def test_delete_drops_the_stage_and_leaves_the_proxy_while_another_stage_lives(
|
|
298
|
+
self,
|
|
299
|
+
):
|
|
300
|
+
(self.root / "samconfig.toml").write_text(SAMCONFIG.format(stack="x"))
|
|
301
|
+
fake = FakeProxy({"POST /apps/acme/shop/orders/credentials": GRANTED})
|
|
302
|
+
target = LambdaTarget(proxy_url="https://proxy.test", app="acme/shop/orders")
|
|
303
|
+
calls, run = self.run_with(
|
|
304
|
+
{"ap-acme-shop-orders-dev", "ap-acme-shop-orders-prod"}
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
with (
|
|
308
|
+
mock.patch("urllib.request.urlopen", fake),
|
|
309
|
+
mock.patch.multiple(
|
|
310
|
+
shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
|
|
311
|
+
),
|
|
312
|
+
):
|
|
313
|
+
target.delete(self.ctx())
|
|
314
|
+
|
|
315
|
+
deleted = next(c for c in calls if c[1] == "delete")
|
|
316
|
+
self.assertEqual(
|
|
317
|
+
deleted[deleted.index("--stack-name") + 1], "ap-acme-shop-orders-dev"
|
|
318
|
+
)
|
|
319
|
+
self.assertNotIn("DELETE", [r[0] for r in fake.requests])
|
|
320
|
+
|
|
321
|
+
def test_delete_of_the_last_stage_deregisters_the_app(self):
|
|
322
|
+
(self.root / "samconfig.toml").write_text(SAMCONFIG.format(stack="x"))
|
|
323
|
+
fake = FakeProxy(
|
|
324
|
+
{
|
|
325
|
+
"POST /apps/acme/shop/orders/credentials": GRANTED,
|
|
326
|
+
"DELETE /apps/acme/shop/orders": {"deleted": True},
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
target = LambdaTarget(proxy_url="https://proxy.test", app="acme/shop/orders")
|
|
330
|
+
calls, run = self.run_with({"ap-acme-shop-orders-dev"})
|
|
331
|
+
|
|
332
|
+
with (
|
|
333
|
+
mock.patch("urllib.request.urlopen", fake),
|
|
334
|
+
mock.patch.multiple(
|
|
335
|
+
shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
|
|
336
|
+
),
|
|
337
|
+
):
|
|
338
|
+
target.delete(self.ctx())
|
|
339
|
+
|
|
340
|
+
self.assertEqual(
|
|
341
|
+
[r[:2] for r in fake.requests if r[0] == "DELETE"],
|
|
342
|
+
[("DELETE", "/apps/acme/shop/orders")],
|
|
343
|
+
)
|
|
344
|
+
self.assertEqual(len([c for c in calls if c[1] == "delete"]), 1)
|
|
345
|
+
|
|
346
|
+
def test_delete_without_org_manage_says_who_can_finish(self):
|
|
347
|
+
(self.root / "samconfig.toml").write_text(SAMCONFIG.format(stack="x"))
|
|
348
|
+
fake = FakeProxy({"POST /apps/acme/shop/orders/credentials": GRANTED})
|
|
349
|
+
target = LambdaTarget(proxy_url="https://proxy.test", app="acme/shop/orders")
|
|
350
|
+
calls, run = self.run_with(set())
|
|
351
|
+
|
|
352
|
+
with (
|
|
353
|
+
mock.patch("urllib.request.urlopen", fake),
|
|
354
|
+
mock.patch.multiple(
|
|
355
|
+
shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
|
|
356
|
+
),
|
|
357
|
+
):
|
|
358
|
+
with self.assertRaises(DeployError) as caught:
|
|
359
|
+
target.delete(self.ctx())
|
|
360
|
+
|
|
361
|
+
self.assertIn("organization manager", str(caught.exception))
|
|
362
|
+
self.assertEqual([c for c in calls if c[1] == "delete"], [])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|