maximem-synap-cli 0.3.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- maximem_synap_cli-0.3.5.dist-info/METADATA +178 -0
- maximem_synap_cli-0.3.5.dist-info/RECORD +30 -0
- maximem_synap_cli-0.3.5.dist-info/WHEEL +5 -0
- maximem_synap_cli-0.3.5.dist-info/entry_points.txt +3 -0
- maximem_synap_cli-0.3.5.dist-info/top_level.txt +1 -0
- synap/cli/README.md +157 -0
- synap/cli/__init__.py +11 -0
- synap/cli/__main__.py +157 -0
- synap/cli/action_rows.py +36 -0
- synap/cli/api.py +402 -0
- synap/cli/app.py +362 -0
- synap/cli/commands/__init__.py +1 -0
- synap/cli/commands/api_keys.py +396 -0
- synap/cli/commands/auth.py +1277 -0
- synap/cli/commands/billing.py +342 -0
- synap/cli/commands/client.py +92 -0
- synap/cli/commands/config_cmd.py +56 -0
- synap/cli/commands/instances.py +595 -0
- synap/cli/commands/memories.py +148 -0
- synap/cli/commands/onboard.py +220 -0
- synap/cli/commands/privacy.py +677 -0
- synap/cli/commands/requests.py +181 -0
- synap/cli/commands/scoping.py +471 -0
- synap/cli/commands/skill.py +100 -0
- synap/cli/commands/visibility.py +302 -0
- synap/cli/config.py +250 -0
- synap/cli/envfile.py +232 -0
- synap/cli/interactive.py +94 -0
- synap/cli/render.py +169 -0
- synap/cli/validate.py +67 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""`maximem-synap api-keys ...` — manage runtime/SDK API keys."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from synap.cli import envfile, interactive, render
|
|
13
|
+
from synap.cli.api import EXIT_CONFLICT, EXIT_GENERIC, CliError
|
|
14
|
+
from synap.cli.config import runtime_env_values
|
|
15
|
+
|
|
16
|
+
app = typer.Typer(no_args_is_help=True)
|
|
17
|
+
|
|
18
|
+
_LIST_COLUMNS = [
|
|
19
|
+
("credential_id", "ID"),
|
|
20
|
+
("label", "LABEL"),
|
|
21
|
+
("instance_id", "INSTANCE"),
|
|
22
|
+
("masked_key", "KEY"),
|
|
23
|
+
("created_at", "CREATED"),
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.command(name="list")
|
|
28
|
+
def list_keys(
|
|
29
|
+
ctx: typer.Context,
|
|
30
|
+
instance_id: Optional[str] = typer.Option(
|
|
31
|
+
None, "--instance", "-i",
|
|
32
|
+
help="Instance to list keys for (omit to list all of the client's keys).",
|
|
33
|
+
),
|
|
34
|
+
) -> None:
|
|
35
|
+
"""List API keys (metadata only — never the secret).
|
|
36
|
+
|
|
37
|
+
With `--instance`, lists that instance's keys; without it, lists every key in
|
|
38
|
+
your client (all instances plus client-scoped CLI keys).
|
|
39
|
+
"""
|
|
40
|
+
cc = ctx.obj
|
|
41
|
+
params = {"instance_id": instance_id} if instance_id else {}
|
|
42
|
+
resp = cc.client().get("/api_keys", params=params)
|
|
43
|
+
render.print_table(resp.get("data", []), _LIST_COLUMNS, empty="No API keys.")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.command()
|
|
47
|
+
def create(
|
|
48
|
+
ctx: typer.Context,
|
|
49
|
+
instance_id: str = typer.Option(..., "--instance", "-i", help="Instance the key is for."),
|
|
50
|
+
label: str = typer.Option("default", "--label", "-l"),
|
|
51
|
+
allow_customer_delete: bool = typer.Option(
|
|
52
|
+
False, "--allow-customer-delete",
|
|
53
|
+
help="Add the delete:data scope, so the key can delete a whole customer's data "
|
|
54
|
+
"(data.delete with scope=\"customer\"). Off by default. Your own key must hold "
|
|
55
|
+
"delete:data (owner and admin keys do).",
|
|
56
|
+
),
|
|
57
|
+
write_env_flag: bool = typer.Option(
|
|
58
|
+
False, "--write-env",
|
|
59
|
+
help="Write the key into an env file and print only a masked key. Variables written: "
|
|
60
|
+
"SYNAP_API_KEY and SYNAP_INSTANCE_ID always (or the _<NAME> forms with --env-suffix); for non-production environments also "
|
|
61
|
+
"SYNAP_BASE_URL, SYNAP_GRPC_HOST, SYNAP_GRPC_PORT and SYNAP_GRPC_USE_TLS. An "
|
|
62
|
+
"existing line for a variable (including an `export ` form or a quoted value) is "
|
|
63
|
+
"replaced in place and a variable never appears twice; other lines are kept. "
|
|
64
|
+
"`--write-env PATH` picks the file (default ./.env). The file is created 0600 and "
|
|
65
|
+
"added to .gitignore.",
|
|
66
|
+
),
|
|
67
|
+
env_file: Optional[str] = typer.Option(
|
|
68
|
+
None, "--env-file", help="Env file used by --write-env (same as `--write-env PATH`).",
|
|
69
|
+
),
|
|
70
|
+
env_suffix: Optional[str] = typer.Option(
|
|
71
|
+
None, "--env-suffix", metavar="NAME",
|
|
72
|
+
help="With --write-env: name the variables per instance, SYNAP_API_KEY_<NAME> and "
|
|
73
|
+
"SYNAP_INSTANCE_ID_<NAME> (NAME: letters, digits, underscore; uppercased), so one "
|
|
74
|
+
"project can hold keys for several instances. Other instances' lines are never "
|
|
75
|
+
"touched. Example: --env-suffix SUPPORT. Host variables keep their plain names.",
|
|
76
|
+
),
|
|
77
|
+
force: bool = typer.Option(
|
|
78
|
+
False, "--force",
|
|
79
|
+
help="With --write-env and no --env-suffix: replace the SYNAP_API_KEY / SYNAP_INSTANCE_ID "
|
|
80
|
+
"already in the file even if they belong to a different instance.",
|
|
81
|
+
),
|
|
82
|
+
) -> None:
|
|
83
|
+
"""Mint a new runtime API key. The secret is shown exactly once.
|
|
84
|
+
|
|
85
|
+
With --write-env the secret goes into the env file and is never printed.
|
|
86
|
+
"""
|
|
87
|
+
cc = ctx.obj
|
|
88
|
+
suffix = _normalize_suffix(env_suffix, write_env_flag or env_file is not None)
|
|
89
|
+
env_path = _prepare_env_path(write_env_flag, env_file)
|
|
90
|
+
if env_path is not None:
|
|
91
|
+
_guard_env_conflict(env_path, instance_id, suffix, force)
|
|
92
|
+
body = {"instance_id": instance_id, "label": label}
|
|
93
|
+
if allow_customer_delete:
|
|
94
|
+
body["allow_customer_delete"] = True
|
|
95
|
+
resp = cc.client().post("/api_keys", json=body)
|
|
96
|
+
if env_path is not None:
|
|
97
|
+
_store_in_env(cc, resp, env_path, instance_id, suffix=suffix)
|
|
98
|
+
return
|
|
99
|
+
if render.is_json():
|
|
100
|
+
render.print_json(resp)
|
|
101
|
+
return
|
|
102
|
+
render.success("API key created.")
|
|
103
|
+
render.console.print()
|
|
104
|
+
render.console.print(f" [bold yellow]{resp['api_key']}[/bold yellow]")
|
|
105
|
+
render.console.print()
|
|
106
|
+
render.warn("Copy it now — it will not be shown again.")
|
|
107
|
+
render.print_detail({
|
|
108
|
+
"credential_id": resp.get("credential_id"),
|
|
109
|
+
"label": resp.get("label"),
|
|
110
|
+
"scopes": ", ".join(resp.get("scopes") or []) or None,
|
|
111
|
+
"created_at": resp.get("created_at"),
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _prepare_env_path(write_env_flag: bool, env_file: Optional[str]) -> Optional[Path]:
|
|
116
|
+
"""Validate the --write-env/--env-file target BEFORE a key is minted."""
|
|
117
|
+
if not (write_env_flag or env_file is not None):
|
|
118
|
+
return None
|
|
119
|
+
write_env = env_file or ".env"
|
|
120
|
+
env_path = Path(write_env)
|
|
121
|
+
if env_path.is_dir():
|
|
122
|
+
raise CliError(
|
|
123
|
+
f"--write-env: '{write_env}' is a directory.",
|
|
124
|
+
code="invalid_argument", exit_code=2,
|
|
125
|
+
hint="Pass a file path such as .env.",
|
|
126
|
+
)
|
|
127
|
+
# The key is shown once, so a failed write afterwards would lose it.
|
|
128
|
+
probe = env_path.resolve()
|
|
129
|
+
target = probe if probe.exists() else _nearest_existing_dir(probe)
|
|
130
|
+
if probe.exists():
|
|
131
|
+
try:
|
|
132
|
+
probe.read_bytes()
|
|
133
|
+
except OSError as e:
|
|
134
|
+
raise CliError(
|
|
135
|
+
f"--write-env: cannot read '{write_env}' ({e.strerror or e}).",
|
|
136
|
+
code="env_not_writable", exit_code=EXIT_GENERIC,
|
|
137
|
+
hint="Check the path and permissions; no key was minted.",
|
|
138
|
+
)
|
|
139
|
+
if not os.access(target, os.W_OK):
|
|
140
|
+
raise CliError(
|
|
141
|
+
f"--write-env: cannot write to '{write_env}'.",
|
|
142
|
+
code="env_not_writable", exit_code=EXIT_GENERIC,
|
|
143
|
+
hint="Check the path and permissions; no key was minted.",
|
|
144
|
+
)
|
|
145
|
+
return env_path
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _normalize_suffix(raw: Optional[str], writing_env: bool) -> str:
|
|
149
|
+
"""Validate --env-suffix; return it uppercased ("" when not given)."""
|
|
150
|
+
if raw is None:
|
|
151
|
+
return ""
|
|
152
|
+
if not writing_env:
|
|
153
|
+
raise CliError(
|
|
154
|
+
"--env-suffix only applies together with --write-env.",
|
|
155
|
+
code="invalid_argument", exit_code=2,
|
|
156
|
+
hint="Add --write-env (or --env-file PATH).",
|
|
157
|
+
)
|
|
158
|
+
name = raw.strip()
|
|
159
|
+
if not re.fullmatch(r"[A-Za-z0-9_]+", name):
|
|
160
|
+
raise CliError(
|
|
161
|
+
f"--env-suffix '{raw}' is not a valid name: use letters, digits and underscore only.",
|
|
162
|
+
code="invalid_argument", exit_code=2,
|
|
163
|
+
hint="For example --env-suffix SUPPORT gives SYNAP_API_KEY_SUPPORT and "
|
|
164
|
+
"SYNAP_INSTANCE_ID_SUPPORT.",
|
|
165
|
+
)
|
|
166
|
+
return name.upper()
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _guard_env_conflict(env_path: Path, instance_id: str, suffix: str, force: bool) -> None:
|
|
170
|
+
"""Refuse, before a key is minted, to overwrite another instance's variables."""
|
|
171
|
+
if force:
|
|
172
|
+
return
|
|
173
|
+
var = f"SYNAP_INSTANCE_ID_{suffix}" if suffix else "SYNAP_INSTANCE_ID"
|
|
174
|
+
existing = envfile.read_env_value(env_path, var)
|
|
175
|
+
if existing and existing != instance_id:
|
|
176
|
+
key_var = f"SYNAP_API_KEY_{suffix}" if suffix else "SYNAP_API_KEY"
|
|
177
|
+
hint = (
|
|
178
|
+
f"Pass --force to replace it, or use another --env-suffix NAME."
|
|
179
|
+
if suffix else
|
|
180
|
+
f"Pass --env-suffix NAME to keep both (writes {key_var}_NAME and {var}_NAME), "
|
|
181
|
+
f"or --force to replace it."
|
|
182
|
+
)
|
|
183
|
+
raise CliError(
|
|
184
|
+
f"--write-env: '{env_path}' already has {var}={existing}, which is a different "
|
|
185
|
+
f"instance from {instance_id}. Nothing was changed and no key was minted.",
|
|
186
|
+
code="env_conflict", exit_code=EXIT_CONFLICT, hint=hint,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _nearest_existing_dir(p: Path) -> Path:
|
|
191
|
+
for d in p.parents:
|
|
192
|
+
if d.exists():
|
|
193
|
+
return d
|
|
194
|
+
return Path(".")
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _store_in_env(
|
|
198
|
+
cc, resp: dict, env_path: Path, instance_id: str,
|
|
199
|
+
extra: Optional[dict] = None, suffix: str = "",
|
|
200
|
+
) -> None:
|
|
201
|
+
"""Write the freshly minted key to the env file; print only a masked key."""
|
|
202
|
+
key = resp["api_key"]
|
|
203
|
+
# Non-production only: point the runtime SDK at the same deployment as the key.
|
|
204
|
+
runtime_vars = runtime_env_values(cc.active_profile().runtime)
|
|
205
|
+
key_var = f"SYNAP_API_KEY_{suffix}" if suffix else "SYNAP_API_KEY"
|
|
206
|
+
id_var = f"SYNAP_INSTANCE_ID_{suffix}" if suffix else "SYNAP_INSTANCE_ID"
|
|
207
|
+
try:
|
|
208
|
+
created, added, updated = envfile.upsert_env(
|
|
209
|
+
env_path, {key_var: key, id_var: instance_id, **runtime_vars},
|
|
210
|
+
)
|
|
211
|
+
gi_state, gi_path = envfile.ensure_gitignored(env_path)
|
|
212
|
+
except (OSError, ValueError) as e: # UnicodeError is a ValueError
|
|
213
|
+
# Never include the key. It exists server-side, so say how to clean up.
|
|
214
|
+
raise CliError(
|
|
215
|
+
f"Key {resp.get('credential_id')} was minted but writing '{env_path}' failed: "
|
|
216
|
+
f"{getattr(e, 'strerror', None) or type(e).__name__}.",
|
|
217
|
+
code="env_write_failed", exit_code=EXIT_GENERIC,
|
|
218
|
+
hint="Fix the path or permissions and re-run the same command. The unused key "
|
|
219
|
+
"stays valid; tell the human its id so it can be revoked later.",
|
|
220
|
+
)
|
|
221
|
+
masked = envfile.mask_key(key)
|
|
222
|
+
result = {
|
|
223
|
+
"env_file": str(env_path.resolve()),
|
|
224
|
+
"created": created,
|
|
225
|
+
"keys_added": added,
|
|
226
|
+
"keys_updated": updated,
|
|
227
|
+
"masked_key": masked,
|
|
228
|
+
"credential_id": resp.get("credential_id"),
|
|
229
|
+
"instance_id": instance_id,
|
|
230
|
+
"gitignore": {"path": str(gi_path), "state": gi_state},
|
|
231
|
+
**({"runtime_env_vars": list(runtime_vars)} if runtime_vars else {}),
|
|
232
|
+
**(extra or {}),
|
|
233
|
+
}
|
|
234
|
+
if render.is_json():
|
|
235
|
+
render.print_json(result)
|
|
236
|
+
return
|
|
237
|
+
verb = "Created" if created else "Updated"
|
|
238
|
+
if runtime_vars:
|
|
239
|
+
names = [id_var, *runtime_vars]
|
|
240
|
+
listed = ", ".join(names[:-1]) + " and " + names[-1]
|
|
241
|
+
render.success(f"{verb} {env_path.resolve()} with {key_var} ({masked}), {listed}.")
|
|
242
|
+
else:
|
|
243
|
+
render.success(f"{verb} {env_path.resolve()} with {key_var} ({masked}) and {id_var}.")
|
|
244
|
+
if gi_state != "already":
|
|
245
|
+
render.info(f"Added '{env_path.name}' to {gi_path} so the key is not committed.")
|
|
246
|
+
render.info("[dim]The full key is not shown. It lives only in the env file.[/dim]")
|
|
247
|
+
if key_var in updated:
|
|
248
|
+
render.warn(
|
|
249
|
+
f"An existing {key_var} was replaced; the old key still works until you "
|
|
250
|
+
"revoke it (`maximem-synap api-keys list`)."
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@app.command()
|
|
255
|
+
def get(ctx: typer.Context, credential_id: str = typer.Argument(...)) -> None:
|
|
256
|
+
"""Show metadata for one API key."""
|
|
257
|
+
cc = ctx.obj
|
|
258
|
+
key = cc.client().get(f"/api_keys/{credential_id}")
|
|
259
|
+
render.print_detail(key, title=key.get("label"))
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@app.command()
|
|
263
|
+
def revoke(
|
|
264
|
+
ctx: typer.Context,
|
|
265
|
+
credential_id: str = typer.Argument(...),
|
|
266
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip the confirmation prompt (required without a terminal)."),
|
|
267
|
+
) -> None:
|
|
268
|
+
"""Revoke an API key immediately."""
|
|
269
|
+
cc = ctx.obj
|
|
270
|
+
if not yes:
|
|
271
|
+
interactive.confirm(f"Revoke key {credential_id}?")
|
|
272
|
+
cc.client().delete(f"/api_keys/{credential_id}")
|
|
273
|
+
render.success("API key revoked.")
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _keep_old_note(credential_id: str) -> str:
|
|
277
|
+
return (f"The old key {credential_id} still works. Once every process uses the new key, "
|
|
278
|
+
f"revoke it: maximem-synap api-keys revoke {credential_id}")
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@app.command()
|
|
282
|
+
def rotate(
|
|
283
|
+
ctx: typer.Context,
|
|
284
|
+
credential_id: str = typer.Argument(..., help="The key to rotate out."),
|
|
285
|
+
label: str = typer.Option(None, "--label", "-l", help="Label for the new key (default: reuse the old one's)."),
|
|
286
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip the confirmation prompt (required without a terminal)."),
|
|
287
|
+
write_env_flag: bool = typer.Option(
|
|
288
|
+
False, "--write-env",
|
|
289
|
+
help="Write the new SYNAP_API_KEY and SYNAP_INSTANCE_ID into an env file and print "
|
|
290
|
+
"only a masked key (same rules as `api-keys create --write-env`).",
|
|
291
|
+
),
|
|
292
|
+
env_file: Optional[str] = typer.Option(
|
|
293
|
+
None, "--env-file", help="Env file used by --write-env (default ./.env).",
|
|
294
|
+
),
|
|
295
|
+
env_suffix: Optional[str] = typer.Option(
|
|
296
|
+
None, "--env-suffix", metavar="NAME",
|
|
297
|
+
help="With --write-env: name the variables per instance, SYNAP_API_KEY_<NAME> and "
|
|
298
|
+
"SYNAP_INSTANCE_ID_<NAME> (NAME: letters, digits, underscore; uppercased), so one "
|
|
299
|
+
"project can hold keys for several instances. Other instances' lines are never "
|
|
300
|
+
"touched. Example: --env-suffix SUPPORT. Host variables keep their plain names.",
|
|
301
|
+
),
|
|
302
|
+
force: bool = typer.Option(
|
|
303
|
+
False, "--force",
|
|
304
|
+
help="With --write-env and no --env-suffix: replace the SYNAP_API_KEY / SYNAP_INSTANCE_ID "
|
|
305
|
+
"already in the file even if they belong to a different instance.",
|
|
306
|
+
),
|
|
307
|
+
keep_old: bool = typer.Option(
|
|
308
|
+
False, "--keep-old",
|
|
309
|
+
help="Leave the old key working, so running processes can move to the new one "
|
|
310
|
+
"first. Revoke it later with `api-keys revoke <id>`.",
|
|
311
|
+
),
|
|
312
|
+
) -> None:
|
|
313
|
+
"""Mint a replacement key for the same instance, then revoke the old one.
|
|
314
|
+
|
|
315
|
+
The new key is minted *before* the old is revoked, so a failure never leaves
|
|
316
|
+
the instance without a working key. With --keep-old the old key is not
|
|
317
|
+
revoked at all, for a rotation with a grace period. With --write-env the new
|
|
318
|
+
secret goes into the env file and is never printed.
|
|
319
|
+
"""
|
|
320
|
+
cc = ctx.obj
|
|
321
|
+
suffix = _normalize_suffix(env_suffix, write_env_flag or env_file is not None)
|
|
322
|
+
env_path = _prepare_env_path(write_env_flag, env_file)
|
|
323
|
+
client = cc.client()
|
|
324
|
+
old = client.get(f"/api_keys/{credential_id}")
|
|
325
|
+
instance_id = old.get("instance_id")
|
|
326
|
+
if not instance_id:
|
|
327
|
+
raise CliError("This key isn't bound to an instance, so it can't be rotated.")
|
|
328
|
+
if env_path is not None:
|
|
329
|
+
_guard_env_conflict(env_path, instance_id, suffix, force)
|
|
330
|
+
new_label = label or old.get("label") or "default"
|
|
331
|
+
|
|
332
|
+
if not yes:
|
|
333
|
+
interactive.confirm(
|
|
334
|
+
f"Mint a new key for instance {instance_id}"
|
|
335
|
+
+ ("? The old key stays active." if keep_old else f" and revoke {credential_id}?")
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
new_body = {"instance_id": instance_id, "label": new_label}
|
|
339
|
+
if "delete:data" in (old.get("scopes") or []):
|
|
340
|
+
# The replacement must do what the old key did; without this the old key is
|
|
341
|
+
# revoked and customer-level deletes start failing with 403.
|
|
342
|
+
new_body["allow_customer_delete"] = True
|
|
343
|
+
try:
|
|
344
|
+
resp = client.post("/api_keys", json=new_body)
|
|
345
|
+
except CliError as e:
|
|
346
|
+
detail = e.detail if isinstance(e.detail, dict) else {}
|
|
347
|
+
if (e.status_code == 403 and new_body.get("allow_customer_delete")
|
|
348
|
+
and detail.get("required") == "delete:data"):
|
|
349
|
+
raise CliError(
|
|
350
|
+
"Your key cannot pass on delete:data, so the replacement could not be created. "
|
|
351
|
+
"The old key was kept and still works.",
|
|
352
|
+
code="missing_scope", status_code=403,
|
|
353
|
+
hint="Run this with a key that holds delete:data (an owner's login), or rotate without "
|
|
354
|
+
"customer-level deletes by minting the new key yourself with `api-keys create`.",
|
|
355
|
+
) from e
|
|
356
|
+
raise
|
|
357
|
+
|
|
358
|
+
revoked = False
|
|
359
|
+
if not keep_old:
|
|
360
|
+
try:
|
|
361
|
+
client.delete(f"/api_keys/{credential_id}")
|
|
362
|
+
revoked = True
|
|
363
|
+
except CliError as e:
|
|
364
|
+
render.warn(f"New key minted, but revoking the old one failed ({e.message}).")
|
|
365
|
+
|
|
366
|
+
if env_path is not None:
|
|
367
|
+
_store_in_env(
|
|
368
|
+
cc, resp, env_path, instance_id, suffix=suffix,
|
|
369
|
+
extra={"revoked_credential_id": credential_id if revoked else None},
|
|
370
|
+
)
|
|
371
|
+
if keep_old:
|
|
372
|
+
render.info(_keep_old_note(credential_id))
|
|
373
|
+
elif not revoked:
|
|
374
|
+
render.warn(f"The old key {credential_id} is NOT revoked.")
|
|
375
|
+
return
|
|
376
|
+
|
|
377
|
+
if render.is_json():
|
|
378
|
+
render.print_json({**resp, "revoked_credential_id": credential_id if revoked else None})
|
|
379
|
+
return
|
|
380
|
+
if keep_old:
|
|
381
|
+
render.success("New key minted.")
|
|
382
|
+
render.info(_keep_old_note(credential_id))
|
|
383
|
+
else:
|
|
384
|
+
render.success(
|
|
385
|
+
f"Rotated. New key minted"
|
|
386
|
+
+ (f"; old key {credential_id} revoked." if revoked else " (old key NOT revoked — see above).")
|
|
387
|
+
)
|
|
388
|
+
render.console.print()
|
|
389
|
+
render.console.print(f" [bold yellow]{resp['api_key']}[/bold yellow]")
|
|
390
|
+
render.console.print()
|
|
391
|
+
render.warn("Copy it now — it will not be shown again.")
|
|
392
|
+
render.print_detail({
|
|
393
|
+
"credential_id": resp.get("credential_id"),
|
|
394
|
+
"label": resp.get("label"),
|
|
395
|
+
"created_at": resp.get("created_at"),
|
|
396
|
+
})
|