@theholocron/holocron-plugin-cloudflare 5.0.0-alpha.432 → 5.0.0-alpha.434
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/dist/index.mjs +48 -17
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, DEFAULT_TOKEN_ROTATION, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations, tokenRotationRows } from "@theholocron/cli";
|
|
2
2
|
import { PREFIX } from "@theholocron/env-utils/lookup";
|
|
3
3
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
4
4
|
import { createCloudflareClient } from "@theholocron/cloudflare-client";
|
|
@@ -18,18 +18,24 @@ const EVERYTHING = {
|
|
|
18
18
|
* token is only reported. This is the plugin's `tokens` declaration, read through `tokenExpectations()`; change it and
|
|
19
19
|
* that table together.
|
|
20
20
|
*/
|
|
21
|
-
const EXPECTED = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const EXPECTED = {
|
|
22
|
+
rotation: {
|
|
23
|
+
maxAgeDays: 90,
|
|
24
|
+
warnDays: 14
|
|
25
|
+
},
|
|
26
|
+
permissions: {
|
|
27
|
+
local: EVERYTHING,
|
|
28
|
+
dev: EVERYTHING,
|
|
29
|
+
ci: {
|
|
30
|
+
zone: "absent",
|
|
31
|
+
dns: "absent",
|
|
32
|
+
routes: "absent",
|
|
33
|
+
scripts: "absent",
|
|
34
|
+
pages: "required",
|
|
35
|
+
tunnels: "absent"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
33
39
|
// src/auth.ts
|
|
34
40
|
/** Resolves the Cloudflare API token from `--token`, `HOLOCRON_CLOUDFLARE_TOKEN`, `CLOUDFLARE_API_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
|
|
35
41
|
const resolveToken = createResolveToken({
|
|
@@ -400,18 +406,22 @@ function generateProxyScript(config) {
|
|
|
400
406
|
].join("\n");
|
|
401
407
|
}
|
|
402
408
|
// src/probes/token/parse-token-args.ts
|
|
403
|
-
/** Reads the words after the probe name: `--layer <word>` and any number of zone names. */
|
|
409
|
+
/** Reads the words after the probe name: `--layer <word>`, `--token-name <VAR>` and any number of zone names. */
|
|
404
410
|
function parseTokenArgs(args) {
|
|
405
411
|
const zones = [];
|
|
406
412
|
let layer;
|
|
413
|
+
let tokenName;
|
|
407
414
|
for (let i = 0; i < args.length; i++) {
|
|
408
415
|
const arg = args[i];
|
|
409
416
|
if (arg === "--layer") layer = args[++i];
|
|
410
417
|
else if (arg.startsWith("--layer=")) layer = arg.slice(8);
|
|
418
|
+
else if (arg === "--token-name") tokenName = args[++i];
|
|
419
|
+
else if (arg.startsWith("--token-name=")) tokenName = arg.slice(13);
|
|
411
420
|
else if (!arg.startsWith("--")) zones.push(arg);
|
|
412
421
|
}
|
|
413
422
|
return {
|
|
414
423
|
...layer ? { layer } : {},
|
|
424
|
+
...tokenName ? { tokenName } : {},
|
|
415
425
|
zones
|
|
416
426
|
};
|
|
417
427
|
}
|
|
@@ -493,7 +503,7 @@ function rowFor({ label, outcome }, rule) {
|
|
|
493
503
|
* `--token cloudflare=<token>` or `--environment <layer>` checks another one; the account id is the plugin's own.
|
|
494
504
|
*
|
|
495
505
|
* A token with no layer is only described. When the CLI passes `--layer` (because `--environment` named `ci`, `dev` or
|
|
496
|
-
* `local`), the results are judged against what that layer's token is meant to carry (the plugin's `tokens` declaration, read with `tokenExpectations()`) and shown in
|
|
506
|
+
* `local`) with `--token-name` (the declared token the Environment held, so the expectations are that token's own), the results are judged against what that layer's token is meant to carry (the plugin's `tokens` declaration, read with `tokenExpectations()`) and shown in
|
|
497
507
|
* two groups, what it should have and what it should not, where a missing or extra permission fails. The other words
|
|
498
508
|
* limit the zone checks to those zones; otherwise up to five are read. How the token is chosen is in `holocron probe --help`.
|
|
499
509
|
*/
|
|
@@ -506,13 +516,20 @@ function tokenProbe(ctx) {
|
|
|
506
516
|
const token = ctx.token();
|
|
507
517
|
probe.secret(token);
|
|
508
518
|
const client = ctx.client();
|
|
509
|
-
const { layer, zones: wanted } = parseTokenArgs(probe.args ?? []);
|
|
510
|
-
const
|
|
519
|
+
const { layer, tokenName, zones: wanted } = parseTokenArgs(probe.args ?? []);
|
|
520
|
+
const expectation = layer ? tokenExpectations(tokens, {
|
|
521
|
+
layer,
|
|
522
|
+
...tokenName ? { envName: tokenName } : {}
|
|
523
|
+
})[0] : void 0;
|
|
524
|
+
const rules = expectation?.rules;
|
|
511
525
|
if (layer && !rules) probe.say({
|
|
512
526
|
status: "info",
|
|
513
527
|
label: layer,
|
|
514
528
|
detail: "no expectations are declared for it, so the token is only described"
|
|
515
529
|
});
|
|
530
|
+
const now = (ctx.now ?? (() => /* @__PURE__ */ new Date()))();
|
|
531
|
+
const rotation = expectation?.rotation ?? DEFAULT_TOKEN_ROTATION;
|
|
532
|
+
let lifetime;
|
|
516
533
|
try {
|
|
517
534
|
const verified = await client.tokens.verify();
|
|
518
535
|
probe.say({
|
|
@@ -520,7 +537,19 @@ function tokenProbe(ctx) {
|
|
|
520
537
|
label: "token",
|
|
521
538
|
detail: `${verified.id} (${verified.status})`
|
|
522
539
|
});
|
|
540
|
+
lifetime = {
|
|
541
|
+
...verified.not_before ? { createdAt: verified.not_before } : {},
|
|
542
|
+
...verified.expires_on ? { expiresAt: verified.expires_on } : {}
|
|
543
|
+
};
|
|
523
544
|
} catch {}
|
|
545
|
+
const rotationRows = tokenRotationRows(lifetime, rotation, now);
|
|
546
|
+
const sayRotation = () => {
|
|
547
|
+
probe.say({
|
|
548
|
+
status: "heading",
|
|
549
|
+
label: "Rotation"
|
|
550
|
+
});
|
|
551
|
+
for (const row of rotationRows) probe.say(row);
|
|
552
|
+
};
|
|
524
553
|
const tried = [];
|
|
525
554
|
let zones = [];
|
|
526
555
|
const zoneOutcome = await reach(async () => {
|
|
@@ -570,6 +599,7 @@ function tokenProbe(ctx) {
|
|
|
570
599
|
}
|
|
571
600
|
if (!rules) {
|
|
572
601
|
for (const t of tried) probe.say(rowFor(t, void 0));
|
|
602
|
+
sayRotation();
|
|
573
603
|
return;
|
|
574
604
|
}
|
|
575
605
|
for (const [heading, rule] of [["Should have", "required"], ["Should not have", "absent"]]) {
|
|
@@ -581,6 +611,7 @@ function tokenProbe(ctx) {
|
|
|
581
611
|
});
|
|
582
612
|
for (const t of inGroup) probe.say(rowFor(t, rule));
|
|
583
613
|
}
|
|
614
|
+
sayRotation();
|
|
584
615
|
}
|
|
585
616
|
};
|
|
586
617
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-cloudflare",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.434",
|
|
4
4
|
"description": "Holocron plugin for Cloudflare. Implements the dns capability against Cloudflare's REST API — zone resolution, DNS record management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -44,20 +44,20 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
46
|
"vitest": "^5.1.0",
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.434",
|
|
48
48
|
"@theholocron/eslint-config": "^8.9.0-alpha.17",
|
|
49
|
-
"@theholocron/
|
|
50
|
-
"@theholocron/
|
|
51
|
-
"@theholocron/kyber": "5.0.0-alpha.432",
|
|
49
|
+
"@theholocron/http-client": "^1.58.0-alpha.30",
|
|
50
|
+
"@theholocron/cloudflare-client": "^1.58.0-alpha.30",
|
|
52
51
|
"@theholocron/misc-utils": "^1.17.0-alpha.4",
|
|
53
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.17",
|
|
54
52
|
"@theholocron/tsdown-config": "^8.9.0-alpha.17",
|
|
55
|
-
"@theholocron/
|
|
53
|
+
"@theholocron/kyber": "5.0.0-alpha.434",
|
|
54
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.17",
|
|
55
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@theholocron/cloudflare-client": "^1.53.1",
|
|
59
59
|
"@theholocron/misc-utils": "^1.16.0",
|
|
60
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
60
|
+
"@theholocron/cli": "5.0.0-alpha.434"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
|
63
63
|
"@theholocron/cloudflare-client": {}
|