canyonos 0.2.3.dev5__tar.gz → 0.2.4.dev2__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.
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/PKG-INFO +2 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/api.py +87 -41
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/auth.py +4 -4
- canyonos-0.2.4.dev2/canyonos/aws_account.py +349 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/aws_provision.py +189 -160
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/chat.py +34 -32
- canyonos-0.2.4.dev2/canyonos/cluster_provision.py +692 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/constants.py +1 -39
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/context.py +60 -12
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/curl.py +10 -9
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/dashboard.compose.yml +7 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/dashboard.py +12 -14
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/dashboard_stack.py +7 -3
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/deploy.py +49 -115
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/deployment.py +19 -3
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/doctor.py +4 -13
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/forwards.py +6 -6
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/init.py +16 -78
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/internal_ca.py +6 -8
- canyonos-0.2.4.dev2/canyonos/keychain.py +197 -0
- canyonos-0.2.4.dev2/canyonos/kubernetes_local.py +687 -0
- canyonos-0.2.4.dev2/canyonos/kubernetes_names.py +66 -0
- canyonos-0.2.4.dev2/canyonos/login.py +472 -0
- canyonos-0.2.4.dev2/canyonos/logout.py +54 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/agents/workflow.py.tmpl +1 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/workflow_config.yaml +2 -2
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/os_support/_windows.py +6 -2
- canyonos-0.2.4.dev2/canyonos/platform.py +165 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/port_utils.py +8 -21
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/ports.py +8 -11
- canyonos-0.2.4.dev2/canyonos/provision.py +221 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/quickstart.py +5 -5
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/records.py +32 -0
- canyonos-0.2.4.dev2/canyonos/rosa_provision.py +932 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/sdk/models.py +12 -3
- canyonos-0.2.4.dev2/canyonos/session.py +396 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/agents/workflow.py.tmpl +4 -3
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/workflow.py.tmpl +5 -4
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/workflow_config.yaml +6 -3
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/status.py +22 -7
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/sync.py +3 -27
- canyonos-0.2.4.dev2/canyonos/targets/__init__.py +111 -0
- canyonos-0.2.4.dev2/canyonos/targets/docker.py +183 -0
- canyonos-0.2.3.dev5/canyonos/kubernetes_target.py → canyonos-0.2.4.dev2/canyonos/targets/kubernetes.py +213 -97
- canyonos-0.2.4.dev2/canyonos/terraform/rosa/.terraform.lock.hcl +124 -0
- canyonos-0.2.4.dev2/canyonos/terraform/rosa/main.tf +65 -0
- canyonos-0.2.4.dev2/canyonos/terraform/rosa/outputs.tf +29 -0
- canyonos-0.2.4.dev2/canyonos/terraform/rosa/variables.tf +80 -0
- canyonos-0.2.4.dev2/canyonos/terraform/rosa/versions.tf +17 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/test.py +45 -34
- canyonos-0.2.4.dev2/canyonos/tools.py +131 -0
- canyonos-0.2.4.dev2/canyonos/whoami.py +92 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/PKG-INFO +2 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/SOURCES.txt +19 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/requires.txt +1 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/cli.py +138 -35
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/pyproject.toml +6 -1
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/utils/help_screen.py +17 -2
- canyonos-0.2.3.dev5/canyonos/kubernetes_local.py +0 -419
- canyonos-0.2.3.dev5/canyonos/provision.py +0 -44
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/README.md +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/__init__.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/clean.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/config.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/contact.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/convert.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/dashboard_registration.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/dev_machine.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/docker_cmd.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/env.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/feedback.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/logs.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/.env.example +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/.gitignore +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/agents/my_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/llms.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/policy.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/prompts.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/new_app_template/config/scaling.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/os_support/__init__.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/os_support/_posix.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/resources.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/sdk/__init__.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/selection.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/serve.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/README.md +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/agents/hello_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/policy.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/test_query.txt +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/helloworld/config/workflow_config.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/helloworld/workflow_group.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/.env +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/.env.example +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/advisor_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/intent_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/metrics_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/price_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/agents/risk_agent.py.tmpl +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/llms.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/policy.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/prompts.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/scaling.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/portfolio/config/test_query.txt +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/starters/portfolio/workflow_group.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/stop.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/theme.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/ui.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/upgrade.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/usage/__init__.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/usage/consent.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/usage/delivery.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/usage/outbox.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/usage/settings.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/validate.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos/workflow_group.yaml +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/dependency_links.txt +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/entry_points.txt +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/canyonos.egg-info/top_level.txt +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/setup.cfg +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/utils/__init__.py +0 -0
- {canyonos-0.2.3.dev5 → canyonos-0.2.4.dev2}/utils/tui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: canyonos
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4.dev2
|
|
4
4
|
Summary: Open-source platform for multi-agent apps: per-agent scaling, tracing and cost, in plain Python
|
|
5
5
|
License-Expression: AGPL-3.0-only
|
|
6
6
|
Project-URL: Homepage, https://canyonos.ai
|
|
@@ -17,6 +17,7 @@ Description-Content-Type: text/markdown
|
|
|
17
17
|
Requires-Dist: boto3[crt]>=1.43.109
|
|
18
18
|
Requires-Dist: cryptography>=50.0.2
|
|
19
19
|
Requires-Dist: pyfiglet
|
|
20
|
+
Requires-Dist: pyjwt[crypto]>=2.10.1
|
|
20
21
|
Requires-Dist: python-dotenv
|
|
21
22
|
Requires-Dist: pyyaml
|
|
22
23
|
Requires-Dist: rich
|
|
@@ -8,11 +8,9 @@ read a workflow group don't each restate the same routes, payloads and failure m
|
|
|
8
8
|
On Docker the API is the local stack's (`dashboard_stack`), on 127.0.0.1 at its host
|
|
9
9
|
port, and every call sends this machine's deploy key, which opens every workflow
|
|
10
10
|
group's routes here and is the only key that creates one; the API runs each workflow
|
|
11
|
-
group's Global Controller container through Docker.
|
|
12
|
-
the
|
|
13
|
-
|
|
14
|
-
CanyonProject. Both answer the same routes and shapes, and an error is
|
|
15
|
-
`{error, message, findings?, warnings?}`.
|
|
11
|
+
group's Global Controller container through Docker. Another target's API is elsewhere,
|
|
12
|
+
at the URL and with the headers its `state()` gives (`canyonos.targets`). All answer the
|
|
13
|
+
same routes and shapes, and an error is `{error, message, findings?, warnings?}`.
|
|
16
14
|
"""
|
|
17
15
|
|
|
18
16
|
import json
|
|
@@ -28,10 +26,9 @@ from canyonos.init import load_state
|
|
|
28
26
|
|
|
29
27
|
REQUEST_TIMEOUT_SECONDS = 60
|
|
30
28
|
STATUS_TIMEOUT_SECONDS = 5
|
|
31
|
-
# Longer than
|
|
32
|
-
#
|
|
29
|
+
# Longer than this machine's API's wait for the deploy to stop, which drains every
|
|
30
|
+
# replica first.
|
|
33
31
|
CLEAN_REQUEST_TIMEOUT_SECONDS = 270
|
|
34
|
-
KUBERNETES_CLEAN_REQUEST_TIMEOUT_SECONDS = 905
|
|
35
32
|
# Longer than one log read on a replica's machine, which may take up to 180s over SSH.
|
|
36
33
|
LOGS_REQUEST_TIMEOUT_SECONDS = 200
|
|
37
34
|
# The API stores a registration without reaching the workflow group's Redis.
|
|
@@ -45,10 +42,10 @@ PREFIX = "/v1/workflow-groups"
|
|
|
45
42
|
# The CanyonOS API names its errors `workflow_groups.<code>`.
|
|
46
43
|
ERROR_PREFIX = "workflow_groups."
|
|
47
44
|
UNKNOWN_WORKFLOW_GROUP = "unknown_workflow_group"
|
|
48
|
-
# What an older
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
|
|
45
|
+
# What an older API elsewhere answers: no route there (a release before the /v1
|
|
46
|
+
# routes), or the /v1 routes of an API that drives only Docker, without Docker or the
|
|
47
|
+
# control key those releases asked for.
|
|
48
|
+
OLDER_API_ERRORS = {
|
|
52
49
|
404: (None, "not_found"),
|
|
53
50
|
503: ("docker.disabled",),
|
|
54
51
|
401: ("auth.control_key_unset",),
|
|
@@ -111,8 +108,9 @@ def forget_api_url():
|
|
|
111
108
|
_docker_url = None
|
|
112
109
|
|
|
113
110
|
|
|
114
|
-
def
|
|
115
|
-
"""Whether `state`'s workflow group is reached through
|
|
111
|
+
def _api_elsewhere(state):
|
|
112
|
+
"""Whether `state`'s workflow group is reached through a CanyonOS API that is not
|
|
113
|
+
this machine's."""
|
|
116
114
|
return bool(state and "api_url" in state)
|
|
117
115
|
|
|
118
116
|
|
|
@@ -126,9 +124,9 @@ def docker_api_headers():
|
|
|
126
124
|
|
|
127
125
|
def _connection(state):
|
|
128
126
|
"""The base URL and headers a call about `state`'s workflow group goes to: the
|
|
129
|
-
|
|
127
|
+
API elsewhere that `state` names, else this machine's with its deploy key; this
|
|
130
128
|
machine's when `state` is None."""
|
|
131
|
-
if
|
|
129
|
+
if _api_elsewhere(state):
|
|
132
130
|
return state["api_url"], state["api_headers"]
|
|
133
131
|
return docker_api_url(), docker_api_headers()
|
|
134
132
|
|
|
@@ -168,8 +166,8 @@ def error_detail(body, status):
|
|
|
168
166
|
|
|
169
167
|
def _database_hint(state):
|
|
170
168
|
"""What to do about the API's database being down: on this machine, `canyonos
|
|
171
|
-
serve` starts it again; ""
|
|
172
|
-
if
|
|
169
|
+
serve` starts it again; "" for an API elsewhere, whose database is not here."""
|
|
170
|
+
if _api_elsewhere(state):
|
|
173
171
|
return ""
|
|
174
172
|
return " If it stays down, run `canyonos serve`, which starts it again."
|
|
175
173
|
|
|
@@ -177,7 +175,7 @@ def _database_hint(state):
|
|
|
177
175
|
def _next_step(state, code):
|
|
178
176
|
"""What to do about the API refusing a call with `code`, as a sentence to add to
|
|
179
177
|
its message; "" when there is nothing to add."""
|
|
180
|
-
if
|
|
178
|
+
if _api_elsewhere(state):
|
|
181
179
|
return ""
|
|
182
180
|
if code in API_KEY_REFUSALS:
|
|
183
181
|
# deploy, sync and stop restart an API on another deploy key themselves
|
|
@@ -208,13 +206,10 @@ def _open(state, method, path, action, data=None, headers=None, timeout=None):
|
|
|
208
206
|
except urllib.error.HTTPError as e:
|
|
209
207
|
detail = error_detail(e.read(), e.code)
|
|
210
208
|
message = detail["error"]
|
|
211
|
-
if
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
from canyonos.kubernetes_target import UPGRADE_CHART
|
|
216
|
-
|
|
217
|
-
message = f"{UPGRADE_CHART} (the cluster's API answered: {message})"
|
|
209
|
+
if _api_elsewhere(state) and detail["code"] in OLDER_API_ERRORS.get(e.code, ()):
|
|
210
|
+
message = (
|
|
211
|
+
f"{state['older_api_fix']} ({state['api_name']} answered: {message})"
|
|
212
|
+
)
|
|
218
213
|
next_step = _next_step(state, detail["code"])
|
|
219
214
|
if next_step:
|
|
220
215
|
message = f"{message.rstrip('.')}.{next_step}"
|
|
@@ -234,7 +229,7 @@ def _open(state, method, path, action, data=None, headers=None, timeout=None):
|
|
|
234
229
|
reason = getattr(e, "reason", e)
|
|
235
230
|
hint = (
|
|
236
231
|
""
|
|
237
|
-
if
|
|
232
|
+
if _api_elsewhere(state)
|
|
238
233
|
else "Run `canyonos deploy` or `canyonos serve` to start it."
|
|
239
234
|
)
|
|
240
235
|
raise ApiError(
|
|
@@ -303,7 +298,7 @@ def start_api_for(state):
|
|
|
303
298
|
`state` records is on this machine, so a command that only reads can ask it. A
|
|
304
299
|
running API is left as it is, and one that won't start is left to the request that
|
|
305
300
|
follows to report."""
|
|
306
|
-
if
|
|
301
|
+
if _api_elsewhere(state):
|
|
307
302
|
return
|
|
308
303
|
# Imported here: serve imports this module.
|
|
309
304
|
from canyonos.serve import start_api_if_down
|
|
@@ -381,8 +376,8 @@ def probe(state=None):
|
|
|
381
376
|
raise ApiError(
|
|
382
377
|
f"The CanyonOS API at {_connection(state)[0]} has no {PREFIX} routes: it "
|
|
383
378
|
f"runs an older image than this CLI ({env.api_image}). In a checkout, build "
|
|
384
|
-
"it with `bun run canyonos:dev`
|
|
385
|
-
"built from
|
|
379
|
+
"it with `bun run canyonos:dev` and retry with `cli-dev` in that shell, "
|
|
380
|
+
"or point CANYONOS_API_IMAGE at an image built from this checkout.",
|
|
386
381
|
status=404,
|
|
387
382
|
code=e.code,
|
|
388
383
|
) from None
|
|
@@ -444,8 +439,8 @@ def delete_workflow_group(state):
|
|
|
444
439
|
"DELETE",
|
|
445
440
|
_group_path(state),
|
|
446
441
|
"Stop",
|
|
447
|
-
timeout=
|
|
448
|
-
if
|
|
442
|
+
timeout=state["clean_timeout"]
|
|
443
|
+
if _api_elsewhere(state)
|
|
449
444
|
else CLEAN_REQUEST_TIMEOUT_SECONDS,
|
|
450
445
|
)
|
|
451
446
|
|
|
@@ -468,13 +463,12 @@ def workflow_group_status(state):
|
|
|
468
463
|
return None
|
|
469
464
|
raise
|
|
470
465
|
version = status.get("version")
|
|
471
|
-
# A checkout's CLI runs whatever core image it is pointed at
|
|
466
|
+
# A checkout's CLI runs whatever core image it is pointed at.
|
|
472
467
|
# A Global Controller that has not reported yet has no version to compare.
|
|
473
468
|
if not env.is_development and version is not None and version != env.VERSION:
|
|
474
|
-
#
|
|
475
|
-
if
|
|
476
|
-
runs = "
|
|
477
|
-
fix = f"Upgrade the CanyonOS operator chart to {env.VERSION}."
|
|
469
|
+
# Elsewhere it is that API's own release, which a deploy keeps.
|
|
470
|
+
if _api_elsewhere(state):
|
|
471
|
+
runs, fix = state["other_release"]
|
|
478
472
|
else:
|
|
479
473
|
runs = "This workflow group's Global Controller runs"
|
|
480
474
|
fix = (
|
|
@@ -502,9 +496,8 @@ def deploy_status(state):
|
|
|
502
496
|
|
|
503
497
|
|
|
504
498
|
def deployed_endpoint(state):
|
|
505
|
-
"""Return the endpoint
|
|
506
|
-
|
|
507
|
-
raise ApiError when the deploy has none yet."""
|
|
499
|
+
"""Return the running deploy's endpoint as the CanyonOS API reports it, reachable
|
|
500
|
+
from here (`reachable_endpoint`); raise ApiError when the deploy has none yet."""
|
|
508
501
|
status = workflow_group_status(state) or {}
|
|
509
502
|
endpoint = status.get("endpoint")
|
|
510
503
|
if endpoint is None:
|
|
@@ -514,7 +507,60 @@ def deployed_endpoint(state):
|
|
|
514
507
|
f"The running deploy has no endpoint yet.{reasons} Run `canyonos status` "
|
|
515
508
|
"to see when it is up."
|
|
516
509
|
)
|
|
517
|
-
return endpoint
|
|
510
|
+
return reachable_endpoint(state, endpoint)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def reachable_endpoint(state, endpoint):
|
|
514
|
+
"""`endpoint`, a workflow group's `routes` (each with its `workflow`,
|
|
515
|
+
`workflow_id`, `agent`, `method`, `arguments` and the `url` it is called at),
|
|
516
|
+
`webhooks` and the `status_url` a request's status is read under, as the CanyonOS
|
|
517
|
+
API reports them, with every URL reachable from here: on Kubernetes the ones that
|
|
518
|
+
name the cluster's in-cluster API Service point at this machine's forward to it."""
|
|
519
|
+
if not _api_elsewhere(state):
|
|
520
|
+
return endpoint
|
|
521
|
+
# Imported here: canyonos.targets.kubernetes imports this module.
|
|
522
|
+
from canyonos.targets.kubernetes import local_api_url
|
|
523
|
+
|
|
524
|
+
def reachable(url):
|
|
525
|
+
return local_api_url(url, state["api_url"])
|
|
526
|
+
|
|
527
|
+
return {
|
|
528
|
+
**endpoint,
|
|
529
|
+
"routes": [
|
|
530
|
+
{**route, "url": reachable(route["url"])} for route in endpoint["routes"]
|
|
531
|
+
],
|
|
532
|
+
"webhooks": [
|
|
533
|
+
{**webhook, "url": reachable(webhook["url"])}
|
|
534
|
+
for webhook in endpoint["webhooks"]
|
|
535
|
+
],
|
|
536
|
+
"status_url": reachable(endpoint["status_url"]),
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def api_base(url):
|
|
541
|
+
"""The base URL of the CanyonOS API in `url`, a route's URL or the `status_url` it
|
|
542
|
+
reports: `url` without its last path segment and its query."""
|
|
543
|
+
parts = urllib.parse.urlsplit(url)
|
|
544
|
+
return urllib.parse.urlunsplit(
|
|
545
|
+
(parts.scheme, parts.netloc, parts.path.rsplit("/", 1)[0], "", "")
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def request_status_url(route_url, request_id):
|
|
550
|
+
"""Where the status of request `request_id`, sent to the route at `route_url`, is
|
|
551
|
+
read."""
|
|
552
|
+
return f"{api_base(route_url)}/status/{request_id}"
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def answers_url(route_url, workflow_group_id, request_id):
|
|
556
|
+
"""Where an answer to a question of request `request_id`, sent to the route at
|
|
557
|
+
`route_url` of workflow group `workflow_group_id`, is posted; `?question=<id>`
|
|
558
|
+
names the question, else the oldest one waiting is answered."""
|
|
559
|
+
workflow_id = urllib.parse.urlsplit(route_url).path.rsplit("/", 1)[1]
|
|
560
|
+
return (
|
|
561
|
+
f"{api_base(route_url)}{PREFIX}/{_quoted(workflow_group_id)}/workflows/"
|
|
562
|
+
f"{workflow_id}/requests/{request_id}/answers"
|
|
563
|
+
)
|
|
518
564
|
|
|
519
565
|
|
|
520
566
|
def test_queries(state):
|
|
@@ -26,8 +26,8 @@ API_KEY_FILE = "api_key"
|
|
|
26
26
|
BEARER_PLACEHOLDER = '-H "Authorization: Bearer <your api key>"'
|
|
27
27
|
|
|
28
28
|
NO_KEY_WARNING = (
|
|
29
|
-
"This workflow group has no API key:
|
|
30
|
-
"
|
|
29
|
+
"This workflow group has no API key: anyone who reaches the CanyonOS API can call "
|
|
30
|
+
"its workflows and its dashboard routes. Set one with --api-key <key>."
|
|
31
31
|
)
|
|
32
32
|
KEY_SET = "This workflow group now uses an API key for secure connections."
|
|
33
33
|
ONLY_THIS_GROUP = (
|
|
@@ -107,8 +107,8 @@ def _adopt_machine_key(deploying: str) -> None:
|
|
|
107
107
|
) from error
|
|
108
108
|
if key is not None:
|
|
109
109
|
ui.note(
|
|
110
|
-
f"Each workflow group now
|
|
111
|
-
"
|
|
110
|
+
f"Each workflow group now has its own API key. The key from {legacy} "
|
|
111
|
+
"was copied into each group's api_key file."
|
|
112
112
|
)
|
|
113
113
|
|
|
114
114
|
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Canyon Code, Inc.
|
|
2
|
+
# SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
The AWS account `canyonos provision` works in: signing in, and the region, asked the
|
|
6
|
+
same way by every provisioner that makes something in AWS.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
|
|
13
|
+
from canyonos import ui
|
|
14
|
+
from canyonos.provision import Cancelled, ask, pick
|
|
15
|
+
|
|
16
|
+
STS_REGION = "us-east-1"
|
|
17
|
+
REGIONS = (
|
|
18
|
+
"us-east-1",
|
|
19
|
+
"us-east-2",
|
|
20
|
+
"us-west-2",
|
|
21
|
+
"eu-west-1",
|
|
22
|
+
"eu-central-1",
|
|
23
|
+
"ap-southeast-1",
|
|
24
|
+
"ap-northeast-1",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
DEFAULT_CREDENTIALS = "__default__"
|
|
28
|
+
AWS_LOGIN = "__aws_login__"
|
|
29
|
+
ACCESS_KEYS = "__access_keys__"
|
|
30
|
+
OTHER_REGION = "__other__"
|
|
31
|
+
NO_BOUNDARY = "__no_boundary__"
|
|
32
|
+
NO_TAGS = "__no_tags__"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def sign_in():
|
|
36
|
+
"""Ask which AWS credentials to use and return a boto3 session with them, once AWS
|
|
37
|
+
accepts them. Raises Cancelled when you back out."""
|
|
38
|
+
import boto3
|
|
39
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
40
|
+
|
|
41
|
+
while True:
|
|
42
|
+
entries = [
|
|
43
|
+
(
|
|
44
|
+
DEFAULT_CREDENTIALS,
|
|
45
|
+
"Use your default AWS credentials",
|
|
46
|
+
"Environment variables, AWS_PROFILE, ~/.aws, SSO or an earlier "
|
|
47
|
+
"`aws login`.",
|
|
48
|
+
)
|
|
49
|
+
]
|
|
50
|
+
if shutil.which("aws"):
|
|
51
|
+
entries.append(
|
|
52
|
+
(
|
|
53
|
+
AWS_LOGIN,
|
|
54
|
+
"Sign in with your browser",
|
|
55
|
+
"Runs `aws login` with your AWS console sign-in.",
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
entries.append(
|
|
59
|
+
(
|
|
60
|
+
ACCESS_KEYS,
|
|
61
|
+
"Enter an access key and secret",
|
|
62
|
+
"Used for this run only and not saved.",
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
choice = pick(entries, "Which AWS credentials should provisioning use?")
|
|
66
|
+
if choice == AWS_LOGIN:
|
|
67
|
+
if subprocess.run(["aws", "login"]).returncode != 0:
|
|
68
|
+
ui.fail("`aws login` did not finish.")
|
|
69
|
+
continue
|
|
70
|
+
session = boto3.Session()
|
|
71
|
+
elif choice == ACCESS_KEYS:
|
|
72
|
+
try:
|
|
73
|
+
session = boto3.Session(
|
|
74
|
+
aws_access_key_id=ask("Access key ID: "),
|
|
75
|
+
aws_secret_access_key=ui.secret("Secret access key"),
|
|
76
|
+
)
|
|
77
|
+
except Cancelled:
|
|
78
|
+
continue
|
|
79
|
+
else:
|
|
80
|
+
session = boto3.Session()
|
|
81
|
+
try:
|
|
82
|
+
identity = session.client(
|
|
83
|
+
"sts", region_name=session.region_name or STS_REGION
|
|
84
|
+
).get_caller_identity()
|
|
85
|
+
except (BotoCoreError, ClientError) as e:
|
|
86
|
+
ui.fail(f"AWS did not accept these credentials: {e}")
|
|
87
|
+
continue
|
|
88
|
+
ui.ok(f"Signed in to AWS account {identity['Account']} as {identity['Arn']}")
|
|
89
|
+
return session
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def choose_region(session, title):
|
|
93
|
+
"""Ask for a region under `title`, the session's default first. Raises Cancelled
|
|
94
|
+
when you back out."""
|
|
95
|
+
current = session.region_name
|
|
96
|
+
regions = [current, *(r for r in REGIONS if r != current)] if current else REGIONS
|
|
97
|
+
entries = [
|
|
98
|
+
(region, region, "Your default region" if region == current else None)
|
|
99
|
+
for region in regions
|
|
100
|
+
]
|
|
101
|
+
entries.append((OTHER_REGION, "Another region", None))
|
|
102
|
+
region = pick(entries, title)
|
|
103
|
+
if region == OTHER_REGION:
|
|
104
|
+
region = ask("Region, e.g. ca-central-1: ")
|
|
105
|
+
return region
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def terraform_environment(session, region):
|
|
109
|
+
"""The environment Terraform signs in to AWS with as `session` does. Access keys
|
|
110
|
+
entered for this run are passed as they are; any other credentials Terraform reads
|
|
111
|
+
from where boto3 found them (the environment, AWS_PROFILE, SSO), so it refreshes
|
|
112
|
+
short-lived ones itself during a long run instead of using a copy that expires."""
|
|
113
|
+
aws = {"AWS_REGION": region}
|
|
114
|
+
credentials = session.get_credentials()
|
|
115
|
+
if credentials.method == "explicit":
|
|
116
|
+
frozen = credentials.get_frozen_credentials()
|
|
117
|
+
aws["AWS_ACCESS_KEY_ID"] = frozen.access_key
|
|
118
|
+
aws["AWS_SECRET_ACCESS_KEY"] = frozen.secret_key
|
|
119
|
+
return aws
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def choose_boundary():
|
|
123
|
+
"""Ask for the permissions boundary the account requires on new IAM roles: its
|
|
124
|
+
ARN, or "" for none."""
|
|
125
|
+
choice = pick(
|
|
126
|
+
[
|
|
127
|
+
(NO_BOUNDARY, "No", "The account has no such rule. Most don't."),
|
|
128
|
+
(
|
|
129
|
+
"",
|
|
130
|
+
"Yes, enter the boundary policy",
|
|
131
|
+
"Every IAM role made for the cluster gets it as its upper limit.",
|
|
132
|
+
),
|
|
133
|
+
],
|
|
134
|
+
"Does your AWS account require a permissions boundary on the IAM roles made "
|
|
135
|
+
"for the cluster? Some company accounts do: ask your AWS admin if unsure.",
|
|
136
|
+
)
|
|
137
|
+
if choice == NO_BOUNDARY:
|
|
138
|
+
return ""
|
|
139
|
+
while True:
|
|
140
|
+
arn = ask("Boundary policy ARN, e.g. arn:aws:iam::<account>:policy/<name>: ")
|
|
141
|
+
if arn.startswith("arn:aws") and ":policy/" in arn:
|
|
142
|
+
return arn
|
|
143
|
+
ui.fail("That isn't an IAM policy ARN.")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def choose_tags():
|
|
147
|
+
"""Ask for tags of your own to put on everything made in AWS, as a dict."""
|
|
148
|
+
choice = pick(
|
|
149
|
+
[
|
|
150
|
+
(
|
|
151
|
+
NO_TAGS,
|
|
152
|
+
"No",
|
|
153
|
+
"CanyonOS still tags everything it makes, to find it again.",
|
|
154
|
+
),
|
|
155
|
+
(
|
|
156
|
+
"",
|
|
157
|
+
"Yes, add tags",
|
|
158
|
+
"Put on everything made in AWS. Keys and values are case-sensitive.",
|
|
159
|
+
),
|
|
160
|
+
],
|
|
161
|
+
"Does your AWS account require tags of its own on new resources?",
|
|
162
|
+
)
|
|
163
|
+
if choice == NO_TAGS:
|
|
164
|
+
return {}
|
|
165
|
+
while True:
|
|
166
|
+
text = ask("Tags as key=value, separated by commas, e.g. team=platform: ")
|
|
167
|
+
pairs = [part.strip().split("=", 1) for part in text.split(",") if part.strip()]
|
|
168
|
+
if pairs and all(len(pair) == 2 and pair[0] for pair in pairs):
|
|
169
|
+
return {key.strip(): value.strip() for key, value in pairs}
|
|
170
|
+
ui.fail("Write each tag as key=value.")
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# Service Quotas codes: VPCs per Region, and EC2-VPC Elastic IPs.
|
|
174
|
+
VPC_QUOTA = ("vpc", "L-F678F1CE")
|
|
175
|
+
ELASTIC_IP_QUOTA = ("ec2", "L-0263D0A3")
|
|
176
|
+
# Subnet tags that tell Kubernetes where to put a load balancer; only the key counts.
|
|
177
|
+
PUBLIC_ELB_TAG = "kubernetes.io/role/elb"
|
|
178
|
+
PRIVATE_ELB_TAG = "kubernetes.io/role/internal-elb"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _limit(session, region, service, code):
|
|
182
|
+
"""An account's limit in `region`, or None when it can't be read."""
|
|
183
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
184
|
+
|
|
185
|
+
quotas = session.client("service-quotas", region_name=region)
|
|
186
|
+
try:
|
|
187
|
+
try:
|
|
188
|
+
found = quotas.get_service_quota(ServiceCode=service, QuotaCode=code)
|
|
189
|
+
except quotas.exceptions.NoSuchResourceException:
|
|
190
|
+
# Never changed in this account: AWS's default.
|
|
191
|
+
found = quotas.get_aws_default_service_quota(
|
|
192
|
+
ServiceCode=service, QuotaCode=code
|
|
193
|
+
)
|
|
194
|
+
return int(found["Quota"]["Value"])
|
|
195
|
+
except (BotoCoreError, ClientError, KeyError, ValueError):
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def network_room(session, region, vpcs, elastic_ips):
|
|
200
|
+
"""What would stop `vpcs` new VPCs and `elastic_ips` new Elastic IPs in `region`
|
|
201
|
+
for the account's limits, as lines; [] when they fit, or the limits can't be read."""
|
|
202
|
+
ec2 = session.client("ec2", region_name=region)
|
|
203
|
+
problems = []
|
|
204
|
+
for needed, (service, code), used, what in (
|
|
205
|
+
(vpcs, VPC_QUOTA, lambda: len(ec2.describe_vpcs()["Vpcs"]), "VPCs"),
|
|
206
|
+
(
|
|
207
|
+
elastic_ips,
|
|
208
|
+
ELASTIC_IP_QUOTA,
|
|
209
|
+
lambda: len(ec2.describe_addresses()["Addresses"]),
|
|
210
|
+
"Elastic IPs",
|
|
211
|
+
),
|
|
212
|
+
):
|
|
213
|
+
limit = _limit(session, region, service, code)
|
|
214
|
+
if limit is None:
|
|
215
|
+
continue
|
|
216
|
+
in_use = used()
|
|
217
|
+
if in_use + needed > limit:
|
|
218
|
+
problems.append(
|
|
219
|
+
f"{region} has {in_use} of its {limit} {what}, and this needs {needed} "
|
|
220
|
+
f"more: free {in_use + needed - limit}, use an existing network, or ask "
|
|
221
|
+
"AWS for a higher limit (Service Quotas)."
|
|
222
|
+
)
|
|
223
|
+
return problems
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _name(tags):
|
|
227
|
+
return next((t["Value"] for t in tags or [] if t["Key"] == "Name"), "")
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def networks(session, region):
|
|
231
|
+
"""The VPCs in `region` a cluster could be made in, each with its subnets by zone: a
|
|
232
|
+
subnet is public when its route table sends 0.0.0.0/0 to an internet gateway, and
|
|
233
|
+
private otherwise, `egress` saying how it reaches out (NAT gateway, transit
|
|
234
|
+
gateway, ...) or None when it can't. Returns [{vpc_id, name, cidr, zones: {zone:
|
|
235
|
+
{"public": [subnet], "private": [subnet]}}}], a subnet being {id, name, free_ips,
|
|
236
|
+
egress, elb_tag}."""
|
|
237
|
+
ec2 = session.client("ec2", region_name=region)
|
|
238
|
+
tables = ec2.describe_route_tables()["RouteTables"]
|
|
239
|
+
found = []
|
|
240
|
+
for vpc in ec2.describe_vpcs()["Vpcs"]:
|
|
241
|
+
vpc_id = vpc["VpcId"]
|
|
242
|
+
mine = [t for t in tables if t["VpcId"] == vpc_id]
|
|
243
|
+
main = next(
|
|
244
|
+
(t for t in mine for a in t.get("Associations", []) if a.get("Main")), None
|
|
245
|
+
)
|
|
246
|
+
zones = {}
|
|
247
|
+
subnets = ec2.describe_subnets(
|
|
248
|
+
Filters=[{"Name": "vpc-id", "Values": [vpc_id]}]
|
|
249
|
+
)["Subnets"]
|
|
250
|
+
for subnet in subnets:
|
|
251
|
+
table = next(
|
|
252
|
+
(
|
|
253
|
+
t
|
|
254
|
+
for t in mine
|
|
255
|
+
for a in t.get("Associations", [])
|
|
256
|
+
if a.get("SubnetId") == subnet["SubnetId"]
|
|
257
|
+
),
|
|
258
|
+
main,
|
|
259
|
+
)
|
|
260
|
+
default = next(
|
|
261
|
+
(
|
|
262
|
+
r
|
|
263
|
+
for r in (table or {}).get("Routes", [])
|
|
264
|
+
if r.get("DestinationCidrBlock") == "0.0.0.0/0"
|
|
265
|
+
and r.get("State", "active") == "active"
|
|
266
|
+
),
|
|
267
|
+
{},
|
|
268
|
+
)
|
|
269
|
+
public = default.get("GatewayId", "").startswith("igw-")
|
|
270
|
+
egress = next(
|
|
271
|
+
(
|
|
272
|
+
label
|
|
273
|
+
for key, label in (
|
|
274
|
+
("GatewayId", "internet gateway"),
|
|
275
|
+
("NatGatewayId", "NAT gateway"),
|
|
276
|
+
("TransitGatewayId", "transit gateway"),
|
|
277
|
+
("NetworkInterfaceId", "network appliance"),
|
|
278
|
+
("VpcPeeringConnectionId", "VPC peering"),
|
|
279
|
+
)
|
|
280
|
+
if default.get(key)
|
|
281
|
+
),
|
|
282
|
+
None,
|
|
283
|
+
)
|
|
284
|
+
tags = {t["Key"] for t in subnet.get("Tags", [])}
|
|
285
|
+
entry = {
|
|
286
|
+
"id": subnet["SubnetId"],
|
|
287
|
+
"name": _name(subnet.get("Tags")),
|
|
288
|
+
"free_ips": subnet["AvailableIpAddressCount"],
|
|
289
|
+
"egress": egress,
|
|
290
|
+
"elb_tag": (PUBLIC_ELB_TAG if public else PRIVATE_ELB_TAG) in tags,
|
|
291
|
+
}
|
|
292
|
+
zone = zones.setdefault(
|
|
293
|
+
subnet["AvailabilityZone"], {"public": [], "private": []}
|
|
294
|
+
)
|
|
295
|
+
zone["public" if public else "private"].append(entry)
|
|
296
|
+
found.append(
|
|
297
|
+
{
|
|
298
|
+
"vpc_id": vpc_id,
|
|
299
|
+
"name": _name(vpc.get("Tags")),
|
|
300
|
+
"cidr": vpc["CidrBlock"],
|
|
301
|
+
"zones": dict(sorted(zones.items())),
|
|
302
|
+
}
|
|
303
|
+
)
|
|
304
|
+
return found
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def refused(session, requests):
|
|
308
|
+
"""Which of `requests`, each (action, resource ARN, {condition key: value}), IAM's
|
|
309
|
+
policy simulator says the signed-in identity may not do, as "action on resource"
|
|
310
|
+
lines, without doing any of them. [] when it allows them all, or when the
|
|
311
|
+
simulator can't be asked (no permission to use it): then only trying tells."""
|
|
312
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
313
|
+
|
|
314
|
+
iam = session.client("iam")
|
|
315
|
+
try:
|
|
316
|
+
arn = session.client(
|
|
317
|
+
"sts", region_name=session.region_name or STS_REGION
|
|
318
|
+
).get_caller_identity()["Arn"]
|
|
319
|
+
# An assumed role's session is simulated as its role.
|
|
320
|
+
assumed = re.match(r"arn:[\w-]+:sts::\d+:assumed-role/([^/]+)/", arn)
|
|
321
|
+
if assumed:
|
|
322
|
+
arn = iam.get_role(RoleName=assumed.group(1))["Role"]["Arn"]
|
|
323
|
+
found = []
|
|
324
|
+
for action, resource, context in requests:
|
|
325
|
+
result = iam.simulate_principal_policy(
|
|
326
|
+
PolicySourceArn=arn,
|
|
327
|
+
ActionNames=[action],
|
|
328
|
+
ResourceArns=[resource],
|
|
329
|
+
ContextEntries=[
|
|
330
|
+
{
|
|
331
|
+
"ContextKeyName": key,
|
|
332
|
+
"ContextKeyValues": [value],
|
|
333
|
+
"ContextKeyType": "string",
|
|
334
|
+
}
|
|
335
|
+
for key, value in context.items()
|
|
336
|
+
],
|
|
337
|
+
)["EvaluationResults"][0]
|
|
338
|
+
if result["EvalDecision"] != "allowed":
|
|
339
|
+
found.append(f"{action} on {resource}")
|
|
340
|
+
except (BotoCoreError, ClientError):
|
|
341
|
+
return []
|
|
342
|
+
return found
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def errors():
|
|
346
|
+
"""The errors boto3 raises, for a provisioner to report as a failed step."""
|
|
347
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
348
|
+
|
|
349
|
+
return (BotoCoreError, ClientError)
|