apx-aws-lambda 0.3.4__tar.gz → 0.3.5__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.4 → apx_aws_lambda-0.3.5}/PKG-INFO +2 -2
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/README.md +1 -1
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/lambda_.py +1 -1
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/proxy.py +40 -8
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/PKG-INFO +2 -2
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/pyproject.toml +1 -1
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/tests/test_proxy.py +77 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/LICENSE +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/__init__.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/cli.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/lambda_handler.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/overlays/index.json +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/plugin.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/shell.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda/tools.py +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/SOURCES.txt +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/requires.txt +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/apx_aws_lambda.egg-info/top_level.txt +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/setup.cfg +0 -0
- {apx_aws_lambda-0.3.4 → apx_aws_lambda-0.3.5}/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.5
|
|
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
|
|
@@ -89,7 +89,7 @@ cd apx-aws-lambda
|
|
|
89
89
|
|
|
90
90
|
The script runs `sam build` + `sam deploy`, prints the stack's `ProxyUrl` and calls `/health`.
|
|
91
91
|
|
|
92
|
-
**2. Register the app** — from a machine logged in to the platform (`action-platform login`) as someone with `org.manage
|
|
92
|
+
**2. Register the app** — happens by itself on the first deploy from the platform by someone with `org.manage`: the proxy answers 404 for an app it does not know, the plugin creates it (the deploy token carries `org.manage`) and goes on. Anyone else gets a readable refusal until a manager deploys once. From a machine logged in to the platform (`action-platform login`) as someone with `org.manage`, or to grant other subjects:
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
95
|
P=https://xxxx.lambda-url.us-east-1.on.aws
|
|
@@ -69,7 +69,7 @@ cd apx-aws-lambda
|
|
|
69
69
|
|
|
70
70
|
The script runs `sam build` + `sam deploy`, prints the stack's `ProxyUrl` and calls `/health`.
|
|
71
71
|
|
|
72
|
-
**2. Register the app** — from a machine logged in to the platform (`action-platform login`) as someone with `org.manage
|
|
72
|
+
**2. Register the app** — happens by itself on the first deploy from the platform by someone with `org.manage`: the proxy answers 404 for an app it does not know, the plugin creates it (the deploy token carries `org.manage`) and goes on. Anyone else gets a readable refusal until a manager deploys once. From a machine logged in to the platform (`action-platform login`) as someone with `org.manage`, or to grant other subjects:
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
75
|
P=https://xxxx.lambda-url.us-east-1.on.aws
|
|
@@ -13,6 +13,13 @@ from action_platform.remote.client import Remote
|
|
|
13
13
|
MIN_PROXY = "0.1.0"
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class ProxyRefused(DeployError):
|
|
17
|
+
def __init__(self, status: int, detail: str, method: str, path: str) -> None:
|
|
18
|
+
super().__init__(f"proxy {method} {path}: {status} {detail}")
|
|
19
|
+
self.status = status
|
|
20
|
+
self.detail = detail
|
|
21
|
+
|
|
22
|
+
|
|
16
23
|
class ProxyClient:
|
|
17
24
|
def __init__(self, url: str, app: str, timeout: float = 20.0) -> None:
|
|
18
25
|
self.url = url.rstrip("/")
|
|
@@ -41,7 +48,10 @@ class ProxyClient:
|
|
|
41
48
|
def health(self) -> dict:
|
|
42
49
|
return self._call("GET", "/health")
|
|
43
50
|
|
|
44
|
-
def credentials(
|
|
51
|
+
def credentials(
|
|
52
|
+
self, ctx: Context, duration: int = 3600, region: str | None = None
|
|
53
|
+
) -> dict:
|
|
54
|
+
"""The app's credentials; an app the proxy does not know yet is registered first when the token may (`org.manage`) — the first deploy by an organization manager creates the roles."""
|
|
45
55
|
health = self.health()
|
|
46
56
|
|
|
47
57
|
if tuple_of(health.get("version", "0")) < tuple_of(MIN_PROXY):
|
|
@@ -49,20 +59,42 @@ class ProxyClient:
|
|
|
49
59
|
f"proxy {self.url} is {health.get('version')}; this plugin needs {MIN_PROXY} or newer — update the proxy stack"
|
|
50
60
|
)
|
|
51
61
|
|
|
62
|
+
token = self.token(ctx)
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
return self._credentials(token, duration)
|
|
66
|
+
except ProxyRefused as e:
|
|
67
|
+
if e.status != 404:
|
|
68
|
+
raise
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
self.create(region, token=token)
|
|
72
|
+
except ProxyRefused as e:
|
|
73
|
+
if e.status == 403:
|
|
74
|
+
raise DeployError(
|
|
75
|
+
f"the proxy does not know {self.app} yet, and this deploy may not register it ({e.detail}): "
|
|
76
|
+
"deploy once as an organization manager, or run `action-platform aws-lambda proxy create`"
|
|
77
|
+
) from e
|
|
78
|
+
|
|
79
|
+
raise
|
|
80
|
+
|
|
81
|
+
return self._credentials(token, duration)
|
|
82
|
+
|
|
83
|
+
def _credentials(self, token: str, duration: int) -> dict:
|
|
52
84
|
return self._call(
|
|
53
85
|
"POST",
|
|
54
86
|
f"/apps/{self.app}/credentials",
|
|
55
87
|
{"duration": duration},
|
|
56
|
-
token=
|
|
88
|
+
token=token,
|
|
57
89
|
)
|
|
58
90
|
|
|
59
|
-
def create(self, region: str | None = None) -> dict:
|
|
60
|
-
"""Admin: both roles for the app, granted to the app itself — the
|
|
91
|
+
def create(self, region: str | None = None, token: str | None = None) -> dict:
|
|
92
|
+
"""Admin: both roles for the app, granted to the app itself — the token must carry `org.manage`."""
|
|
61
93
|
return self._call(
|
|
62
94
|
"POST",
|
|
63
95
|
f"/apps/{self.app}",
|
|
64
96
|
{"region": region} if region else {},
|
|
65
|
-
token=self.token(),
|
|
97
|
+
token=token or self.token(),
|
|
66
98
|
)
|
|
67
99
|
|
|
68
100
|
def show(self) -> dict:
|
|
@@ -79,8 +111,8 @@ class ProxyClient:
|
|
|
79
111
|
token=self.token(),
|
|
80
112
|
)
|
|
81
113
|
|
|
82
|
-
def env(self, ctx: Context) -> dict[str, str]:
|
|
83
|
-
data = self.credentials(ctx)
|
|
114
|
+
def env(self, ctx: Context, region: str | None = None) -> dict[str, str]:
|
|
115
|
+
data = self.credentials(ctx, region=region)
|
|
84
116
|
|
|
85
117
|
return {
|
|
86
118
|
"AWS_ACCESS_KEY_ID": data["access_key_id"],
|
|
@@ -119,7 +151,7 @@ class ProxyClient:
|
|
|
119
151
|
except ValueError:
|
|
120
152
|
pass
|
|
121
153
|
|
|
122
|
-
raise
|
|
154
|
+
raise ProxyRefused(e.code, str(detail), method, path) from e
|
|
123
155
|
except urllib.error.URLError as e:
|
|
124
156
|
raise DeployError(f"proxy {self.url} unreachable: {e.reason}") from e
|
|
125
157
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
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
|
|
@@ -89,7 +89,7 @@ cd apx-aws-lambda
|
|
|
89
89
|
|
|
90
90
|
The script runs `sam build` + `sam deploy`, prints the stack's `ProxyUrl` and calls `/health`.
|
|
91
91
|
|
|
92
|
-
**2. Register the app** — from a machine logged in to the platform (`action-platform login`) as someone with `org.manage
|
|
92
|
+
**2. Register the app** — happens by itself on the first deploy from the platform by someone with `org.manage`: the proxy answers 404 for an app it does not know, the plugin creates it (the deploy token carries `org.manage`) and goes on. Anyone else gets a readable refusal until a manager deploys once. From a machine logged in to the platform (`action-platform login`) as someone with `org.manage`, or to grant other subjects:
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
95
|
P=https://xxxx.lambda-url.us-east-1.on.aws
|
|
@@ -99,6 +99,83 @@ class ProxyClientTest(unittest.TestCase):
|
|
|
99
99
|
|
|
100
100
|
self.assertIn("403 nope", str(caught.exception))
|
|
101
101
|
|
|
102
|
+
def test_an_unknown_app_is_registered_on_the_way_when_the_token_may(self):
|
|
103
|
+
fake = FakeProxy({"POST /apps/acme/shop/orders": {"created": True}})
|
|
104
|
+
credentials = "POST /apps/acme/shop/orders/credentials"
|
|
105
|
+
|
|
106
|
+
def answer(request, timeout=None):
|
|
107
|
+
if (
|
|
108
|
+
f"{request.get_method()} {request.full_url.split('proxy.test', 1)[1]}"
|
|
109
|
+
== credentials
|
|
110
|
+
and credentials not in fake.answers
|
|
111
|
+
):
|
|
112
|
+
fake.answers[credentials] = GRANTED
|
|
113
|
+
fake.requests.append(
|
|
114
|
+
(
|
|
115
|
+
request.get_method(),
|
|
116
|
+
"/apps/acme/shop/orders/credentials",
|
|
117
|
+
None,
|
|
118
|
+
None,
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
raise urllib.error.HTTPError(
|
|
122
|
+
request.full_url,
|
|
123
|
+
404,
|
|
124
|
+
"no",
|
|
125
|
+
{},
|
|
126
|
+
io.BytesIO(b'{"error":"no app acme/shop/orders; create it first"}'),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
return fake(request, timeout)
|
|
130
|
+
|
|
131
|
+
with mock.patch("urllib.request.urlopen", answer):
|
|
132
|
+
env = ProxyClient("https://proxy.test", "acme/shop/orders").env(
|
|
133
|
+
self.ctx(), "eu-west-1"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
self.assertEqual(env["AWS_ACCESS_KEY_ID"], "AKIA")
|
|
137
|
+
self.assertEqual(
|
|
138
|
+
[(m, p, b) for m, p, b, _ in fake.requests[1:]],
|
|
139
|
+
[
|
|
140
|
+
("POST", "/apps/acme/shop/orders/credentials", None),
|
|
141
|
+
("POST", "/apps/acme/shop/orders", {"region": "eu-west-1"}),
|
|
142
|
+
("POST", "/apps/acme/shop/orders/credentials", {"duration": 3600}),
|
|
143
|
+
],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def test_an_unknown_app_the_token_may_not_register_is_a_readable_error(self):
|
|
147
|
+
fake = FakeProxy({})
|
|
148
|
+
|
|
149
|
+
def answer(request, timeout=None):
|
|
150
|
+
path = request.full_url.split("proxy.test", 1)[1]
|
|
151
|
+
|
|
152
|
+
if path.endswith("/credentials"):
|
|
153
|
+
raise urllib.error.HTTPError(
|
|
154
|
+
request.full_url,
|
|
155
|
+
404,
|
|
156
|
+
"no",
|
|
157
|
+
{},
|
|
158
|
+
io.BytesIO(b'{"error":"no app; create it first"}'),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if path == "/apps/acme/shop/orders":
|
|
162
|
+
raise urllib.error.HTTPError(
|
|
163
|
+
request.full_url,
|
|
164
|
+
403,
|
|
165
|
+
"no",
|
|
166
|
+
{},
|
|
167
|
+
io.BytesIO(b'{"error":"org.manage is required"}'),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
return fake(request, timeout)
|
|
171
|
+
|
|
172
|
+
with mock.patch("urllib.request.urlopen", answer):
|
|
173
|
+
with self.assertRaises(DeployError) as caught:
|
|
174
|
+
ProxyClient("https://proxy.test", "acme/shop/orders").env(self.ctx())
|
|
175
|
+
|
|
176
|
+
self.assertIn("organization manager", str(caught.exception))
|
|
177
|
+
self.assertIn("org.manage is required", str(caught.exception))
|
|
178
|
+
|
|
102
179
|
def test_an_old_proxy_is_refused(self):
|
|
103
180
|
fake = FakeProxy({}, version="0.0.1")
|
|
104
181
|
|
|
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
|