elan-cli 0.1.4__tar.gz → 0.1.6__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.
- {elan_cli-0.1.4 → elan_cli-0.1.6}/CHANGELOG.md +50 -1
- {elan_cli-0.1.4 → elan_cli-0.1.6}/PKG-INFO +1 -1
- {elan_cli-0.1.4 → elan_cli-0.1.6}/pyproject.toml +1 -1
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/deploy.py +102 -16
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/main.py +29 -1
- elan_cli-0.1.6/src/elan_cli/scan.py +172 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/.gitignore +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/LICENSE +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/README.md +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/__init__.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/adk.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/auth.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/child.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/client.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/config.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/destroy.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/doctor.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/env.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/files.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/invoke.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/logs.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/manifests.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/project.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/projects.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/prompt.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/rollback.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/scaffold.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/secret.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/stream.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/tenant.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/validate.py +0 -0
- {elan_cli-0.1.4 → elan_cli-0.1.6}/src/elan_cli/wallet.py +0 -0
|
@@ -3,7 +3,56 @@
|
|
|
3
3
|
Versions follow the tag that published them — `cli/v*`. A version with no date
|
|
4
4
|
has not been published yet.
|
|
5
5
|
|
|
6
|
-
## 0.1.
|
|
6
|
+
## 0.1.6 — 2026-11-15
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **`elan scan` re-scans what your project runs, now.** A deploy checks its image
|
|
10
|
+
once, so a vulnerability published afterwards is found only by checking
|
|
11
|
+
again. For each image it prints the counts by severity and each CRITICAL
|
|
12
|
+
finding, as `elan deploy` does. Anything new since the last scan that would
|
|
13
|
+
refuse a deploy today is listed separately; your organization's admins are
|
|
14
|
+
told about it too. A link to the project's Security page in the console
|
|
15
|
+
follows. If the vulnerability database has not changed since the image's
|
|
16
|
+
last scan, the answer is the same, so it says so and nothing is charged.
|
|
17
|
+
Pass `--project` outside a project directory.
|
|
18
|
+
- **`elan scan schedule` shows or sets how often running images are re-scanned:**
|
|
19
|
+
`off`, `daily`, `weekly` (Sunday), `monthly` (the 1st), or `every <N>` days
|
|
20
|
+
from 1 to 90, for example `elan scan schedule every 14`. It prints the next
|
|
21
|
+
check, the last one and the platform's estimate of scans a month. Re-scans
|
|
22
|
+
are off until you choose a schedule, because each completed one is charged.
|
|
23
|
+
Times are midnight UTC, printed in your own time zone.
|
|
24
|
+
|
|
25
|
+
## 0.1.5 — 2026-11-15
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
- **A successful `elan deploy` ends with "What's Next?"** It links the console's
|
|
29
|
+
Playground, already open on your agent when the deploy has one target, and
|
|
30
|
+
the quickstart for calling the agent from your app. `elan status` does not
|
|
31
|
+
repeat it. Like the scan link, both come from the platform, so they point at
|
|
32
|
+
the right console for the environment you deployed to.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- **`elan deploy` and `elan status` summarise a scan instead of printing all of
|
|
36
|
+
it.** A real image carries hundreds of findings, and every one was printed as
|
|
37
|
+
a raw Python dict, which buried the deploy's outcome. You now get one line of
|
|
38
|
+
counts by severity, then each CRITICAL finding (fixable ones first, at most
|
|
39
|
+
ten) with the version that fixes it. A link to the deployment's Scan tab in
|
|
40
|
+
the console follows, where the full list can be filtered by severity and by
|
|
41
|
+
whether a fix exists. A refused deploy links the same report after its
|
|
42
|
+
problems. The link is one the platform supplies, so it keeps working if the
|
|
43
|
+
console's pages move.
|
|
44
|
+
- **The `image <registry path>` line is gone.** That path is in the platform's
|
|
45
|
+
own registry, which you can neither open nor pull from. The rollout table
|
|
46
|
+
still shows which targets moved to the new digest.
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
- **An image that was never scanned now says so.** The CLI looked for
|
|
50
|
+
`skipped` and `reason`, which the platform never sends; it sends
|
|
51
|
+
`completed: false` and `incomplete_reason`. So an unscanned image printed
|
|
52
|
+
nothing, which looked exactly like a clean one. It now prints
|
|
53
|
+
`not scanned: <reason>` and that this is not the same as clean.
|
|
54
|
+
|
|
55
|
+
## 0.1.4 — 2026-11-13
|
|
7
56
|
|
|
8
57
|
### Added
|
|
9
58
|
- A refusal that names a page to fix it now prints that page. `elan project
|
|
@@ -196,12 +196,17 @@ def _follow(api: Api, deployment_id: str, *, sleep=time.sleep) -> int:
|
|
|
196
196
|
seen = phase
|
|
197
197
|
|
|
198
198
|
if str(status.get("state")) in TERMINAL:
|
|
199
|
-
return report(status)
|
|
199
|
+
return report(status, after_deploy=True)
|
|
200
200
|
sleep(POLL_SECONDS)
|
|
201
201
|
|
|
202
202
|
|
|
203
|
-
def report(status: dict) -> int:
|
|
204
|
-
"""What happened, in the shape somebody actually asks about.
|
|
203
|
+
def report(status: dict, *, after_deploy: bool = False) -> int:
|
|
204
|
+
"""What happened, in the shape somebody actually asks about.
|
|
205
|
+
|
|
206
|
+
`after_deploy` adds "What's Next?" to a success — the moment somebody has
|
|
207
|
+
just shipped an agent and wants to use it. `elan status` passes nothing,
|
|
208
|
+
because reading an old deploy is not that moment.
|
|
209
|
+
"""
|
|
205
210
|
state = str(status.get("state"))
|
|
206
211
|
print()
|
|
207
212
|
|
|
@@ -212,6 +217,10 @@ def report(status: dict) -> int:
|
|
|
212
217
|
for line in str(problem.get("message", "")).splitlines():
|
|
213
218
|
print(f" {line}")
|
|
214
219
|
print()
|
|
220
|
+
# A SCAN REFUSAL NAMES ITS FIXES ABOVE; the whole report is a link
|
|
221
|
+
# away, for whatever else the image carries.
|
|
222
|
+
if status.get("scan") and (link := (status.get("links") or {}).get("scan")):
|
|
223
|
+
print(f" full scan report: {link}")
|
|
215
224
|
return 1
|
|
216
225
|
|
|
217
226
|
if state == "failed":
|
|
@@ -224,15 +233,47 @@ def report(status: dict) -> int:
|
|
|
224
233
|
print(" Those resources still exist and are still billed.")
|
|
225
234
|
return 1
|
|
226
235
|
|
|
236
|
+
# NO `image <registry path>` LINE. That path is in the PLATFORM's registry,
|
|
237
|
+
# which a developer can neither open nor pull from, so it named nothing
|
|
238
|
+
# they could use; the table below shows which targets moved to the new
|
|
239
|
+
# digest, which is the part that answers a question.
|
|
227
240
|
digest = status.get("digest") or ""
|
|
228
|
-
if digest:
|
|
229
|
-
print(f"image {digest}")
|
|
230
|
-
|
|
231
241
|
_rollout(status.get("rollout") or {}, digest)
|
|
232
|
-
_scan(status.get("scan") or {})
|
|
242
|
+
_scan(status.get("scan") or {}, status.get("links") or {})
|
|
243
|
+
if after_deploy and state == "succeeded":
|
|
244
|
+
_next_steps(status.get("links") or {})
|
|
233
245
|
return 0
|
|
234
246
|
|
|
235
247
|
|
|
248
|
+
def _next_steps(links: dict) -> None:
|
|
249
|
+
"""Where to go once an agent is live: try it, then wire it into an app.
|
|
250
|
+
|
|
251
|
+
ONE AGENT IS NAMED, MORE ARE PICKED. A deploy of one target links the
|
|
252
|
+
playground already open on it; a project of several links the playground
|
|
253
|
+
itself, where the reader chooses — a list of a link per agent is a list
|
|
254
|
+
nobody reads to the end.
|
|
255
|
+
|
|
256
|
+
EVERY URL IS THE PLATFORM'S, from `links` (ADR-0175): this package spells
|
|
257
|
+
no console path, so these keep working when the console's pages move, and
|
|
258
|
+
a platform that offers none gets no section rather than a broken one.
|
|
259
|
+
"""
|
|
260
|
+
targets = links.get("playground_targets") or {}
|
|
261
|
+
lines: list[tuple[str, str]] = []
|
|
262
|
+
if len(targets) == 1:
|
|
263
|
+
(slug, link), = targets.items()
|
|
264
|
+
lines.append((f"Try {slug} in the Playground:", link))
|
|
265
|
+
elif links.get("playground"):
|
|
266
|
+
lines.append(("Try your agents in the Playground:", links["playground"]))
|
|
267
|
+
if links.get("quickstart"):
|
|
268
|
+
lines.append(("Integrate it with your app:", links["quickstart"]))
|
|
269
|
+
if not lines:
|
|
270
|
+
return
|
|
271
|
+
width = max(len(label) for label, _ in lines)
|
|
272
|
+
print("\n What's Next?")
|
|
273
|
+
for label, link in lines:
|
|
274
|
+
print(f" {label:<{width}} {link}")
|
|
275
|
+
|
|
276
|
+
|
|
236
277
|
def _rollout(rollout: dict, digest: str) -> None:
|
|
237
278
|
"""Which targets moved, and which kept what they were running.
|
|
238
279
|
|
|
@@ -242,24 +283,69 @@ def _rollout(rollout: dict, digest: str) -> None:
|
|
|
242
283
|
"""
|
|
243
284
|
if not rollout:
|
|
244
285
|
return
|
|
245
|
-
print("
|
|
286
|
+
print(" target digest")
|
|
246
287
|
for slug, target_digest in sorted(rollout.items()):
|
|
247
288
|
shown = str(target_digest).rsplit("@", 1)[-1][:19] or "-"
|
|
248
289
|
moved = " <- new" if digest and target_digest == digest else ""
|
|
249
290
|
print(f" {slug:<26} {shown}{moved}")
|
|
250
291
|
|
|
251
292
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
293
|
+
#: Worst first, in the platform's own vocabulary, and how each reads here.
|
|
294
|
+
SEVERITIES = {"CRITICAL": "critical", "HIGH": "high", "MEDIUM": "medium",
|
|
295
|
+
"LOW": "low", "MINIMAL": "minimal",
|
|
296
|
+
"SEVERITY_UNSPECIFIED": "unrated"}
|
|
297
|
+
|
|
298
|
+
#: How many CRITICAL findings are listed before the rest is left to the link.
|
|
299
|
+
SHOWN = 10
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _scan(scan: dict, links: dict) -> None:
|
|
303
|
+
"""A SUMMARY, THE CRITICAL FINDINGS, AND A LINK — never the whole list.
|
|
304
|
+
|
|
305
|
+
A real image carries hundreds of findings, nearly all of them unfixable
|
|
306
|
+
base-image packages, and printing every one buried the deploy's outcome
|
|
307
|
+
under a page of dicts. What a developer acts on from a terminal is the
|
|
308
|
+
tally and anything CRITICAL; the console's Scan tab has the rest, with
|
|
309
|
+
filters, one link away (`links.scan`, a deep link the platform composes —
|
|
310
|
+
this package spells no console path, ADR-0175).
|
|
311
|
+
|
|
312
|
+
WHETHER IT WAS SCANNED, not only what was found. A tenant reading nothing
|
|
313
|
+
cannot tell a clean image from one nobody looked at. This read `skipped`
|
|
314
|
+
and `reason`, which the API never sent — it sends `completed: false` and
|
|
315
|
+
`incomplete_reason` — so an unscanned image printed nothing at all.
|
|
316
|
+
"""
|
|
255
317
|
if not scan:
|
|
256
318
|
return
|
|
257
|
-
|
|
258
|
-
|
|
319
|
+
link = links.get("scan", "")
|
|
320
|
+
if not scan.get("completed"):
|
|
321
|
+
reason = scan.get("incomplete_reason") or "no reason recorded"
|
|
322
|
+
print(f"\n not scanned: {reason}")
|
|
323
|
+
print(" this image was deployed without a vulnerability check, "
|
|
324
|
+
"which is not the same as clean")
|
|
325
|
+
if link:
|
|
326
|
+
print(f" {link}")
|
|
259
327
|
return
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
328
|
+
|
|
329
|
+
findings = scan.get("findings") or []
|
|
330
|
+
if not findings:
|
|
331
|
+
print("\n scan: nothing found")
|
|
332
|
+
else:
|
|
333
|
+
counts = scan.get("counts") or {}
|
|
334
|
+
tally = ", ".join(f"{counts[name]} {label}"
|
|
335
|
+
for name, label in SEVERITIES.items() if counts.get(name))
|
|
336
|
+
print(f"\n scan: {len(findings)} findings — {tally}")
|
|
337
|
+
# FIXABLE FIRST: those are the ones somebody can act on today.
|
|
338
|
+
critical = sorted((f for f in findings if f.get("severity") == "CRITICAL"),
|
|
339
|
+
key=lambda f: not f.get("fixable"))
|
|
340
|
+
for finding in critical[:SHOWN]:
|
|
341
|
+
fix = (f"fixed in {finding.get('fixed_version')}" if finding.get("fixable")
|
|
342
|
+
else "no fix available")
|
|
343
|
+
print(f" CRITICAL {finding.get('cve')} {finding.get('package')} "
|
|
344
|
+
f"{finding.get('installed_version')} ({fix})")
|
|
345
|
+
if len(critical) > SHOWN:
|
|
346
|
+
print(f" … and {len(critical) - SHOWN} more critical")
|
|
347
|
+
if link:
|
|
348
|
+
print(f" full report: {link}")
|
|
263
349
|
|
|
264
350
|
|
|
265
351
|
def status(api: Api, deployment_id: str) -> int:
|
|
@@ -37,6 +37,7 @@ from elan_cli import doctor as doctor_cmd
|
|
|
37
37
|
from elan_cli import invoke as invoke_cmd
|
|
38
38
|
from elan_cli import logs as logs_cmd
|
|
39
39
|
from elan_cli import projects as projects_cmd
|
|
40
|
+
from elan_cli import scan as scan_cmd
|
|
40
41
|
from elan_cli.auth import AuthError
|
|
41
42
|
from elan_cli.client import Api, ApiError
|
|
42
43
|
from elan_cli.config import Config, ConfigError
|
|
@@ -62,7 +63,8 @@ from elan_cli.wallet import WalletError
|
|
|
62
63
|
#: subclasses and asserts each one appears here — guilty until named, because a
|
|
63
64
|
#: positive predicate over an open set is a sampling method rather than a guard.
|
|
64
65
|
REFUSALS = (ProjectError, ConfigError, AuthError, ApiError, SecretError,
|
|
65
|
-
WalletError, FilesError, ManifestError, StreamError
|
|
66
|
+
WalletError, FilesError, ManifestError, StreamError,
|
|
67
|
+
scan_cmd.ScanError)
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
def version_line() -> str:
|
|
@@ -235,6 +237,22 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
235
237
|
status = sub.add_parser("status", help="how a deployment is getting on")
|
|
236
238
|
status.add_argument("deployment_id")
|
|
237
239
|
|
|
240
|
+
# RE-SCANS OF WHAT IS RUNNING (ADR-0240). `--project` IS DECLARED ON BOTH
|
|
241
|
+
# LEVELS UNDER TWO NAMES, because argparse lets a subparser's default
|
|
242
|
+
# overwrite its parent's value: one dest would make
|
|
243
|
+
# `elan scan --project x schedule` forget the `x`.
|
|
244
|
+
scan = sub.add_parser("scan", help="re-scan what this project runs, now")
|
|
245
|
+
scan.add_argument("--project", default="",
|
|
246
|
+
help="defaults to the project in elan.yaml")
|
|
247
|
+
scan_sub = scan.add_subparsers(dest="scan_command")
|
|
248
|
+
scan_schedule = scan_sub.add_parser(
|
|
249
|
+
"schedule", help="show or set how often running images are re-scanned")
|
|
250
|
+
scan_schedule.add_argument(
|
|
251
|
+
"when", nargs="*",
|
|
252
|
+
help="off | daily | weekly | monthly | every <N> (N from 1 to 90 days)")
|
|
253
|
+
scan_schedule.add_argument("--project", dest="schedule_project", default="",
|
|
254
|
+
help="defaults to the project in elan.yaml")
|
|
255
|
+
|
|
238
256
|
# PLATFORM STAFF ONLY, enforced by the service rather than here. A CLI that
|
|
239
257
|
# refused locally would be a second rule to keep in step with the one that
|
|
240
258
|
# actually holds the credential.
|
|
@@ -514,6 +532,16 @@ def _dispatch(args, parser) -> int:
|
|
|
514
532
|
finally:
|
|
515
533
|
api.close()
|
|
516
534
|
|
|
535
|
+
if args.command == "scan":
|
|
536
|
+
api = Api(Config.load())
|
|
537
|
+
try:
|
|
538
|
+
if args.scan_command == "schedule":
|
|
539
|
+
project = scan_cmd.project_of(args.schedule_project or args.project)
|
|
540
|
+
return scan_cmd.schedule(api, project, args.when)
|
|
541
|
+
return scan_cmd.now(api, scan_cmd.project_of(args.project))
|
|
542
|
+
finally:
|
|
543
|
+
api.close()
|
|
544
|
+
|
|
517
545
|
if args.command == "agents":
|
|
518
546
|
config = Config.load()
|
|
519
547
|
api = Api(config)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""`elan scan`: re-scan what a project runs, and how often that happens by itself.
|
|
2
|
+
|
|
3
|
+
A DEPLOY CHECKS ITS IMAGE ONCE. A vulnerability published the next day is
|
|
4
|
+
found only by checking again — on the project's schedule, or now. Both cost
|
|
5
|
+
the tenant a scan (`security.rescan`), which is why the schedule is off until
|
|
6
|
+
somebody chooses one, and why `elan scan schedule` prints the monthly estimate
|
|
7
|
+
the platform computes beside whatever it sets (ADR-0240).
|
|
8
|
+
|
|
9
|
+
EVERY RULE AND EVERY LINK IS THE PLATFORM'S. What a schedule may be, when it
|
|
10
|
+
next runs and what it is estimated to cost all come back from the API, so this
|
|
11
|
+
package spells no slot rule and no console path that could drift from the
|
|
12
|
+
service's.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from urllib.parse import quote
|
|
19
|
+
|
|
20
|
+
from elan_cli.client import Api
|
|
21
|
+
from elan_cli.deploy import SEVERITIES, SHOWN
|
|
22
|
+
from elan_cli.project import ProjectError, find
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ScanError(Exception):
|
|
26
|
+
"""A scan command that cannot be sent, already phrased for the developer."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def project_of(explicit: str) -> str:
|
|
30
|
+
"""The project to act in: what was asked for, or what `elan.yaml` says —
|
|
31
|
+
the rule `elan wallet` and `elan deploy` already follow."""
|
|
32
|
+
if explicit.strip():
|
|
33
|
+
return explicit.strip()
|
|
34
|
+
try:
|
|
35
|
+
return find().spec.project
|
|
36
|
+
except ProjectError as exc:
|
|
37
|
+
raise ScanError("which project? run this inside one, or pass --project "
|
|
38
|
+
f"({exc})") from exc
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _path(project: str, tail: str) -> str:
|
|
42
|
+
return f"/v1/projects/{quote(project, safe='')}/{tail}"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _when(iso: str) -> str:
|
|
46
|
+
"""An instant in the reader's own zone, named, so nobody converts in their
|
|
47
|
+
head. The service sends UTC."""
|
|
48
|
+
if not iso:
|
|
49
|
+
return ""
|
|
50
|
+
moment = datetime.fromisoformat(iso.replace("Z", "+00:00")).astimezone()
|
|
51
|
+
return moment.strftime("%Y-%m-%d %H:%M %Z")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def now(api: Api, project: str) -> int:
|
|
55
|
+
"""Scan every image the project runs, now, and say what came back."""
|
|
56
|
+
print(f"scanning what {project} runs…")
|
|
57
|
+
result = api.request("POST", _path(project, "scans"))
|
|
58
|
+
for image in result.get("images") or []:
|
|
59
|
+
_image(image)
|
|
60
|
+
link = (result.get("links") or {}).get("security", "")
|
|
61
|
+
if link:
|
|
62
|
+
print(f"\n full report: {link}")
|
|
63
|
+
# A SCAN THAT COULD NOT BE RECORDED is the service's fault, and a script
|
|
64
|
+
# running this must be able to tell.
|
|
65
|
+
return 1 if result.get("errors") else 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _image(image: dict) -> None:
|
|
69
|
+
targets = ", ".join(image.get("targets") or []) or image.get("image_digest", "")
|
|
70
|
+
print(f"\n {targets}")
|
|
71
|
+
if image.get("skipped"):
|
|
72
|
+
print(f" skipped: {image['skipped']}")
|
|
73
|
+
return
|
|
74
|
+
found = image.get("result")
|
|
75
|
+
if not found:
|
|
76
|
+
return
|
|
77
|
+
scan = found.get("scan") or {}
|
|
78
|
+
if found.get("deduped"):
|
|
79
|
+
print(" unchanged: the vulnerability database has not moved since the "
|
|
80
|
+
"last scan, so the answer is the same and this was not charged")
|
|
81
|
+
elif not scan.get("completed"):
|
|
82
|
+
reason = scan.get("incomplete_reason") or "no reason recorded"
|
|
83
|
+
print(f" not scanned: {reason}")
|
|
84
|
+
print(" which is not the same as clean")
|
|
85
|
+
return
|
|
86
|
+
_findings(scan)
|
|
87
|
+
fresh = image.get("newly_blocking") or []
|
|
88
|
+
if fresh:
|
|
89
|
+
print(f" NEW since the last scan, and each would refuse a deploy today "
|
|
90
|
+
f"({len(fresh)}); your organization's admins have been told:")
|
|
91
|
+
for finding in fresh[:SHOWN]:
|
|
92
|
+
print(f" {finding.get('severity')} {finding.get('cve')} "
|
|
93
|
+
f"{finding.get('package')} {finding.get('installed_version')} "
|
|
94
|
+
f"(fixed in {finding.get('fixed_version')})")
|
|
95
|
+
if len(fresh) > SHOWN:
|
|
96
|
+
print(f" … and {len(fresh) - SHOWN} more")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _findings(scan: dict) -> None:
|
|
100
|
+
"""The tally and the CRITICAL findings, as `elan deploy` prints them."""
|
|
101
|
+
findings = scan.get("findings") or []
|
|
102
|
+
if not findings:
|
|
103
|
+
print(" nothing found")
|
|
104
|
+
return
|
|
105
|
+
counts = scan.get("counts") or {}
|
|
106
|
+
tally = ", ".join(f"{counts[name]} {label}"
|
|
107
|
+
for name, label in SEVERITIES.items() if counts.get(name))
|
|
108
|
+
print(f" {len(findings)} findings — {tally}")
|
|
109
|
+
critical = sorted((f for f in findings if f.get("severity") == "CRITICAL"),
|
|
110
|
+
key=lambda f: not f.get("fixable"))
|
|
111
|
+
for finding in critical[:SHOWN]:
|
|
112
|
+
fix = (f"fixed in {finding.get('fixed_version')}" if finding.get("fixable")
|
|
113
|
+
else "no fix available")
|
|
114
|
+
print(f" CRITICAL {finding.get('cve')} {finding.get('package')} "
|
|
115
|
+
f"{finding.get('installed_version')} ({fix})")
|
|
116
|
+
if len(critical) > SHOWN:
|
|
117
|
+
print(f" … and {len(critical) - SHOWN} more critical")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
#: What `elan scan schedule` accepts, as the reader types it.
|
|
121
|
+
WORDS = ("off", "daily", "weekly", "monthly")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _body(words: list[str]) -> dict:
|
|
125
|
+
"""`["every", "14"]` to the API's body. The NUMBER is the service's to
|
|
126
|
+
judge, so a bad one is refused there, in the service's own words."""
|
|
127
|
+
said = [word.lower() for word in words]
|
|
128
|
+
if said and said[-1] == "days":
|
|
129
|
+
said = said[:-1]
|
|
130
|
+
if len(said) == 1 and said[0] in WORDS:
|
|
131
|
+
return {"schedule": said[0]}
|
|
132
|
+
if said and said[0] == "every":
|
|
133
|
+
if len(said) != 2:
|
|
134
|
+
raise ScanError("say how many days: elan scan schedule every 14")
|
|
135
|
+
return {"schedule": "interval", "interval_days": said[1]}
|
|
136
|
+
raise ScanError("choose one of: off, daily, weekly, monthly, or every <N> "
|
|
137
|
+
"(for example: elan scan schedule every 14)")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def schedule(api: Api, project: str, words: list[str]) -> int:
|
|
141
|
+
"""Show how often the project's running images are re-scanned, or set it."""
|
|
142
|
+
path = _path(project, "scan-schedule")
|
|
143
|
+
if words:
|
|
144
|
+
view = api.request("PUT", path, json=_body(words))
|
|
145
|
+
print(f"{project}: re-scans set to {view.get('label', '')}")
|
|
146
|
+
else:
|
|
147
|
+
view = api.request("GET", path)
|
|
148
|
+
print(f"{project}: re-scans {view.get('label', '')}")
|
|
149
|
+
_view(view)
|
|
150
|
+
return 0
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _view(view: dict) -> None:
|
|
154
|
+
images = view.get("images", 0)
|
|
155
|
+
if view.get("schedule") == "off":
|
|
156
|
+
print(" next: never — re-scans are off, and nothing is charged for them")
|
|
157
|
+
elif view.get("next_run_is_due"):
|
|
158
|
+
print(" next: due now — the hourly check scans it within the hour")
|
|
159
|
+
elif view.get("next_run"):
|
|
160
|
+
print(f" next: {_when(view['next_run'])} (within the hour after)")
|
|
161
|
+
else:
|
|
162
|
+
print(" next: once something is deployed")
|
|
163
|
+
last = _when(view.get("last_run", ""))
|
|
164
|
+
print(f" last: {last or 'never'}")
|
|
165
|
+
if view.get("schedule") != "off":
|
|
166
|
+
estimate = view.get("estimated_scans_per_month", 0)
|
|
167
|
+
print(f" estimate: about {estimate:g} scans a month "
|
|
168
|
+
f"({images} image{'' if images == 1 else 's'}; one image is one "
|
|
169
|
+
"scan however many agents run it)")
|
|
170
|
+
link = (view.get("links") or {}).get("security", "")
|
|
171
|
+
if link:
|
|
172
|
+
print(f" manage: {link}")
|
|
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
|
|
File without changes
|