@nasebanal/cli 0.16.0 → 1.1.0
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.
- package/README.md +12 -1
- package/dist/completion.js +117 -0
- package/dist/index.js +20 -0
- package/package.json +1 -1
- package/specs/assurance.yaml +552 -4
package/README.md
CHANGED
|
@@ -689,7 +689,18 @@ How it behaves:
|
|
|
689
689
|
- **A published tool that is not installed** gets a message with its repository instead of "unknown command".
|
|
690
690
|
- Names are plain lowercase (`[a-z][a-z0-9-]*`); the first match on `PATH` wins; macOS and Linux only. Anything named `nb-<name>` and executable on your `PATH` runs with your rights, as with any command, so keep `PATH` to directories you trust.
|
|
691
691
|
|
|
692
|
-
To make your own: an executable `nb-<name>` on `PATH` whose second line is `# nb-<name> - <one line>`.
|
|
692
|
+
To make your own: an executable `nb-<name>` on `PATH` whose second line is `# nb-<name> - <one line>`. To complete below it, see "Tab completion".
|
|
693
|
+
|
|
694
|
+
## Tab completion
|
|
695
|
+
|
|
696
|
+
```bash
|
|
697
|
+
# ~/.zshrc, after compinit # ~/.bashrc
|
|
698
|
+
source <(nb completion zsh) source <(nb completion bash)
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
`nb quick<TAB>` completes to `nb quickstarts`, `nb assu<TAB>` to `nb assurance`, and below a command its sub-commands and (after a `-`) its options. The script only asks `nb __complete <words...>`, so it follows the command tree, the generated API groups included, with no list to keep in step.
|
|
702
|
+
|
|
703
|
+
A tool answers for the words after its name: `nb quickstarts kong re<TAB>` runs `nb-quickstarts --complete kong re`, which prints one candidate per line (the last word is the one being typed). `nb` asks a tool only when its script contains the literal `--complete`, so it never runs an `nb-*` program that did not say it can answer (the same rule as `nb -h`); a tool that fails or takes more than 2 seconds just gives no candidates.
|
|
693
704
|
|
|
694
705
|
## Adding a New API
|
|
695
706
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tab completion: `nb completion zsh|bash` prints a script that asks `nb __complete <words...>` for candidates.
|
|
3
|
+
*
|
|
4
|
+
* The script is thin on purpose; what can be completed lives here, so it follows the command tree (the generated API
|
|
5
|
+
* groups included) without a second list to keep up to date.
|
|
6
|
+
*
|
|
7
|
+
* - The first word: the built-in commands and the tools found on PATH (`nb quick<TAB>` -> `quickstarts`).
|
|
8
|
+
* - Below a built-in command: its sub-commands, or its options after a `-`.
|
|
9
|
+
* - Below a tool: whatever `nb-<tool> --complete <words...>` prints, one candidate per line (the last word is the
|
|
10
|
+
* one being typed). A tool is asked only when its script contains the literal `--complete`: like `nb -h`, this
|
|
11
|
+
* must not run an `nb-*` program that never said it can answer.
|
|
12
|
+
*/
|
|
13
|
+
import { execFile } from "node:child_process";
|
|
14
|
+
import { closeSync, openSync, readSync } from "node:fs";
|
|
15
|
+
export const SHELLS = ["zsh", "bash"];
|
|
16
|
+
/** Global options that take a value, so the word after one is not a command. */
|
|
17
|
+
const GLOBAL_OPTIONS_WITH_VALUE = new Set(["--env", "--token"]);
|
|
18
|
+
const TOOL_TIMEOUT_MS = 2000;
|
|
19
|
+
const SCAN_BYTES = 64 * 1024;
|
|
20
|
+
export function completionScript(shell) {
|
|
21
|
+
if (shell === "zsh") {
|
|
22
|
+
return [
|
|
23
|
+
"# nb tab completion (zsh). Add to ~/.zshrc, after compinit: source <(nb completion zsh)",
|
|
24
|
+
"_nb() {",
|
|
25
|
+
" local -a candidates",
|
|
26
|
+
' candidates=("${(@f)$(nb __complete "${(@)words[2,CURRENT]}" 2>/dev/null)}")',
|
|
27
|
+
" candidates=(${candidates:#})",
|
|
28
|
+
" (( ${#candidates} )) && compadd -- $candidates",
|
|
29
|
+
"}",
|
|
30
|
+
"compdef _nb nb",
|
|
31
|
+
"",
|
|
32
|
+
].join("\n");
|
|
33
|
+
}
|
|
34
|
+
return [
|
|
35
|
+
"# nb tab completion (bash). Add to ~/.bashrc: source <(nb completion bash)",
|
|
36
|
+
"_nb_complete() {",
|
|
37
|
+
" local IFS=$'\\n'",
|
|
38
|
+
' COMPREPLY=($(nb __complete "${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))',
|
|
39
|
+
"}",
|
|
40
|
+
"complete -F _nb_complete nb",
|
|
41
|
+
"",
|
|
42
|
+
].join("\n");
|
|
43
|
+
}
|
|
44
|
+
/** Whether the tool's script says it answers `--complete` (read, never run). */
|
|
45
|
+
export function supportsComplete(file) {
|
|
46
|
+
try {
|
|
47
|
+
const fd = openSync(file, "r");
|
|
48
|
+
try {
|
|
49
|
+
const buf = Buffer.alloc(SCAN_BYTES);
|
|
50
|
+
const n = readSync(fd, buf, 0, buf.length, 0);
|
|
51
|
+
const text = buf.subarray(0, n).toString("utf8");
|
|
52
|
+
return text.startsWith("#!") && text.includes("--complete");
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
closeSync(fd);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Ask a tool for candidates: its stdout lines, or nothing when it fails, times out or is silent. */
|
|
63
|
+
export function askTool(plugin, words) {
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
execFile(plugin.file, ["--complete", ...words], { timeout: TOOL_TIMEOUT_MS, maxBuffer: 1024 * 1024, env: { ...process.env, NB_PLUGIN_NAME: `nb ${plugin.name}` } }, (err, stdout) => resolve(err ? [] : lines(stdout))).stdin?.end();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function lines(text) {
|
|
69
|
+
return text.split("\n").filter((l) => l !== "");
|
|
70
|
+
}
|
|
71
|
+
function visible(cmd) {
|
|
72
|
+
return cmd.commands.filter((c) => !c._hidden);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The candidates for `words` (what follows `nb`; the last one is being typed, possibly empty).
|
|
76
|
+
* `ask` is how a tool is asked, injected so a test needs no process.
|
|
77
|
+
*/
|
|
78
|
+
export async function complete(program, plugins, words, ask = askTool) {
|
|
79
|
+
if (words.length === 0)
|
|
80
|
+
return [];
|
|
81
|
+
const current = words[words.length - 1];
|
|
82
|
+
let prior = words.slice(0, -1);
|
|
83
|
+
// Global options come before the command: `nb --env local assu<TAB>`.
|
|
84
|
+
while (prior.length > 0 && prior[0].startsWith("-")) {
|
|
85
|
+
prior = prior.slice(GLOBAL_OPTIONS_WITH_VALUE.has(prior[0]) ? 2 : 1);
|
|
86
|
+
}
|
|
87
|
+
let names;
|
|
88
|
+
if (prior.length === 0) {
|
|
89
|
+
if (current.startsWith("-")) {
|
|
90
|
+
names = program.options.flatMap((o) => (o.long ? [o.long] : []));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
names = [...visible(program).map((c) => c.name()), ...plugins.map((p) => p.name)];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const builtin = program.commands.find((c) => c.name() === prior[0] || c.aliases().includes(prior[0]));
|
|
98
|
+
const plugin = builtin ? undefined : plugins.find((p) => p.name === prior[0]);
|
|
99
|
+
if (plugin) {
|
|
100
|
+
return supportsComplete(plugin.file) ? ask(plugin, [...prior.slice(1), current]) : [];
|
|
101
|
+
}
|
|
102
|
+
let cmd = builtin;
|
|
103
|
+
for (const w of prior.slice(1)) {
|
|
104
|
+
if (!cmd)
|
|
105
|
+
break;
|
|
106
|
+
if (w.startsWith("-"))
|
|
107
|
+
continue;
|
|
108
|
+
cmd = cmd.commands.find((c) => c.name() === w || c.aliases().includes(w));
|
|
109
|
+
}
|
|
110
|
+
if (!cmd)
|
|
111
|
+
return [];
|
|
112
|
+
names = current.startsWith("-")
|
|
113
|
+
? cmd.options.flatMap((o) => (o.long ? [o.long] : []))
|
|
114
|
+
: visible(cmd).map((c) => c.name());
|
|
115
|
+
}
|
|
116
|
+
return [...new Set(names)].filter((n) => n.startsWith(current)).sort();
|
|
117
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { attachMonitorSpecOptions } from "./reports/monitors.js";
|
|
|
18
18
|
import { attachSpecsCommands, buildSpecsCommand } from "./specs/command.js";
|
|
19
19
|
import { buildUpgradeCommand, startUpdateNotifier } from "./update.js";
|
|
20
20
|
import { findPlugins, missingMessage, pluginCall, pluginHelp, runPlugin } from "./plugins.js";
|
|
21
|
+
import { SHELLS, complete, completionScript } from "./completion.js";
|
|
21
22
|
// Single source of truth for the version: package.json (dist/ and src/ both sit
|
|
22
23
|
// next to it). A hard-coded string here drifts from the release tag.
|
|
23
24
|
const { version } = createRequire(import.meta.url)("../package.json");
|
|
@@ -32,6 +33,18 @@ program
|
|
|
32
33
|
.showHelpAfterError();
|
|
33
34
|
program.addCommand(buildAuthCommand());
|
|
34
35
|
program.addCommand(buildUpgradeCommand(version));
|
|
36
|
+
program
|
|
37
|
+
.command("completion")
|
|
38
|
+
.description("Print the tab-completion script: source <(nb completion zsh)")
|
|
39
|
+
.argument("<shell>", `shell: ${SHELLS.join(" | ")}`)
|
|
40
|
+
.action((shell) => {
|
|
41
|
+
if (!SHELLS.includes(shell)) {
|
|
42
|
+
printError(new Error(`Unknown shell '${shell}'. Use one of: ${SHELLS.join(", ")}.`));
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
process.stdout.write(completionScript(shell));
|
|
47
|
+
});
|
|
35
48
|
for (const api of API_CATALOG) {
|
|
36
49
|
if (!specExists(api.spec)) {
|
|
37
50
|
// `nb specs push` / `pull` need no contract to run: without one the old standalone group still works.
|
|
@@ -70,6 +83,13 @@ const reserved = new Set(["help", ...program.commands.flatMap((c) => [c.name(),
|
|
|
70
83
|
program.addHelpText("after", '\n[beta] marks the groups of NASEBANAL Evolution\'s beta: they may change in any release.\nSee README, "Stability and compatibility".');
|
|
71
84
|
program.addHelpText("after", () => pluginHelp(findPlugins(process.env.PATH, reserved)));
|
|
72
85
|
async function main() {
|
|
86
|
+
// The shells' completion scripts call `nb __complete <words...>`: one candidate per line, nothing else on stdout.
|
|
87
|
+
if (process.argv[2] === "__complete") {
|
|
88
|
+
const candidates = await complete(program, findPlugins(process.env.PATH, reserved), process.argv.slice(3));
|
|
89
|
+
if (candidates.length > 0)
|
|
90
|
+
process.stdout.write(candidates.join("\n") + "\n");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
73
93
|
const call = pluginCall(process.argv, process.env.PATH, reserved);
|
|
74
94
|
if (call) {
|
|
75
95
|
if ("missing" in call) {
|
package/package.json
CHANGED
package/specs/assurance.yaml
CHANGED
|
@@ -2,7 +2,7 @@ openapi: 3.0.3
|
|
|
2
2
|
info:
|
|
3
3
|
title: NASEBANAL Assurance API
|
|
4
4
|
description: "Backend of NASEBANAL Assurance (quality assurance for APIs and web apps, under NASEBANAL Evolution). Authenticates users via Auth0 JWT and Personal Access Tokens (PAT) and integrates with the Account API. External monitoring: register URLs to be probed on an interval, then read availability reports. Test results: report the normalised result of each CI/CD job into a repository (the id nb-specs-api issues), then read its runs and suites. Assurance is a results store keyed by that id: the repository, and every setting of it (the public badge and report, the token of the public links, attachments, the API-version rule), belongs to nb-specs-api, which Assurance asks when a rule needs a setting. 2.0.0 (unreleased) replaced the project by the repository, moved the settings to nb-specs-api and removed the commercial Contracts feature (contracts, deliverables, documents, SLA clause). Every response is wrapped as `{ success, data }` (or `{ success: false, error }`)."
|
|
5
|
-
version: 2.
|
|
5
|
+
version: 2.1.0
|
|
6
6
|
contact:
|
|
7
7
|
name: NASEBANAL
|
|
8
8
|
url: https://www.nasebanal.com
|
|
@@ -20,6 +20,8 @@ tags:
|
|
|
20
20
|
description: User profile endpoints
|
|
21
21
|
- name: Monitors
|
|
22
22
|
description: "External monitoring: URLs probed on an interval"
|
|
23
|
+
- name: Probes
|
|
24
|
+
description: "Probes (nb-prober) that check push monitors from inside a private network: registered here, each with its own key"
|
|
23
25
|
- name: Reports
|
|
24
26
|
description: Availability reports built from daily rollups and incidents
|
|
25
27
|
- name: Specs
|
|
@@ -131,7 +133,7 @@ paths:
|
|
|
131
133
|
- Monitors
|
|
132
134
|
operationId: createMonitor
|
|
133
135
|
summary: Create a monitor
|
|
134
|
-
description:
|
|
136
|
+
description: "A `pull` monitor's URL must be a public http(s) host on port 80, 443, 8080 or 8443; private, loopback, link-local and single-label hosts are refused. A `push` monitor is checked by a probe (see `/probes`) from inside the owner's network, so its URL may be a private host: the Worker never requests it, and only its shape is checked (http or https, no credentials, at most 2048 characters). A push monitor needs `probe_id`."
|
|
135
137
|
requestBody:
|
|
136
138
|
required: true
|
|
137
139
|
content:
|
|
@@ -296,7 +298,7 @@ paths:
|
|
|
296
298
|
- Monitors
|
|
297
299
|
operationId: checkMonitor
|
|
298
300
|
summary: Run a check now
|
|
299
|
-
description: "Probes the URL immediately and records the outcome. A target that is down still returns 200 with `ok: false` (the check ran). Refused with 429 within 10 seconds of the previous check."
|
|
301
|
+
description: "Probes the URL immediately and records the outcome. A target that is down still returns 200 with `ok: false` (the check ran). Refused with 429 within 10 seconds of the previous check. Refused with 409 `MODE_MISMATCH` for a `push` monitor: the Worker cannot reach its URL, and its probe checks it on its own schedule."
|
|
300
302
|
responses:
|
|
301
303
|
"200":
|
|
302
304
|
description: Check outcome
|
|
@@ -331,6 +333,12 @@ paths:
|
|
|
331
333
|
$ref: "#/components/responses/Forbidden"
|
|
332
334
|
"404":
|
|
333
335
|
$ref: "#/components/responses/NotFound"
|
|
336
|
+
"409":
|
|
337
|
+
description: The monitor is not a pull monitor (`MODE_MISMATCH`)
|
|
338
|
+
content:
|
|
339
|
+
application/json:
|
|
340
|
+
schema:
|
|
341
|
+
$ref: "#/components/schemas/Error"
|
|
334
342
|
"429":
|
|
335
343
|
description: Checked moments ago (`RATE_LIMITED`)
|
|
336
344
|
content:
|
|
@@ -446,6 +454,341 @@ paths:
|
|
|
446
454
|
$ref: "#/components/responses/Forbidden"
|
|
447
455
|
"404":
|
|
448
456
|
$ref: "#/components/responses/NotFound"
|
|
457
|
+
/api/v1/probes:
|
|
458
|
+
get:
|
|
459
|
+
tags:
|
|
460
|
+
- Probes
|
|
461
|
+
operationId: listProbes
|
|
462
|
+
summary: List probes
|
|
463
|
+
description: The probes of the caller's namespace, by name, each with its status, its last heartbeat and how many monitors use it.
|
|
464
|
+
parameters:
|
|
465
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
466
|
+
responses:
|
|
467
|
+
"200":
|
|
468
|
+
description: Probes
|
|
469
|
+
content:
|
|
470
|
+
application/json:
|
|
471
|
+
schema:
|
|
472
|
+
type: object
|
|
473
|
+
required:
|
|
474
|
+
- success
|
|
475
|
+
- data
|
|
476
|
+
properties:
|
|
477
|
+
success:
|
|
478
|
+
type: boolean
|
|
479
|
+
example: true
|
|
480
|
+
data:
|
|
481
|
+
type: object
|
|
482
|
+
required:
|
|
483
|
+
- data
|
|
484
|
+
- total
|
|
485
|
+
- limit
|
|
486
|
+
properties:
|
|
487
|
+
data:
|
|
488
|
+
type: array
|
|
489
|
+
items:
|
|
490
|
+
$ref: "#/components/schemas/Probe"
|
|
491
|
+
total:
|
|
492
|
+
type: integer
|
|
493
|
+
limit:
|
|
494
|
+
type: integer
|
|
495
|
+
description: Maximum probes per namespace
|
|
496
|
+
"401":
|
|
497
|
+
$ref: "#/components/responses/Unauthorized"
|
|
498
|
+
"403":
|
|
499
|
+
$ref: "#/components/responses/Forbidden"
|
|
500
|
+
post:
|
|
501
|
+
tags:
|
|
502
|
+
- Probes
|
|
503
|
+
operationId: createProbe
|
|
504
|
+
summary: Register a probe
|
|
505
|
+
description: "Registers a probe and issues its key, which is returned once. Give the key to nb-prober (`NB_PROBER_KEY`): it identifies the probe, and lets it list its own monitors and report their results, nothing else. 409 `PROBE_NAME_TAKEN` when the namespace already has a probe of that name, 409 `LIMIT_REACHED` at 10 probes."
|
|
506
|
+
parameters:
|
|
507
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
508
|
+
requestBody:
|
|
509
|
+
required: true
|
|
510
|
+
content:
|
|
511
|
+
application/json:
|
|
512
|
+
schema:
|
|
513
|
+
$ref: "#/components/schemas/ProbeCreate"
|
|
514
|
+
responses:
|
|
515
|
+
"201":
|
|
516
|
+
description: The probe and its key (shown once)
|
|
517
|
+
content:
|
|
518
|
+
application/json:
|
|
519
|
+
schema:
|
|
520
|
+
type: object
|
|
521
|
+
required:
|
|
522
|
+
- success
|
|
523
|
+
- data
|
|
524
|
+
properties:
|
|
525
|
+
success:
|
|
526
|
+
type: boolean
|
|
527
|
+
example: true
|
|
528
|
+
data:
|
|
529
|
+
$ref: "#/components/schemas/ProbeCreated"
|
|
530
|
+
"400":
|
|
531
|
+
$ref: "#/components/responses/ValidationError"
|
|
532
|
+
"401":
|
|
533
|
+
$ref: "#/components/responses/Unauthorized"
|
|
534
|
+
"403":
|
|
535
|
+
$ref: "#/components/responses/Forbidden"
|
|
536
|
+
"409":
|
|
537
|
+
description: The name is taken in this namespace (`PROBE_NAME_TAKEN`), or the limit of probes is reached (`LIMIT_REACHED`)
|
|
538
|
+
content:
|
|
539
|
+
application/json:
|
|
540
|
+
schema:
|
|
541
|
+
$ref: "#/components/schemas/Error"
|
|
542
|
+
/api/v1/probes/{id}:
|
|
543
|
+
parameters:
|
|
544
|
+
- name: id
|
|
545
|
+
in: path
|
|
546
|
+
required: true
|
|
547
|
+
schema:
|
|
548
|
+
type: string
|
|
549
|
+
description: Probe id
|
|
550
|
+
get:
|
|
551
|
+
tags:
|
|
552
|
+
- Probes
|
|
553
|
+
operationId: getProbe
|
|
554
|
+
summary: Get a probe
|
|
555
|
+
description: One probe of the caller's namespace, with its status and its last heartbeat.
|
|
556
|
+
parameters:
|
|
557
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
558
|
+
responses:
|
|
559
|
+
"200":
|
|
560
|
+
description: Probe
|
|
561
|
+
content:
|
|
562
|
+
application/json:
|
|
563
|
+
schema:
|
|
564
|
+
type: object
|
|
565
|
+
required:
|
|
566
|
+
- success
|
|
567
|
+
- data
|
|
568
|
+
properties:
|
|
569
|
+
success:
|
|
570
|
+
type: boolean
|
|
571
|
+
example: true
|
|
572
|
+
data:
|
|
573
|
+
$ref: "#/components/schemas/Probe"
|
|
574
|
+
"401":
|
|
575
|
+
$ref: "#/components/responses/Unauthorized"
|
|
576
|
+
"403":
|
|
577
|
+
$ref: "#/components/responses/Forbidden"
|
|
578
|
+
"404":
|
|
579
|
+
$ref: "#/components/responses/NotFound"
|
|
580
|
+
patch:
|
|
581
|
+
tags:
|
|
582
|
+
- Probes
|
|
583
|
+
operationId: updateProbe
|
|
584
|
+
summary: Update a probe
|
|
585
|
+
description: Rename it or change its description. The key and the monitors are not touched.
|
|
586
|
+
parameters:
|
|
587
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
588
|
+
requestBody:
|
|
589
|
+
required: true
|
|
590
|
+
content:
|
|
591
|
+
application/json:
|
|
592
|
+
schema:
|
|
593
|
+
$ref: "#/components/schemas/ProbeUpdate"
|
|
594
|
+
responses:
|
|
595
|
+
"200":
|
|
596
|
+
description: The updated probe
|
|
597
|
+
content:
|
|
598
|
+
application/json:
|
|
599
|
+
schema:
|
|
600
|
+
type: object
|
|
601
|
+
required:
|
|
602
|
+
- success
|
|
603
|
+
- data
|
|
604
|
+
properties:
|
|
605
|
+
success:
|
|
606
|
+
type: boolean
|
|
607
|
+
example: true
|
|
608
|
+
data:
|
|
609
|
+
$ref: "#/components/schemas/Probe"
|
|
610
|
+
"400":
|
|
611
|
+
$ref: "#/components/responses/ValidationError"
|
|
612
|
+
"401":
|
|
613
|
+
$ref: "#/components/responses/Unauthorized"
|
|
614
|
+
"403":
|
|
615
|
+
$ref: "#/components/responses/Forbidden"
|
|
616
|
+
"404":
|
|
617
|
+
$ref: "#/components/responses/NotFound"
|
|
618
|
+
"409":
|
|
619
|
+
description: PROBE_NAME_TAKEN
|
|
620
|
+
content:
|
|
621
|
+
application/json:
|
|
622
|
+
schema:
|
|
623
|
+
$ref: "#/components/schemas/Error"
|
|
624
|
+
delete:
|
|
625
|
+
tags:
|
|
626
|
+
- Probes
|
|
627
|
+
operationId: deleteProbe
|
|
628
|
+
summary: Delete a probe
|
|
629
|
+
description: "Refused with 409 `PROBE_IN_USE` while a monitor uses it: move or delete those monitors first. Its key stops working at once."
|
|
630
|
+
parameters:
|
|
631
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
632
|
+
responses:
|
|
633
|
+
"200":
|
|
634
|
+
description: Deleted
|
|
635
|
+
content:
|
|
636
|
+
application/json:
|
|
637
|
+
schema:
|
|
638
|
+
type: object
|
|
639
|
+
required:
|
|
640
|
+
- success
|
|
641
|
+
- data
|
|
642
|
+
properties:
|
|
643
|
+
success:
|
|
644
|
+
type: boolean
|
|
645
|
+
example: true
|
|
646
|
+
data:
|
|
647
|
+
type: object
|
|
648
|
+
properties:
|
|
649
|
+
id:
|
|
650
|
+
type: string
|
|
651
|
+
deleted:
|
|
652
|
+
type: boolean
|
|
653
|
+
"401":
|
|
654
|
+
$ref: "#/components/responses/Unauthorized"
|
|
655
|
+
"403":
|
|
656
|
+
$ref: "#/components/responses/Forbidden"
|
|
657
|
+
"404":
|
|
658
|
+
$ref: "#/components/responses/NotFound"
|
|
659
|
+
"409":
|
|
660
|
+
description: A monitor still uses the probe (`PROBE_IN_USE`)
|
|
661
|
+
content:
|
|
662
|
+
application/json:
|
|
663
|
+
schema:
|
|
664
|
+
$ref: "#/components/schemas/Error"
|
|
665
|
+
/api/v1/probes/{id}/key:
|
|
666
|
+
parameters:
|
|
667
|
+
- name: id
|
|
668
|
+
in: path
|
|
669
|
+
required: true
|
|
670
|
+
schema:
|
|
671
|
+
type: string
|
|
672
|
+
description: Probe id
|
|
673
|
+
post:
|
|
674
|
+
tags:
|
|
675
|
+
- Probes
|
|
676
|
+
operationId: rotateProbeKey
|
|
677
|
+
summary: Issue a new key
|
|
678
|
+
description: "Replaces the probe's key: the old one stops working at once, the new one is returned once. Use it when a key was lost or may have leaked."
|
|
679
|
+
parameters:
|
|
680
|
+
- $ref: "#/components/parameters/ActiveOrganization"
|
|
681
|
+
responses:
|
|
682
|
+
"200":
|
|
683
|
+
description: The probe and its new key (shown once)
|
|
684
|
+
content:
|
|
685
|
+
application/json:
|
|
686
|
+
schema:
|
|
687
|
+
type: object
|
|
688
|
+
required:
|
|
689
|
+
- success
|
|
690
|
+
- data
|
|
691
|
+
properties:
|
|
692
|
+
success:
|
|
693
|
+
type: boolean
|
|
694
|
+
example: true
|
|
695
|
+
data:
|
|
696
|
+
$ref: "#/components/schemas/ProbeCreated"
|
|
697
|
+
"401":
|
|
698
|
+
$ref: "#/components/responses/Unauthorized"
|
|
699
|
+
"403":
|
|
700
|
+
$ref: "#/components/responses/Forbidden"
|
|
701
|
+
"404":
|
|
702
|
+
$ref: "#/components/responses/NotFound"
|
|
703
|
+
/api/v1/probe/monitors:
|
|
704
|
+
get:
|
|
705
|
+
tags:
|
|
706
|
+
- Probes
|
|
707
|
+
operationId: listProbeMonitors
|
|
708
|
+
summary: List the probe's monitors (heartbeat)
|
|
709
|
+
description: "Called by nb-prober with its key on every pass. Returns the enabled `push` monitors that use this probe, with the settings it needs (URL, method, expected status, keyword, timeout, interval); the uptime is not computed. It is also the heartbeat: it records `last_seen_at` (at most once a minute) and the version sent in `X-Prober-Version`. Only the probe's key is accepted."
|
|
710
|
+
security:
|
|
711
|
+
- ProbeKey: []
|
|
712
|
+
parameters:
|
|
713
|
+
- name: X-Prober-Version
|
|
714
|
+
in: header
|
|
715
|
+
required: false
|
|
716
|
+
schema:
|
|
717
|
+
type: string
|
|
718
|
+
maxLength: 32
|
|
719
|
+
description: The version of nb-prober (recorded as the probe's `version`).
|
|
720
|
+
responses:
|
|
721
|
+
"200":
|
|
722
|
+
description: The probe's monitors
|
|
723
|
+
content:
|
|
724
|
+
application/json:
|
|
725
|
+
schema:
|
|
726
|
+
type: object
|
|
727
|
+
required:
|
|
728
|
+
- success
|
|
729
|
+
- data
|
|
730
|
+
properties:
|
|
731
|
+
success:
|
|
732
|
+
type: boolean
|
|
733
|
+
example: true
|
|
734
|
+
data:
|
|
735
|
+
type: object
|
|
736
|
+
required:
|
|
737
|
+
- data
|
|
738
|
+
- total
|
|
739
|
+
properties:
|
|
740
|
+
data:
|
|
741
|
+
type: array
|
|
742
|
+
items:
|
|
743
|
+
$ref: "#/components/schemas/Monitor"
|
|
744
|
+
total:
|
|
745
|
+
type: integer
|
|
746
|
+
"401":
|
|
747
|
+
$ref: "#/components/responses/Unauthorized"
|
|
748
|
+
/api/v1/probe/monitors/{id}/results:
|
|
749
|
+
parameters:
|
|
750
|
+
- name: id
|
|
751
|
+
in: path
|
|
752
|
+
required: true
|
|
753
|
+
schema:
|
|
754
|
+
type: string
|
|
755
|
+
description: Monitor id
|
|
756
|
+
post:
|
|
757
|
+
tags:
|
|
758
|
+
- Probes
|
|
759
|
+
operationId: reportProbeResults
|
|
760
|
+
summary: Report check outcomes
|
|
761
|
+
description: "nb-prober reports what it measured for one of its monitors. Recorded exactly like a Worker check: monitor state, incident, daily uptime. Idempotent per `checked_at`: a resend is counted in `duplicates`. Items are applied oldest first. An item older than the monitor's latest check is stored for the history and the daily uptime but changes neither the monitor's state nor its incidents (a backfill must not rewrite the present). 200 even when some items are rejected; look at `rejected`. 404 for a monitor that is not this probe's. Only the probe's key is accepted."
|
|
762
|
+
security:
|
|
763
|
+
- ProbeKey: []
|
|
764
|
+
requestBody:
|
|
765
|
+
required: true
|
|
766
|
+
content:
|
|
767
|
+
application/json:
|
|
768
|
+
schema:
|
|
769
|
+
$ref: "#/components/schemas/MonitorResultsReport"
|
|
770
|
+
responses:
|
|
771
|
+
"200":
|
|
772
|
+
description: Outcome of the batch
|
|
773
|
+
content:
|
|
774
|
+
application/json:
|
|
775
|
+
schema:
|
|
776
|
+
type: object
|
|
777
|
+
required:
|
|
778
|
+
- success
|
|
779
|
+
- data
|
|
780
|
+
properties:
|
|
781
|
+
success:
|
|
782
|
+
type: boolean
|
|
783
|
+
example: true
|
|
784
|
+
data:
|
|
785
|
+
$ref: "#/components/schemas/MonitorResultsAck"
|
|
786
|
+
"400":
|
|
787
|
+
$ref: "#/components/responses/ValidationError"
|
|
788
|
+
"401":
|
|
789
|
+
$ref: "#/components/responses/Unauthorized"
|
|
790
|
+
"404":
|
|
791
|
+
$ref: "#/components/responses/NotFound"
|
|
449
792
|
/api/v1/report:
|
|
450
793
|
get:
|
|
451
794
|
tags:
|
|
@@ -1311,6 +1654,11 @@ components:
|
|
|
1311
1654
|
scheme: bearer
|
|
1312
1655
|
bearerFormat: JWT or PAT
|
|
1313
1656
|
description: Use either an Auth0 JWT token or a Personal Access Token (PAT) starting with `nbpat_`.
|
|
1657
|
+
ProbeKey:
|
|
1658
|
+
type: http
|
|
1659
|
+
scheme: bearer
|
|
1660
|
+
bearerFormat: nbp_ key
|
|
1661
|
+
description: A probe's key (`nbp_...`), issued by `POST /probes`. It is accepted only by the two operations that say so (list the probe's monitors, report their results) and by nothing else.
|
|
1314
1662
|
schemas:
|
|
1315
1663
|
User:
|
|
1316
1664
|
type: object
|
|
@@ -1382,8 +1730,9 @@ components:
|
|
|
1382
1730
|
- connection_failed
|
|
1383
1731
|
- unexpected_status
|
|
1384
1732
|
- keyword_not_found
|
|
1733
|
+
- no_report
|
|
1385
1734
|
- null
|
|
1386
|
-
description: Why a check failed; null when it passed
|
|
1735
|
+
description: "Why a check failed; null when it passed. `no_report` is written by the server only: a push monitor whose probe has sent nothing for its interval plus grace period is recorded as down with it. A report that sends it is refused."
|
|
1387
1736
|
MonitorSettings:
|
|
1388
1737
|
type: object
|
|
1389
1738
|
properties:
|
|
@@ -1437,6 +1786,19 @@ components:
|
|
|
1437
1786
|
type: string
|
|
1438
1787
|
nullable: true
|
|
1439
1788
|
description: The repository the spec is tied to (required when creating one, together with spec_id; nb-specs-api says which one the spec is tied to). Its uptime counts toward that spec's quality gates.
|
|
1789
|
+
mode:
|
|
1790
|
+
allOf:
|
|
1791
|
+
- $ref: "#/components/schemas/MonitorMode"
|
|
1792
|
+
description: "Create-only. Changing it in an update is refused (400): the history of a pull and of a push monitor would mean two different things. Delete the monitor and make a new one."
|
|
1793
|
+
probe_id:
|
|
1794
|
+
type: string
|
|
1795
|
+
nullable: true
|
|
1796
|
+
description: "The probe that checks this monitor: the id of a probe of the same namespace (see `/probes`). Required for a push monitor, null for a pull monitor. 422 `PROBE_NOT_FOUND` when the id is not a probe of the caller's namespace."
|
|
1797
|
+
grace_minutes:
|
|
1798
|
+
type: integer
|
|
1799
|
+
minimum: 1
|
|
1800
|
+
maximum: 1440
|
|
1801
|
+
description: "Push monitors only. A monitor with no report for `interval_minutes` plus this many minutes is recorded as down with the error `no_report`. Default: `interval_minutes`. null on a pull monitor."
|
|
1440
1802
|
description:
|
|
1441
1803
|
type: string
|
|
1442
1804
|
nullable: true
|
|
@@ -1525,6 +1887,16 @@ components:
|
|
|
1525
1887
|
type: string
|
|
1526
1888
|
nullable: true
|
|
1527
1889
|
description: The repository the spec is tied to (required when creating one, together with spec_id; nb-specs-api says which one the spec is tied to). Its uptime counts toward that spec's quality gates.
|
|
1890
|
+
mode:
|
|
1891
|
+
$ref: "#/components/schemas/MonitorMode"
|
|
1892
|
+
probe_id:
|
|
1893
|
+
type: string
|
|
1894
|
+
nullable: true
|
|
1895
|
+
description: "The probe that checks this monitor: the id of a probe of the same namespace (see `/probes`). Required for a push monitor, null for a pull monitor. 422 `PROBE_NOT_FOUND` when the id is not a probe of the caller's namespace."
|
|
1896
|
+
grace_minutes:
|
|
1897
|
+
type: integer
|
|
1898
|
+
nullable: true
|
|
1899
|
+
description: "Push monitors only. A monitor with no report for `interval_minutes` plus this many minutes is recorded as down with the error `no_report`. Default: `interval_minutes`. null on a pull monitor."
|
|
1528
1900
|
description:
|
|
1529
1901
|
type: string
|
|
1530
1902
|
nullable: true
|
|
@@ -1538,6 +1910,182 @@ components:
|
|
|
1538
1910
|
type: number
|
|
1539
1911
|
nullable: true
|
|
1540
1912
|
description: Percent, null before the first check
|
|
1913
|
+
MonitorMode:
|
|
1914
|
+
type: string
|
|
1915
|
+
enum:
|
|
1916
|
+
- pull
|
|
1917
|
+
- push
|
|
1918
|
+
default: pull
|
|
1919
|
+
description: "pull: the Worker requests the URL on the interval (public hosts only). push: a probe inside the owner's network checks the URL and reports the outcome; the Worker never requests the URL."
|
|
1920
|
+
MonitorResultItem:
|
|
1921
|
+
type: object
|
|
1922
|
+
required:
|
|
1923
|
+
- checked_at
|
|
1924
|
+
- ok
|
|
1925
|
+
- response_ms
|
|
1926
|
+
properties:
|
|
1927
|
+
checked_at:
|
|
1928
|
+
type: string
|
|
1929
|
+
format: date-time
|
|
1930
|
+
description: When the probe made the check (the probe's clock, UTC). At most 5 minutes ahead of, and 7 days behind, the server's time.
|
|
1931
|
+
ok:
|
|
1932
|
+
type: boolean
|
|
1933
|
+
status_code:
|
|
1934
|
+
type: integer
|
|
1935
|
+
nullable: true
|
|
1936
|
+
minimum: 100
|
|
1937
|
+
maximum: 599
|
|
1938
|
+
response_ms:
|
|
1939
|
+
type: integer
|
|
1940
|
+
minimum: 0
|
|
1941
|
+
maximum: 600000
|
|
1942
|
+
error:
|
|
1943
|
+
type: string
|
|
1944
|
+
nullable: true
|
|
1945
|
+
enum:
|
|
1946
|
+
- timeout
|
|
1947
|
+
- connection_failed
|
|
1948
|
+
- unexpected_status
|
|
1949
|
+
- keyword_not_found
|
|
1950
|
+
- null
|
|
1951
|
+
description: Required when `ok` is false, null when it is true. `no_report` is refused.
|
|
1952
|
+
MonitorResultsReport:
|
|
1953
|
+
type: object
|
|
1954
|
+
required:
|
|
1955
|
+
- results
|
|
1956
|
+
properties:
|
|
1957
|
+
results:
|
|
1958
|
+
type: array
|
|
1959
|
+
minItems: 1
|
|
1960
|
+
maxItems: 100
|
|
1961
|
+
description: The outcomes, 1 to 100 per request, in any order.
|
|
1962
|
+
items:
|
|
1963
|
+
$ref: "#/components/schemas/MonitorResultItem"
|
|
1964
|
+
MonitorResultsAck:
|
|
1965
|
+
type: object
|
|
1966
|
+
required:
|
|
1967
|
+
- accepted
|
|
1968
|
+
- duplicates
|
|
1969
|
+
- rejected
|
|
1970
|
+
properties:
|
|
1971
|
+
accepted:
|
|
1972
|
+
type: integer
|
|
1973
|
+
description: Items newly stored.
|
|
1974
|
+
duplicates:
|
|
1975
|
+
type: integer
|
|
1976
|
+
description: Items whose `checked_at` was already stored; ignored.
|
|
1977
|
+
rejected:
|
|
1978
|
+
type: array
|
|
1979
|
+
description: Items refused, by position in the request (0-based).
|
|
1980
|
+
items:
|
|
1981
|
+
type: object
|
|
1982
|
+
required:
|
|
1983
|
+
- index
|
|
1984
|
+
- reason
|
|
1985
|
+
properties:
|
|
1986
|
+
index:
|
|
1987
|
+
type: integer
|
|
1988
|
+
reason:
|
|
1989
|
+
type: string
|
|
1990
|
+
enum:
|
|
1991
|
+
- too_old
|
|
1992
|
+
- in_future
|
|
1993
|
+
- invalid_error
|
|
1994
|
+
description: "`too_old`: more than 7 days behind. `in_future`: more than 5 minutes ahead. `invalid_error`: `error` is missing on a failure, set on a success, or `no_report`."
|
|
1995
|
+
monitor:
|
|
1996
|
+
$ref: "#/components/schemas/Monitor"
|
|
1997
|
+
ProbeStatus:
|
|
1998
|
+
type: string
|
|
1999
|
+
enum:
|
|
2000
|
+
- pending
|
|
2001
|
+
- online
|
|
2002
|
+
- offline
|
|
2003
|
+
description: "pending: never seen. online: seen within the last 2 minutes. offline: not seen for more than 2 minutes."
|
|
2004
|
+
Probe:
|
|
2005
|
+
type: object
|
|
2006
|
+
properties:
|
|
2007
|
+
id:
|
|
2008
|
+
type: string
|
|
2009
|
+
name:
|
|
2010
|
+
type: string
|
|
2011
|
+
minLength: 1
|
|
2012
|
+
maxLength: 64
|
|
2013
|
+
pattern: ^[a-z0-9][a-z0-9._-]*$
|
|
2014
|
+
description: The probe's name, chosen by the owner (such as `office-tokyo`). Unique within the namespace. A monitor refers to the probe by `id`, so renaming is safe.
|
|
2015
|
+
description:
|
|
2016
|
+
type: string
|
|
2017
|
+
nullable: true
|
|
2018
|
+
maxLength: 500
|
|
2019
|
+
organization_id:
|
|
2020
|
+
type: integer
|
|
2021
|
+
nullable: true
|
|
2022
|
+
example: null
|
|
2023
|
+
status:
|
|
2024
|
+
$ref: "#/components/schemas/ProbeStatus"
|
|
2025
|
+
last_seen_at:
|
|
2026
|
+
type: string
|
|
2027
|
+
format: date-time
|
|
2028
|
+
nullable: true
|
|
2029
|
+
description: When the probe last asked for its monitors (a heartbeat). Written at most once a minute.
|
|
2030
|
+
offline_since:
|
|
2031
|
+
type: string
|
|
2032
|
+
format: date-time
|
|
2033
|
+
nullable: true
|
|
2034
|
+
description: When the server noticed the probe had gone silent (at most a minute after it crossed the 2-minute line); null while it is online or pending.
|
|
2035
|
+
version:
|
|
2036
|
+
type: string
|
|
2037
|
+
nullable: true
|
|
2038
|
+
description: The version of nb-prober as it last reported it (`X-Prober-Version`); null before the first heartbeat.
|
|
2039
|
+
key_prefix:
|
|
2040
|
+
type: string
|
|
2041
|
+
description: The first characters of the current key, to tell keys apart in the list; never enough to use it.
|
|
2042
|
+
monitor_count:
|
|
2043
|
+
type: integer
|
|
2044
|
+
description: How many monitors use this probe.
|
|
2045
|
+
created_at:
|
|
2046
|
+
type: string
|
|
2047
|
+
format: date-time
|
|
2048
|
+
updated_at:
|
|
2049
|
+
type: string
|
|
2050
|
+
format: date-time
|
|
2051
|
+
ProbeCreate:
|
|
2052
|
+
type: object
|
|
2053
|
+
required:
|
|
2054
|
+
- name
|
|
2055
|
+
properties:
|
|
2056
|
+
name:
|
|
2057
|
+
type: string
|
|
2058
|
+
minLength: 1
|
|
2059
|
+
maxLength: 64
|
|
2060
|
+
pattern: ^[a-z0-9][a-z0-9._-]*$
|
|
2061
|
+
description:
|
|
2062
|
+
type: string
|
|
2063
|
+
nullable: true
|
|
2064
|
+
maxLength: 500
|
|
2065
|
+
ProbeUpdate:
|
|
2066
|
+
type: object
|
|
2067
|
+
minProperties: 1
|
|
2068
|
+
properties:
|
|
2069
|
+
name:
|
|
2070
|
+
type: string
|
|
2071
|
+
minLength: 1
|
|
2072
|
+
maxLength: 64
|
|
2073
|
+
pattern: ^[a-z0-9][a-z0-9._-]*$
|
|
2074
|
+
description:
|
|
2075
|
+
type: string
|
|
2076
|
+
nullable: true
|
|
2077
|
+
maxLength: 500
|
|
2078
|
+
ProbeCreated:
|
|
2079
|
+
type: object
|
|
2080
|
+
required:
|
|
2081
|
+
- probe
|
|
2082
|
+
- key
|
|
2083
|
+
properties:
|
|
2084
|
+
probe:
|
|
2085
|
+
$ref: "#/components/schemas/Probe"
|
|
2086
|
+
key:
|
|
2087
|
+
type: string
|
|
2088
|
+
description: "The probe's key, `nbp_<probe id>_<secret>`. Shown only in this response: only a hash is stored, so a lost key is replaced with `POST /probes/{id}/key`."
|
|
1541
2089
|
CheckResult:
|
|
1542
2090
|
type: object
|
|
1543
2091
|
properties:
|