@pithy-sh/storage 0.1.5 → 0.2.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/dist/capability.js +2 -2
- package/dist/provision/provisionStorage.d.ts +12 -3
- package/dist/provision/provisionStorage.d.ts.map +1 -1
- package/dist/provision/provisionStorage.js +12 -3
- package/dist/secret/registry.d.ts +21 -1
- package/dist/secret/registry.d.ts.map +1 -1
- package/dist/secret/registry.js +24 -7
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +13 -10
- package/pithy.manifest.json +1 -1
- package/src/capability.ts +2 -2
- package/src/provision/provisionStorage.ts +12 -3
- package/src/secret/registry.ts +39 -5
- package/src/version.generated.ts +1 -1
package/dist/capability.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { StorageConfig } from "./config/config.js";
|
|
4
4
|
import { storageTables } from "./data/tables.js";
|
|
5
|
-
import { storageSecretsRegistry } from "./secret/registry.js";
|
|
5
|
+
import { STORAGE_BUCKET_BINDING, storageSecretsRegistry } from "./secret/registry.js";
|
|
6
6
|
import { registerStorageRoutes } from "./http/routes.js";
|
|
7
7
|
import { storage_0001_objects } from "./migrations/0001_objects.js";
|
|
8
8
|
import { storageExampleSeed } from "./seeds/example.js";
|
|
@@ -42,7 +42,7 @@ function storage(options = {}) {
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
type: "r2",
|
|
45
|
-
name:
|
|
45
|
+
name: STORAGE_BUCKET_BINDING
|
|
46
46
|
},
|
|
47
47
|
...workflowBindings(storageWorkflows)
|
|
48
48
|
];
|
|
@@ -46,6 +46,14 @@ import { type ManagedEnvironment } from "@pithy-sh/secrets/src/scope";
|
|
|
46
46
|
* genuinely 3–63 lowercase characters, starting and ending alphanumeric. Every other namespace Pithy
|
|
47
47
|
* writes into was once held to that same 63 for no reason; asking for a bucket by name is how this one
|
|
48
48
|
* keeps it on purpose.
|
|
49
|
+
*
|
|
50
|
+
* **The `<thing>` segment is `storage`, and `packages/storage/pithy.manifest.json` now says so too**,
|
|
51
|
+
* with `"resource": "storage"` on the `STORAGE_BUCKET` binding (#519). Until it did, `pithy add` and
|
|
52
|
+
* `pithy provision` composed `<project>-<env>-storage-bucket` from the binding name while this composed
|
|
53
|
+
* `<project>-<env>-storage`: two names for one bucket, which is #513's defect in the two capabilities
|
|
54
|
+
* that issue left out. The binding keeps `_BUCKET` — it is read as `env.STORAGE_BUCKET` in a Worker —
|
|
55
|
+
* and the resource drops it, because `r2` is already the composed name's own kind.
|
|
56
|
+
* `cli/src/ci/bindingResourceNames.test.ts` holds this function and that manifest line to one string.
|
|
49
57
|
*/
|
|
50
58
|
export declare function storageBucketName(project: string, env: ManagedEnvironment): string;
|
|
51
59
|
/**
|
|
@@ -98,9 +106,10 @@ export interface StorageProvisionResult {
|
|
|
98
106
|
* completing one environment end to end before starting the next — means a failure creating prod's
|
|
99
107
|
* bucket stops the run before staging's worker is deployed against a half-provisioned account.
|
|
100
108
|
*
|
|
101
|
-
* `environments` is the
|
|
102
|
-
*
|
|
103
|
-
*
|
|
109
|
+
* `environments` is **what the caller determined it can act on**, which the CLI narrows from the project's
|
|
110
|
+
* declaration (#241) to the environments whose app database exists (pithy-sh/pithy#512). Nothing is
|
|
111
|
+
* skipped here and nothing decides here: an environment reaching this list is provisioned, and one that
|
|
112
|
+
* did not was already reported to the operator by name, with why and with the command that fixes it.
|
|
104
113
|
*/
|
|
105
114
|
export declare function provisionStorage(provisioner: StorageProvisioner, environments: DeclaredEnvironments | readonly string[]): Promise<StorageProvisionResult>;
|
|
106
115
|
/** The teardown seam — the inverse of {@link StorageProvisioner}. Every step idempotent. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisionStorage.d.ts","sourceRoot":"","sources":["../../src/provision/provisionStorage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,E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4F;IAC5F,YAAY,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,kBAAkB,CAAA;KAAE,GAAG,gBAAgB,CAAC,CAAC;CACrE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,kBAAkB,EAC/B,YAAY,EAAE,oBAAoB,GAAG,SAAS,MAAM,EAAE,GACrD,OAAO,CAAC,sBAAsB,CAAC,CAiBjC;AASD,4FAA4F;AAC5F,MAAM,WAAW,oBAAoB;IACnC,wFAAwF;IACxF,YAAY,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD;;;;;;;;OAQG;IACH,YAAY,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD;AAED,qGAAqG;AACrG,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,oBAAoB,GAAG,SAAS,MAAM,EAAE,EACtD,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -49,6 +49,14 @@ import { managedEnvironments } from "@pithy-sh/secrets/src/scope";
|
|
|
49
49
|
* genuinely 3–63 lowercase characters, starting and ending alphanumeric. Every other namespace Pithy
|
|
50
50
|
* writes into was once held to that same 63 for no reason; asking for a bucket by name is how this one
|
|
51
51
|
* keeps it on purpose.
|
|
52
|
+
*
|
|
53
|
+
* **The `<thing>` segment is `storage`, and `packages/storage/pithy.manifest.json` now says so too**,
|
|
54
|
+
* with `"resource": "storage"` on the `STORAGE_BUCKET` binding (#519). Until it did, `pithy add` and
|
|
55
|
+
* `pithy provision` composed `<project>-<env>-storage-bucket` from the binding name while this composed
|
|
56
|
+
* `<project>-<env>-storage`: two names for one bucket, which is #513's defect in the two capabilities
|
|
57
|
+
* that issue left out. The binding keeps `_BUCKET` — it is read as `env.STORAGE_BUCKET` in a Worker —
|
|
58
|
+
* and the resource drops it, because `r2` is already the composed name's own kind.
|
|
59
|
+
* `cli/src/ci/bindingResourceNames.test.ts` holds this function and that manifest line to one string.
|
|
52
60
|
*/
|
|
53
61
|
function storageBucketName(project, env) {
|
|
54
62
|
return resourceNames(project).env(env).r2(STORAGE_CAPABILITY);
|
|
@@ -71,9 +79,10 @@ function storageWorkerName(project, env) {
|
|
|
71
79
|
* completing one environment end to end before starting the next — means a failure creating prod's
|
|
72
80
|
* bucket stops the run before staging's worker is deployed against a half-provisioned account.
|
|
73
81
|
*
|
|
74
|
-
* `environments` is the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
82
|
+
* `environments` is **what the caller determined it can act on**, which the CLI narrows from the project's
|
|
83
|
+
* declaration (#241) to the environments whose app database exists (pithy-sh/pithy#512). Nothing is
|
|
84
|
+
* skipped here and nothing decides here: an environment reaching this list is provisioned, and one that
|
|
85
|
+
* did not was already reported to the operator by name, with why and with the command that fixes it.
|
|
77
86
|
*/
|
|
78
87
|
async function provisionStorage(provisioner, environments) {
|
|
79
88
|
await provisioner.preflight();
|
|
@@ -59,14 +59,34 @@ export interface R2CredentialsEntry {
|
|
|
59
59
|
origin: SecretOrigin;
|
|
60
60
|
/** How the pair is replaced. `manual`, always — the same page, by the same human. */
|
|
61
61
|
rotation: SecretRotation;
|
|
62
|
+
/**
|
|
63
|
+
* The R2 binding this bundle presigns, when the declaring capability names one — `STORAGE_BUCKET`,
|
|
64
|
+
* `MEDIA_BUCKET`, `SUPPORT_BUCKET`. See {@link SecretRegistryEntryBase.binding}: it is what lets
|
|
65
|
+
* `pithy doctor` and `pithy secrets ls` stop asking for a credential whose bucket the project has
|
|
66
|
+
* declined (#541).
|
|
67
|
+
*/
|
|
68
|
+
binding?: string;
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
65
72
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
73
|
+
*
|
|
74
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
75
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
76
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
77
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
78
|
+
*
|
|
79
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
80
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
81
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
82
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
83
|
+
* site to invent one.
|
|
66
84
|
*/
|
|
67
|
-
export declare function r2CredentialsRegistry<const N extends string>(name: N): Record<N, R2CredentialsEntry>;
|
|
85
|
+
export declare function r2CredentialsRegistry<const N extends string>(name: N, binding?: string): Record<N, R2CredentialsEntry>;
|
|
68
86
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
69
87
|
export declare const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
88
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
89
|
+
export declare const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
70
90
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
71
91
|
export declare const storageSecretsRegistry: Record<"storage-r2-credentials", R2CredentialsEntry>;
|
|
72
92
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/secret/registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC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EvD,uGAAuG;AACvG,eAAO,MAAM,sBAAsB,sDAAmE,CAAC"}
|
package/dist/secret/registry.js
CHANGED
|
@@ -26,9 +26,9 @@ import { defineSecretRegistry } from "@pithy-sh/secrets/src/registry";
|
|
|
26
26
|
* to define, and `CloudflareR2Manager` validates its config against it.
|
|
27
27
|
*/
|
|
28
28
|
const R2StorageCredentials = R2Credentials.extend({
|
|
29
|
-
accountId: z.string().min(1).describe("The Cloudflare account id the bucket lives in — the S3 endpoint host."),
|
|
30
|
-
bucket: z.string().min(1).describe("The R2 bucket name every presigned URL and server-side object call targets."),
|
|
31
|
-
apiToken: z.string().min(1).describe("The R2-scoped Cloudflare API token the key pair was derived from. Carried alongside because an R2 S3 access key IS a CF API token — the id is the key id, the SHA-256 of the value is the secret — so whatever provisions the pair already holds it, and `CloudflareR2Manager` needs it to prove bucket access.")
|
|
29
|
+
accountId: z.string().min(1).meta({ multiline: false }).describe("The Cloudflare account id the bucket lives in — the S3 endpoint host."),
|
|
30
|
+
bucket: z.string().min(1).meta({ multiline: false }).describe("The R2 bucket name every presigned URL and server-side object call targets."),
|
|
31
|
+
apiToken: z.string().min(1).meta({ multiline: false }).describe("The R2-scoped Cloudflare API token the key pair was derived from. Carried alongside because an R2 S3 access key IS a CF API token — the id is the key id, the SHA-256 of the value is the secret — so whatever provisions the pair already holds it, and `CloudflareR2Manager` needs it to prove bucket access.")
|
|
32
32
|
}).describe("The account, key pair, scoped token, and bucket name the object store presigns and addresses R2 with.");
|
|
33
33
|
/**
|
|
34
34
|
* Where a human makes an R2 S3 access-key pair, and where the same human makes the next one.
|
|
@@ -72,13 +72,30 @@ const R2_CREDENTIALS_ENTRY = {
|
|
|
72
72
|
/**
|
|
73
73
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
74
74
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
75
|
+
*
|
|
76
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
77
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
78
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
79
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
80
|
+
*
|
|
81
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
82
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
83
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
84
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
85
|
+
* site to invent one.
|
|
75
86
|
*/
|
|
76
|
-
function r2CredentialsRegistry(name) {
|
|
77
|
-
|
|
87
|
+
function r2CredentialsRegistry(name, binding) {
|
|
88
|
+
const entry = binding === void 0 ? R2_CREDENTIALS_ENTRY : {
|
|
89
|
+
...R2_CREDENTIALS_ENTRY,
|
|
90
|
+
binding
|
|
91
|
+
};
|
|
92
|
+
return defineSecretRegistry({ [name]: entry });
|
|
78
93
|
}
|
|
79
94
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
80
95
|
const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
96
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
97
|
+
const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
81
98
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
82
|
-
const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET);
|
|
99
|
+
const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET, STORAGE_BUCKET_BINDING);
|
|
83
100
|
//#endregion
|
|
84
|
-
export { R2StorageCredentials, STORAGE_R2_SECRET, r2CredentialsRegistry, storageSecretsRegistry };
|
|
101
|
+
export { R2StorageCredentials, STORAGE_BUCKET_BINDING, STORAGE_R2_SECRET, r2CredentialsRegistry, storageSecretsRegistry };
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
/** This package's npm name — the join key against a release feed. */
|
|
4
4
|
export declare const PACKAGE_NAME = "@pithy-sh/storage";
|
|
5
5
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
6
|
-
export declare const PACKAGE_VERSION = "0.
|
|
6
|
+
export declare const PACKAGE_VERSION = "0.2.0";
|
|
7
7
|
//# sourceMappingURL=version.generated.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
/** This package's npm name — the join key against a release feed. */
|
|
5
5
|
const PACKAGE_NAME = "@pithy-sh/storage";
|
|
6
6
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
7
|
-
const PACKAGE_VERSION = "0.
|
|
7
|
+
const PACKAGE_VERSION = "0.2.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PACKAGE_NAME, PACKAGE_VERSION };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,13 +36,21 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@cloudflare/workers-types": "^5.20260729.1",
|
|
39
|
-
"@hono/zod-validator": "^0.9.0"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"@pithy-sh/
|
|
39
|
+
"@hono/zod-validator": "^0.9.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@pithy-sh/cloudflare": "^0.2.0",
|
|
43
|
+
"@pithy-sh/core": "^0.4.0",
|
|
44
|
+
"@pithy-sh/secrets": "^0.2.0",
|
|
45
|
+
"hono": "^4.13.2",
|
|
46
|
+
"kysely": "^0.29.0",
|
|
47
|
+
"zod": "^4.4.0"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
45
50
|
"@cloudflare/vitest-plugin": "^1.0.0",
|
|
51
|
+
"@pithy-sh/cloudflare": "workspace:*",
|
|
52
|
+
"@pithy-sh/core": "workspace:*",
|
|
53
|
+
"@pithy-sh/secrets": "workspace:*",
|
|
46
54
|
"@pithy-sh/tsconfig": "workspace:*",
|
|
47
55
|
"@types/node": "^22.15.0",
|
|
48
56
|
"@vitest/coverage-v8": "^4.1.0",
|
|
@@ -54,10 +62,5 @@
|
|
|
54
62
|
"vitest": "^4.1.0",
|
|
55
63
|
"wrangler": "^4.115.0",
|
|
56
64
|
"zod": "^4.4.0"
|
|
57
|
-
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"hono": "^4.13.2",
|
|
60
|
-
"kysely": "^0.29.0",
|
|
61
|
-
"zod": "^4.4.0"
|
|
62
65
|
}
|
|
63
66
|
}
|
package/pithy.manifest.json
CHANGED
package/src/capability.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { StorageConfig, type StorageConfigInput } from "./config/config";
|
|
|
11
11
|
import { storageTables } from "./data/tables";
|
|
12
12
|
import { registerStorageRoutes } from "./http/routes";
|
|
13
13
|
import { storage_0001_objects } from "./migrations/0001_objects";
|
|
14
|
-
import { storageSecretsRegistry } from "./secret/registry";
|
|
14
|
+
import { STORAGE_BUCKET_BINDING, storageSecretsRegistry } from "./secret/registry";
|
|
15
15
|
import { storageExampleSeed } from "./seeds/example";
|
|
16
16
|
import { PACKAGE_VERSION } from "./version.generated";
|
|
17
17
|
import { storageWorkflows } from "./workflows/specs";
|
|
@@ -66,7 +66,7 @@ export function storage(options: StorageOptions = {}): StorageCapability {
|
|
|
66
66
|
// The app database — the objects and shares tables live here.
|
|
67
67
|
{ type: "d1", name: "DB" },
|
|
68
68
|
// The bucket the bytes live in. Deliberately separate from media's `MEDIA_BUCKET`.
|
|
69
|
-
{ type: "r2", name:
|
|
69
|
+
{ type: "r2", name: STORAGE_BUCKET_BINDING },
|
|
70
70
|
// The sweep's Workflow binding, derived from the spec rather than written again — one declaration,
|
|
71
71
|
// so a binding rename cannot leave the two disagreeing. Optional: the binding exists only once
|
|
72
72
|
// `pithy storage provision` has deployed the sweep worker, and an unprovisioned project must still
|
|
@@ -52,6 +52,14 @@ import { STORAGE_CAPABILITY } from "../workflows/specs";
|
|
|
52
52
|
* genuinely 3–63 lowercase characters, starting and ending alphanumeric. Every other namespace Pithy
|
|
53
53
|
* writes into was once held to that same 63 for no reason; asking for a bucket by name is how this one
|
|
54
54
|
* keeps it on purpose.
|
|
55
|
+
*
|
|
56
|
+
* **The `<thing>` segment is `storage`, and `packages/storage/pithy.manifest.json` now says so too**,
|
|
57
|
+
* with `"resource": "storage"` on the `STORAGE_BUCKET` binding (#519). Until it did, `pithy add` and
|
|
58
|
+
* `pithy provision` composed `<project>-<env>-storage-bucket` from the binding name while this composed
|
|
59
|
+
* `<project>-<env>-storage`: two names for one bucket, which is #513's defect in the two capabilities
|
|
60
|
+
* that issue left out. The binding keeps `_BUCKET` — it is read as `env.STORAGE_BUCKET` in a Worker —
|
|
61
|
+
* and the resource drops it, because `r2` is already the composed name's own kind.
|
|
62
|
+
* `cli/src/ci/bindingResourceNames.test.ts` holds this function and that manifest line to one string.
|
|
55
63
|
*/
|
|
56
64
|
export function storageBucketName(project: string, env: ManagedEnvironment): string {
|
|
57
65
|
return resourceNames(project).env(env).r2(STORAGE_CAPABILITY);
|
|
@@ -109,9 +117,10 @@ export interface StorageProvisionResult {
|
|
|
109
117
|
* completing one environment end to end before starting the next — means a failure creating prod's
|
|
110
118
|
* bucket stops the run before staging's worker is deployed against a half-provisioned account.
|
|
111
119
|
*
|
|
112
|
-
* `environments` is the
|
|
113
|
-
*
|
|
114
|
-
*
|
|
120
|
+
* `environments` is **what the caller determined it can act on**, which the CLI narrows from the project's
|
|
121
|
+
* declaration (#241) to the environments whose app database exists (pithy-sh/pithy#512). Nothing is
|
|
122
|
+
* skipped here and nothing decides here: an environment reaching this list is provisioned, and one that
|
|
123
|
+
* did not was already reported to the operator by name, with why and with the command that fixes it.
|
|
115
124
|
*/
|
|
116
125
|
export async function provisionStorage(
|
|
117
126
|
provisioner: StorageProvisioner,
|
package/src/secret/registry.ts
CHANGED
|
@@ -29,11 +29,20 @@ import { z } from "zod";
|
|
|
29
29
|
* to define, and `CloudflareR2Manager` validates its config against it.
|
|
30
30
|
*/
|
|
31
31
|
export const R2StorageCredentials = R2Credentials.extend({
|
|
32
|
-
accountId: z
|
|
33
|
-
|
|
32
|
+
accountId: z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1)
|
|
35
|
+
.meta({ multiline: false })
|
|
36
|
+
.describe("The Cloudflare account id the bucket lives in — the S3 endpoint host."),
|
|
37
|
+
bucket: z
|
|
38
|
+
.string()
|
|
39
|
+
.min(1)
|
|
40
|
+
.meta({ multiline: false })
|
|
41
|
+
.describe("The R2 bucket name every presigned URL and server-side object call targets."),
|
|
34
42
|
apiToken: z
|
|
35
43
|
.string()
|
|
36
44
|
.min(1)
|
|
45
|
+
.meta({ multiline: false })
|
|
37
46
|
.describe(
|
|
38
47
|
"The R2-scoped Cloudflare API token the key pair was derived from. Carried alongside because an R2 S3 access key IS a CF API token — the id is the key id, the SHA-256 of the value is the secret — so whatever provisions the pair already holds it, and `CloudflareR2Manager` needs it to prove bucket access.",
|
|
39
48
|
),
|
|
@@ -68,6 +77,13 @@ export interface R2CredentialsEntry {
|
|
|
68
77
|
origin: SecretOrigin;
|
|
69
78
|
/** How the pair is replaced. `manual`, always — the same page, by the same human. */
|
|
70
79
|
rotation: SecretRotation;
|
|
80
|
+
/**
|
|
81
|
+
* The R2 binding this bundle presigns, when the declaring capability names one — `STORAGE_BUCKET`,
|
|
82
|
+
* `MEDIA_BUCKET`, `SUPPORT_BUCKET`. See {@link SecretRegistryEntryBase.binding}: it is what lets
|
|
83
|
+
* `pithy doctor` and `pithy secrets ls` stop asking for a credential whose bucket the project has
|
|
84
|
+
* declined (#541).
|
|
85
|
+
*/
|
|
86
|
+
binding?: string;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
/**
|
|
@@ -106,13 +122,31 @@ const R2_CREDENTIALS_ENTRY: R2CredentialsEntry = {
|
|
|
106
122
|
/**
|
|
107
123
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
108
124
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
125
|
+
*
|
|
126
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
127
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
128
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
129
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
130
|
+
*
|
|
131
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
132
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
133
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
134
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
135
|
+
* site to invent one.
|
|
109
136
|
*/
|
|
110
|
-
export function r2CredentialsRegistry<const N extends string>(
|
|
111
|
-
|
|
137
|
+
export function r2CredentialsRegistry<const N extends string>(
|
|
138
|
+
name: N,
|
|
139
|
+
binding?: string,
|
|
140
|
+
): Record<N, R2CredentialsEntry> {
|
|
141
|
+
const entry: R2CredentialsEntry = binding === undefined ? R2_CREDENTIALS_ENTRY : { ...R2_CREDENTIALS_ENTRY, binding };
|
|
142
|
+
return defineSecretRegistry({ [name]: entry } as Record<N, R2CredentialsEntry> & SecretRegistry);
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
115
146
|
export const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
116
147
|
|
|
148
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
149
|
+
export const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
150
|
+
|
|
117
151
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
118
|
-
export const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET);
|
|
152
|
+
export const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET, STORAGE_BUCKET_BINDING);
|
package/src/version.generated.ts
CHANGED