multicloud-cli 0.3.1__tar.gz → 0.4.1__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.
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/PKG-INFO +13 -6
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/README.md +12 -5
- multicloud_cli-0.4.1/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/account.py +3 -6
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/api.py +6 -1
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/auth.py +53 -23
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/catalog.py +2 -2
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/cloud_account.py +250 -32
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/extend.py +2 -2
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/main.py +3 -2
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/node.py +2 -2
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/orgopt.py +9 -1
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/pool.py +85 -7
- multicloud_cli-0.4.1/multicloud_cli/ssh.py +529 -0
- multicloud_cli-0.4.1/multicloud_cli/ssh_cert.py +137 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_account_extend.py +13 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_apply.py +75 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_auth.py +21 -2
- multicloud_cli-0.4.1/tests/test_cloud_account.py +567 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_conventions.py +18 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_pool.py +64 -0
- multicloud_cli-0.4.1/tests/test_ssh.py +794 -0
- multicloud_cli-0.4.1/tests/test_ssh_cert.py +96 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_sso_session.py +67 -2
- multicloud_cli-0.3.1/multicloud_cli/__init__.py +0 -1
- multicloud_cli-0.3.1/multicloud_cli/ssh.py +0 -260
- multicloud_cli-0.3.1/tests/test_cloud_account.py +0 -294
- multicloud_cli-0.3.1/tests/test_ssh.py +0 -353
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/.gitignore +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/LICENSE +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/net.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/pyproject.toml +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/__init__.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/conftest.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/helpers.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_net.py +0 -0
- {multicloud_cli-0.3.1 → multicloud_cli-0.4.1}/tests/test_sso.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: multicloud-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: mctl: the Multicloud command line: sign in, connect your cloud account, run pools
|
|
5
5
|
Project-URL: Homepage, https://multicloud.io
|
|
6
6
|
Author-email: Multicloud Team <info@multicloud.io>
|
|
@@ -73,7 +73,7 @@ mctl cloud-account verify 7 --wait
|
|
|
73
73
|
| Command | What it does |
|
|
74
74
|
|---|---|
|
|
75
75
|
| `mctl auth login` | Sign in with your browser (SSO). `--no-browser` prints a code to enter on another device (SSH, containers). `--api-key` stores an API key instead (hidden prompt or `--key-stdin`). |
|
|
76
|
-
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the session
|
|
76
|
+
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the SSO session (the stored API key stays; `logout --api-key` deletes it). |
|
|
77
77
|
| `mctl cloud-account create` | Declare an AWS account and write `multicloud.tf`. |
|
|
78
78
|
| `mctl cloud-account apply <id>` | `init`, `plan`, a question (`--yes` skips it, `--plan-only` stops after the plan), then `apply` with a fresh connect code and a wait for the check. |
|
|
79
79
|
| `mctl cloud-account token <id>` | A new one-time connect code, for a manual `terraform apply`. |
|
|
@@ -82,7 +82,8 @@ mctl cloud-account verify 7 --wait
|
|
|
82
82
|
| `mctl overview` / `billing` | Setup checklist, alerts and pool counts; payment gate status. Read access or a member sign-in. |
|
|
83
83
|
| `mctl extend create NAME` | Make an Extend pool. Owner sign-in only. |
|
|
84
84
|
| `mctl peering create\|list\|show\|revoke POOL ...` | Manage the peerings of an Extend pool. Owner sign-in only. |
|
|
85
|
-
| `mctl ssh allow\|list\|revoke`, `mctl node list`, `mctl ssh NODE [-y] [-- ssh args]` | Operators
|
|
85
|
+
| `mctl ssh allow\|list\|revoke`, `mctl node list`, `mctl ssh NODE [-y] [-- ssh args]` | Operators (role `multicloud-admins`): open tcp/22 on a node for your own IPv4 address, list the nodes and the grants, connect. Organization owners: `mctl ssh NODE` logs in to a node of your pool with a 30-minute certificate. Details: `mctl ssh --help`. |
|
|
86
|
+
| `mctl ssh support allow --pool POOL [--for 4h]`, `support list`, `support revoke ID` | Organization owner: let Multicloud support log in to one pool for up to 7 days, see the consents and the certificates issued, end a consent. A support certificate already issued stays valid up to 30 minutes after a revoke. |
|
|
86
87
|
|
|
87
88
|
The connect code reaches Terraform only through the environment of the `apply` process.
|
|
88
89
|
`mctl` never prints a key or a token, and only `mctl cloud-account token` prints a connect code.
|
|
@@ -110,11 +111,15 @@ access token by itself. A session ends after at most 10 hours; then run `mctl au
|
|
|
110
111
|
|
|
111
112
|
- **Organization.** The sign-in holds the organizations you belong to. With one, no `--org` is needed. With
|
|
112
113
|
several, name one: `--org <org-id>` or `MULTICLOUD_ORG`.
|
|
113
|
-
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key.
|
|
114
|
+
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key. The catalog
|
|
115
|
+
takes a stored key of the named organization first. To use a stored key for every command where you are signed in,
|
|
116
|
+
run `mctl auth logout` (it signs you out in the browser too; the key stays); `mctl auth login --api-key` warns about this.
|
|
114
117
|
- **Roles.** Pool reads need membership. Everything that changes a pool, and every `cloud-account` command, needs the
|
|
115
118
|
owner role of the organization (an API key with the matching scope works too).
|
|
116
119
|
- **Logout.** `mctl auth logout` ends the session at Keycloak and deletes the local copy. Because `mctl` shares
|
|
117
|
-
your Keycloak browser session, it signs you out of Keycloak in your browser too.
|
|
120
|
+
your Keycloak browser session, it signs you out of Keycloak in your browser too. The stored API key stays, and the
|
|
121
|
+
output says where. To delete the key, run `mctl auth logout --api-key --org <org-id>` (add `--sso` to do both). A key
|
|
122
|
+
cannot be shown again, so after that you create a new key in the console.
|
|
118
123
|
- **Settings.** `MULTICLOUD_ISSUER_URL` (or `issuer` in `~/.config/multicloud/cli.json`) overrides the Keycloak
|
|
119
124
|
realm URL `https://auth.multicloud.io/realms/multicloud`. Like the API URL it must be `https://`.
|
|
120
125
|
- **Other environments.** The defaults point to production (`auth.multicloud.io`, `api.multicloud.io`). For
|
|
@@ -138,6 +143,8 @@ mctl pool classes # the machine sizes you can a
|
|
|
138
143
|
mctl pool create ci --github-org my-gh-org --max-cost-per-hour 2 --classes cpu-4 \
|
|
139
144
|
--clouds '[{"type":"AWS","regions":["us-east-1"]}]'
|
|
140
145
|
mctl pool list
|
|
146
|
+
mctl pool update ci --max-servers 20 --set idle_reap_minutes=5 --set min_vcpus=8 # CI pool
|
|
147
|
+
mctl pool update gpu --set min_accelerator_count=2 --set grant.cpu=16 --reset max_risk # Extend pool
|
|
141
148
|
mctl pool hibernate ci # pause: no machines, no cost, the name stays
|
|
142
149
|
mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6 pool deleted, 1 other error
|
|
143
150
|
```
|
|
@@ -145,7 +152,7 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
145
152
|
| Command | What it does |
|
|
146
153
|
|---|---|
|
|
147
154
|
| `mctl pool create <name>` | Make a pool. Use `--from-file pool.json` for the full request, or the flags `--github-org`, `--clouds`, `--classes`, `--max-cost-per-hour`, `--spot-policy`, `--cpu-units-requests`, `--image-by-class`, `--egress-by-class`, `--class-headroom`. A repeated run with the same `--idempotency-key` makes one pool. Put cloud keys in the file, not on the command line. |
|
|
148
|
-
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--classes`, `--spot-policy`, `--cpu-units-requests` or `--
|
|
155
|
+
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names` and `excluded_accelerator_names` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. |
|
|
149
156
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
150
157
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
151
158
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
@@ -42,7 +42,7 @@ mctl cloud-account verify 7 --wait
|
|
|
42
42
|
| Command | What it does |
|
|
43
43
|
|---|---|
|
|
44
44
|
| `mctl auth login` | Sign in with your browser (SSO). `--no-browser` prints a code to enter on another device (SSH, containers). `--api-key` stores an API key instead (hidden prompt or `--key-stdin`). |
|
|
45
|
-
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the session
|
|
45
|
+
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the SSO session (the stored API key stays; `logout --api-key` deletes it). |
|
|
46
46
|
| `mctl cloud-account create` | Declare an AWS account and write `multicloud.tf`. |
|
|
47
47
|
| `mctl cloud-account apply <id>` | `init`, `plan`, a question (`--yes` skips it, `--plan-only` stops after the plan), then `apply` with a fresh connect code and a wait for the check. |
|
|
48
48
|
| `mctl cloud-account token <id>` | A new one-time connect code, for a manual `terraform apply`. |
|
|
@@ -51,7 +51,8 @@ mctl cloud-account verify 7 --wait
|
|
|
51
51
|
| `mctl overview` / `billing` | Setup checklist, alerts and pool counts; payment gate status. Read access or a member sign-in. |
|
|
52
52
|
| `mctl extend create NAME` | Make an Extend pool. Owner sign-in only. |
|
|
53
53
|
| `mctl peering create\|list\|show\|revoke POOL ...` | Manage the peerings of an Extend pool. Owner sign-in only. |
|
|
54
|
-
| `mctl ssh allow\|list\|revoke`, `mctl node list`, `mctl ssh NODE [-y] [-- ssh args]` | Operators
|
|
54
|
+
| `mctl ssh allow\|list\|revoke`, `mctl node list`, `mctl ssh NODE [-y] [-- ssh args]` | Operators (role `multicloud-admins`): open tcp/22 on a node for your own IPv4 address, list the nodes and the grants, connect. Organization owners: `mctl ssh NODE` logs in to a node of your pool with a 30-minute certificate. Details: `mctl ssh --help`. |
|
|
55
|
+
| `mctl ssh support allow --pool POOL [--for 4h]`, `support list`, `support revoke ID` | Organization owner: let Multicloud support log in to one pool for up to 7 days, see the consents and the certificates issued, end a consent. A support certificate already issued stays valid up to 30 minutes after a revoke. |
|
|
55
56
|
|
|
56
57
|
The connect code reaches Terraform only through the environment of the `apply` process.
|
|
57
58
|
`mctl` never prints a key or a token, and only `mctl cloud-account token` prints a connect code.
|
|
@@ -79,11 +80,15 @@ access token by itself. A session ends after at most 10 hours; then run `mctl au
|
|
|
79
80
|
|
|
80
81
|
- **Organization.** The sign-in holds the organizations you belong to. With one, no `--org` is needed. With
|
|
81
82
|
several, name one: `--org <org-id>` or `MULTICLOUD_ORG`.
|
|
82
|
-
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key.
|
|
83
|
+
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key. The catalog
|
|
84
|
+
takes a stored key of the named organization first. To use a stored key for every command where you are signed in,
|
|
85
|
+
run `mctl auth logout` (it signs you out in the browser too; the key stays); `mctl auth login --api-key` warns about this.
|
|
83
86
|
- **Roles.** Pool reads need membership. Everything that changes a pool, and every `cloud-account` command, needs the
|
|
84
87
|
owner role of the organization (an API key with the matching scope works too).
|
|
85
88
|
- **Logout.** `mctl auth logout` ends the session at Keycloak and deletes the local copy. Because `mctl` shares
|
|
86
|
-
your Keycloak browser session, it signs you out of Keycloak in your browser too.
|
|
89
|
+
your Keycloak browser session, it signs you out of Keycloak in your browser too. The stored API key stays, and the
|
|
90
|
+
output says where. To delete the key, run `mctl auth logout --api-key --org <org-id>` (add `--sso` to do both). A key
|
|
91
|
+
cannot be shown again, so after that you create a new key in the console.
|
|
87
92
|
- **Settings.** `MULTICLOUD_ISSUER_URL` (or `issuer` in `~/.config/multicloud/cli.json`) overrides the Keycloak
|
|
88
93
|
realm URL `https://auth.multicloud.io/realms/multicloud`. Like the API URL it must be `https://`.
|
|
89
94
|
- **Other environments.** The defaults point to production (`auth.multicloud.io`, `api.multicloud.io`). For
|
|
@@ -107,6 +112,8 @@ mctl pool classes # the machine sizes you can a
|
|
|
107
112
|
mctl pool create ci --github-org my-gh-org --max-cost-per-hour 2 --classes cpu-4 \
|
|
108
113
|
--clouds '[{"type":"AWS","regions":["us-east-1"]}]'
|
|
109
114
|
mctl pool list
|
|
115
|
+
mctl pool update ci --max-servers 20 --set idle_reap_minutes=5 --set min_vcpus=8 # CI pool
|
|
116
|
+
mctl pool update gpu --set min_accelerator_count=2 --set grant.cpu=16 --reset max_risk # Extend pool
|
|
110
117
|
mctl pool hibernate ci # pause: no machines, no cost, the name stays
|
|
111
118
|
mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6 pool deleted, 1 other error
|
|
112
119
|
```
|
|
@@ -114,7 +121,7 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
114
121
|
| Command | What it does |
|
|
115
122
|
|---|---|
|
|
116
123
|
| `mctl pool create <name>` | Make a pool. Use `--from-file pool.json` for the full request, or the flags `--github-org`, `--clouds`, `--classes`, `--max-cost-per-hour`, `--spot-policy`, `--cpu-units-requests`, `--image-by-class`, `--egress-by-class`, `--class-headroom`. A repeated run with the same `--idempotency-key` makes one pool. Put cloud keys in the file, not on the command line. |
|
|
117
|
-
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--classes`, `--spot-policy`, `--cpu-units-requests` or `--
|
|
124
|
+
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names` and `excluded_accelerator_names` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. |
|
|
118
125
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
119
126
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
120
127
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.1"
|
|
@@ -9,6 +9,7 @@ from typing import Any, Dict
|
|
|
9
9
|
import click
|
|
10
10
|
|
|
11
11
|
from . import api, exitcodes
|
|
12
|
+
from .orgopt import org_option
|
|
12
13
|
from .output import dump as _dump, json_option, run
|
|
13
14
|
|
|
14
15
|
READ = "org:read"
|
|
@@ -25,10 +26,6 @@ def _get(org, path: str) -> Dict[str, Any]:
|
|
|
25
26
|
raise AccountError(str(ex), ex.exit_code)
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
def _org_option(f):
|
|
29
|
-
return click.option("--org", default=None, help="Organization ID, the short name such as acme (default: MULTICLOUD_ORG)")(f)
|
|
30
|
-
|
|
31
|
-
|
|
32
29
|
def _checklist_line(item: Dict[str, Any]) -> str:
|
|
33
30
|
state = item.get("state")
|
|
34
31
|
notes = [n for n in ((state if state not in ("done", "open", None) else None),
|
|
@@ -65,7 +62,7 @@ def readable_billing(data: Dict[str, Any]) -> str:
|
|
|
65
62
|
|
|
66
63
|
|
|
67
64
|
@click.command()
|
|
68
|
-
@
|
|
65
|
+
@org_option()
|
|
69
66
|
@json_option
|
|
70
67
|
def overview(org, as_json):
|
|
71
68
|
"""Show the setup checklist, alerts and pool counts of the organization."""
|
|
@@ -76,7 +73,7 @@ def overview(org, as_json):
|
|
|
76
73
|
|
|
77
74
|
|
|
78
75
|
@click.command()
|
|
79
|
-
@
|
|
76
|
+
@org_option()
|
|
80
77
|
@json_option
|
|
81
78
|
def billing(org, as_json):
|
|
82
79
|
"""Show the payment gate of the organization and its dates."""
|
|
@@ -14,6 +14,8 @@ import requests
|
|
|
14
14
|
from . import auth, config, exitcodes, net, sso
|
|
15
15
|
|
|
16
16
|
TIMEOUT_S = 30
|
|
17
|
+
# The name of each scope in the console key form (multicloud.io, Account, API keys).
|
|
18
|
+
CONSOLE_SCOPE_NAMES = {"org:read": "Pools: Read", "org:write": "Pools: Manage", "org:admin": "Pools: Full"}
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
class ApiError(Exception):
|
|
@@ -153,7 +155,10 @@ def call(method: str, org: Optional[str], path: str = "", *, body: Optional[Dict
|
|
|
153
155
|
text = _detail_text(data) or f"HTTP {r.status_code}"
|
|
154
156
|
# A 401 is a bad or expired credential, not a missing scope.
|
|
155
157
|
if r.status_code == 403 and scope and not use_sso:
|
|
156
|
-
text += f" (HTTP {r.status_code}. The API key may lack the '{scope}' scope.
|
|
158
|
+
text += f" (HTTP {r.status_code}. The API key may lack the '{scope}' scope."
|
|
159
|
+
if scope in CONSOLE_SCOPE_NAMES:
|
|
160
|
+
text += f" The console key form calls it '{CONSOLE_SCOPE_NAMES[scope]}'."
|
|
161
|
+
text += ")"
|
|
157
162
|
raise ApiError(text, r.status_code)
|
|
158
163
|
data = dict(data) if isinstance(data, dict) else {"body": data}
|
|
159
164
|
data["_status"] = r.status_code
|
|
@@ -17,6 +17,7 @@ import click
|
|
|
17
17
|
import requests
|
|
18
18
|
|
|
19
19
|
from . import config, exitcodes, net, sso
|
|
20
|
+
from .orgopt import ORG_ID_HELP, org_option
|
|
20
21
|
|
|
21
22
|
try:
|
|
22
23
|
import fcntl
|
|
@@ -31,6 +32,8 @@ SERVICE = "multicloud-api-key"
|
|
|
31
32
|
SSO_SERVICE = "multicloud-sso"
|
|
32
33
|
TIMEOUT_S = 30
|
|
33
34
|
REFRESH_SKEW_S = 60
|
|
35
|
+
LOGIN_ORG_HELP = f"{ORG_ID_HELP} (default: MULTICLOUD_ORG, saved, or the one in your sign-in)"
|
|
36
|
+
SAVED_ORG_HELP = f"{ORG_ID_HELP} (default: MULTICLOUD_ORG or saved)"
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
class AuthError(Exception):
|
|
@@ -174,6 +177,11 @@ def delete_key(org: str) -> list:
|
|
|
174
177
|
return _delete_secret(SERVICE, account(org))
|
|
175
178
|
|
|
176
179
|
|
|
180
|
+
def stored_key_source(org: str) -> Optional[str]:
|
|
181
|
+
"""Where a stored key for the organization is ('OS keyring' or 'file <path>'), or None. Ignores the environment."""
|
|
182
|
+
return _load_secret(SERVICE, account(org))[1]
|
|
183
|
+
|
|
184
|
+
|
|
177
185
|
def sso_account(issuer: str, part: str) -> str:
|
|
178
186
|
return f"{issuer}#{part}"
|
|
179
187
|
|
|
@@ -266,7 +274,7 @@ def fresh_access_token(issuer: str, rejected: Optional[str] = None) -> str:
|
|
|
266
274
|
new = sso.refresh(issuer, tokens.refresh)
|
|
267
275
|
except sso.SsoError as ex:
|
|
268
276
|
if ex.code == "invalid_grant":
|
|
269
|
-
raise SessionEnded("Your session ended. Run: mctl auth login (or mctl auth logout
|
|
277
|
+
raise SessionEnded("Your session ended. Run: mctl auth login (or mctl auth logout to use a stored API key)")
|
|
270
278
|
raise AuthError(str(ex))
|
|
271
279
|
try:
|
|
272
280
|
store_sso(issuer, new)
|
|
@@ -311,7 +319,7 @@ def auth():
|
|
|
311
319
|
|
|
312
320
|
|
|
313
321
|
@auth.command()
|
|
314
|
-
@
|
|
322
|
+
@org_option(LOGIN_ORG_HELP)
|
|
315
323
|
@click.option("--api-url", default=None, help="API URL (default: MULTICLOUD_API_URL or saved)")
|
|
316
324
|
@click.option("--issuer-url", default=None, help="Keycloak realm URL (default: MULTICLOUD_ISSUER_URL, saved, or auth.multicloud.io)")
|
|
317
325
|
@click.option("--no-browser", is_flag=True, help="Sign in with a code on another device (for SSH and containers)")
|
|
@@ -326,7 +334,7 @@ def login(org, api_url, issuer_url, no_browser, use_key, key_stdin):
|
|
|
326
334
|
click.echo(f"Error: {ex} Nothing stored.", err=True)
|
|
327
335
|
sys.exit(1)
|
|
328
336
|
if use_key or key_stdin:
|
|
329
|
-
_login_key(org, url, key_stdin)
|
|
337
|
+
_login_key(org, url, key_stdin, issuer)
|
|
330
338
|
return
|
|
331
339
|
_check_hosts(url, issuer)
|
|
332
340
|
try:
|
|
@@ -382,7 +390,7 @@ def _key_exit_code(error: str) -> int:
|
|
|
382
390
|
return exitcodes.for_status(int(m.group(1))) if m else exitcodes.ERROR
|
|
383
391
|
|
|
384
392
|
|
|
385
|
-
def _login_key(org, url, key_stdin):
|
|
393
|
+
def _login_key(org, url, key_stdin, issuer):
|
|
386
394
|
org = need_org(org)
|
|
387
395
|
host = urlparse(url).hostname or ""
|
|
388
396
|
if host not in ("localhost", "127.0.0.1", "::1") and host != "multicloud.io" \
|
|
@@ -407,6 +415,17 @@ def _login_key(org, url, key_stdin):
|
|
|
407
415
|
sys.exit(1)
|
|
408
416
|
config.save(org=org, api_url=url)
|
|
409
417
|
click.echo(f"Stored the API key for {org} in {where}. It can read the cloud accounts of {org}.")
|
|
418
|
+
try:
|
|
419
|
+
signed_in = load_sso(issuer) is not None
|
|
420
|
+
except AuthError:
|
|
421
|
+
signed_in = False
|
|
422
|
+
if signed_in:
|
|
423
|
+
# The order is MULTICLOUD_API_KEY, the SSO sign-in, the stored key; the catalog takes the stored key first
|
|
424
|
+
# (api.call). An ended session still wins until it is removed. Say so where it surprises.
|
|
425
|
+
click.echo("Warning: an SSO sign-in is stored. mctl uses it before this key, except for the catalog. "
|
|
426
|
+
"To use this key for every command, run: mctl auth logout (this also signs you out in "
|
|
427
|
+
"your browser). A script or CI job can set MULTICLOUD_API_KEY instead; it wins over the sign-in.",
|
|
428
|
+
err=True)
|
|
410
429
|
|
|
411
430
|
|
|
412
431
|
def _expiry_text(access: str) -> str:
|
|
@@ -419,7 +438,7 @@ def _expiry_text(access: str) -> str:
|
|
|
419
438
|
|
|
420
439
|
|
|
421
440
|
@auth.command()
|
|
422
|
-
@
|
|
441
|
+
@org_option(SAVED_ORG_HELP)
|
|
423
442
|
@click.option("--json", "as_json", is_flag=True, help="Print method, api_url, org, orgs, expires and works as JSON")
|
|
424
443
|
def status(org, as_json):
|
|
425
444
|
"""Show how you are signed in and check that it works."""
|
|
@@ -471,7 +490,7 @@ def status(org, as_json):
|
|
|
471
490
|
info["expires"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(exp)) if exp else None
|
|
472
491
|
if tokens and not env_key:
|
|
473
492
|
if stored:
|
|
474
|
-
say(f"Stored API key for {slug}: {source} (
|
|
493
|
+
say(f"Stored API key for {slug}: {source} (used only for the catalog while an SSO sign-in exists)")
|
|
475
494
|
orgs = sso.orgs_in_token(tokens.access)
|
|
476
495
|
explicit = config.org_is_explicit(org)
|
|
477
496
|
if len(orgs) > 1 and not explicit and slug not in orgs:
|
|
@@ -505,14 +524,17 @@ def status(org, as_json):
|
|
|
505
524
|
|
|
506
525
|
|
|
507
526
|
@auth.command()
|
|
508
|
-
@
|
|
509
|
-
@click.option("--sso", "
|
|
510
|
-
@click.option("--api-key", "
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
527
|
+
@org_option(SAVED_ORG_HELP)
|
|
528
|
+
@click.option("--sso", "do_sso", is_flag=True, help="End the SSO session (the default)")
|
|
529
|
+
@click.option("--api-key", "do_key", is_flag=True,
|
|
530
|
+
help="Delete the stored API key of the organization. Add --sso to end the SSO session too")
|
|
531
|
+
def logout(org, do_sso, do_key):
|
|
532
|
+
"""End the SSO session at Keycloak and remove it. The stored API key stays unless you add --api-key.
|
|
533
|
+
|
|
534
|
+
The CLI shares the Keycloak browser session, so this signs you out of Keycloak in your browser too.
|
|
535
|
+
An API key cannot be shown again: after --api-key, create a new key in the console to use one again."""
|
|
536
|
+
if not do_key:
|
|
537
|
+
do_sso = True
|
|
516
538
|
try:
|
|
517
539
|
if do_sso:
|
|
518
540
|
try:
|
|
@@ -529,19 +551,27 @@ def logout(org, only_sso, only_key):
|
|
|
529
551
|
click.echo(f"Warning: could not end the session at the sign-in server ({ex}). "
|
|
530
552
|
"It stays valid until it expires.", err=True)
|
|
531
553
|
click.echo(f"Removed the SSO sign-in from {', '.join(delete_sso(issuer)) or 'nowhere'}.")
|
|
532
|
-
|
|
554
|
+
else:
|
|
533
555
|
click.echo("No SSO sign-in stored.")
|
|
556
|
+
slug = config.get_org(org)
|
|
534
557
|
if do_key:
|
|
535
|
-
|
|
536
|
-
if slug:
|
|
537
|
-
removed = delete_key(slug)
|
|
538
|
-
if removed:
|
|
539
|
-
click.echo(f"Removed the API key for {slug} from {', '.join(removed)}.")
|
|
540
|
-
elif only_key:
|
|
541
|
-
click.echo(f"No stored API key for {slug}.")
|
|
542
|
-
elif only_key:
|
|
558
|
+
if not slug:
|
|
543
559
|
click.echo("Error: name the organization with --org or MULTICLOUD_ORG.", err=True)
|
|
544
560
|
sys.exit(1)
|
|
561
|
+
removed = delete_key(slug)
|
|
562
|
+
if removed:
|
|
563
|
+
click.echo(f"Removed the API key for {slug} from {', '.join(removed)}.")
|
|
564
|
+
else:
|
|
565
|
+
click.echo(f"No stored API key for {slug}.")
|
|
566
|
+
elif slug:
|
|
567
|
+
try:
|
|
568
|
+
where = stored_key_source(slug)
|
|
569
|
+
except AuthError as ex:
|
|
570
|
+
click.echo(f"Warning: could not check the stored API key for {slug}: {ex}", err=True)
|
|
571
|
+
where = None
|
|
572
|
+
if where:
|
|
573
|
+
click.echo(f"The API key for {slug} stays stored in the {where}. "
|
|
574
|
+
f"To delete it, run: mctl auth logout --api-key --org {slug}")
|
|
545
575
|
except AuthError as ex:
|
|
546
576
|
click.echo(f"Error: {ex}", err=True)
|
|
547
577
|
sys.exit(1)
|
|
@@ -12,7 +12,7 @@ from typing import Any, Dict, List, Optional
|
|
|
12
12
|
import click
|
|
13
13
|
|
|
14
14
|
from . import api, exitcodes
|
|
15
|
-
from .orgopt import org_group
|
|
15
|
+
from .orgopt import org_group, org_option
|
|
16
16
|
from .output import dump as _dump, echo as _echo, json_option, no_headers_option, plain as _plain, quiet_option, run, table as _table
|
|
17
17
|
|
|
18
18
|
SCOPE = "catalog"
|
|
@@ -67,7 +67,7 @@ def _call(org, path: str, params: Optional[Dict[str, Any]] = None) -> Dict[str,
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
@click.group(cls=org_group("catalog_org"))
|
|
70
|
-
@
|
|
70
|
+
@org_option()
|
|
71
71
|
@click.pass_context
|
|
72
72
|
def catalog(ctx, org):
|
|
73
73
|
"""Find servers and prices (sign in first: mctl auth login)."""
|