WC-5233 use patch apis for wrangler preview secret commands - #15043
WC-5233 use patch apis for wrangler preview secret commands#15043podonnell-dev wants to merge 3 commits into
wrangler preview secret commands#15043Conversation
🦋 Changeset detectedLatest commit: 7b3c9db The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| PREVIEW_NOT_FOUND_ERR_CODE, | ||
| previewNotFoundMessage, | ||
| resolvePreviewName, | ||
| } from "./index"; |
There was a problem hiding this comment.
open to making this easier to distinguish - maybe a shared.ts or something similar
| ); | ||
| } | ||
|
|
||
| function mockGetPreviewDeploymentError(code: number) { |
There was a problem hiding this comment.
diff between this and mockPreviewDeploymentNotFound?
| expect, | ||
| }) => { | ||
| mockStdIn.send("preview-secret"); | ||
| let patchedPreviewDefaults = false; |
There was a problem hiding this comment.
don't really need the assertion that we aren't patching preview defaults any more. that's just cruft lying around from the previous design.
| test("reads the latest Preview deployment and lists secrets as JSON", async ({ | ||
| expect, | ||
| }) => { | ||
| let requestUrl: string | undefined; | ||
| mockGetLatestPreviewDeployment( | ||
| { | ||
| DB_PASSWORD: { type: "secret_text" }, | ||
| API_KEY: { type: "secret_text" }, | ||
| PUBLIC_VAR: { type: "plain_text", text: "visible" }, | ||
| }, | ||
| ({ url }) => { | ||
| requestUrl = url; | ||
| } | ||
| ); | ||
| await runWrangler( | ||
| "preview secret list --json --worker-name test-worker" | ||
| "preview secret list --json --name test-preview --worker-name test-worker" | ||
| ); | ||
| expect(requestUrl).toContain( | ||
| "/workers/workers/test-worker/previews/test-preview/deployments/latest" | ||
| ); | ||
| expect(std.out).toContain('"name": "DB_PASSWORD"'); | ||
| expect(std.out).toContain('"name": "API_KEY"'); | ||
| expect(std.out).toContain('"type": "secret_text"'); | ||
| expect(std.out).not.toContain("PUBLIC_VAR"); | ||
| }); | ||
|
|
||
| test("should list secrets in pretty format", async ({ expect }) => { | ||
| msw.use( | ||
| http.get(`*/accounts/:accountId/workers/workers/:workerId`, () => | ||
| HttpResponse.json({ | ||
| success: true, | ||
| result: { | ||
| preview_defaults: { | ||
| env: { | ||
| MY_SECRET: { type: "secret_text" }, | ||
| PLAIN: { type: "plain_text", text: "not-a-secret" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ) | ||
| test("should list secrets in pretty format with values masked", async ({ | ||
| expect, | ||
| }) => { | ||
| mockGetLatestPreviewDeployment({ | ||
| MY_SECRET: { type: "secret_text", text: "super-secret-value" }, | ||
| PLAIN: { type: "plain_text", text: "not-a-secret" }, | ||
| }); | ||
| await runWrangler( | ||
| "preview secret list --name test-preview --worker-name test-worker" | ||
| ); | ||
| await runWrangler("preview secret list --worker-name test-worker"); | ||
| expect(std.out).toContain("Worker: test-worker"); | ||
| expect(std.out).toContain("Previews settings"); | ||
| expect(std.out).toContain("Secrets"); | ||
| expect(std.out).toContain("MY_SECRET"); | ||
| expect(std.out).not.toContain("PLAIN"); | ||
| expect(std.out).toContain("********"); | ||
| expect(std.out).not.toContain("super-secret-value"); | ||
| }); |
There was a problem hiding this comment.
maybe a matrix test for "can handle no text value provided" vs. "masks text value if provided" and "json" vs. "pretty"?
| ); | ||
| }); | ||
|
|
||
| test("creates a deployment with an empty patch for null-only input", async ({ |
There was a problem hiding this comment.
is skipping over null values current behavior?
if they're all null, should we error as if no input was provided?
| export const previewSecretBulkCommand = createCommand({ | ||
| metadata: { | ||
| description: | ||
| "Upload multiple secrets to a Worker Preview's latest deployment", |
There was a problem hiding this comment.
| "Upload multiple secrets to a Worker Preview's latest deployment", | |
| "Upload multiple secrets to a Worker Preview and create a new deployment", |
| export const previewSecretDeleteCommand = createCommand({ | ||
| metadata: { | ||
| description: | ||
| "Delete a secret variable from a Worker Preview's latest deployment", |
There was a problem hiding this comment.
| "Delete a secret variable from a Worker Preview's latest deployment", | |
| "Delete a secret variable from a Worker Preview and create a new deployment", |
GregBrimble
left a comment
There was a problem hiding this comment.
Only other thing I'd consider testing is: no preview name provided and not in a git worktree.
| export const noPreviewDeploymentPatchMessage = (previewName: string) => | ||
| `There are currently no deployments for the Preview "${previewName}". Please create a Preview deployment before modifying a secret.`; | ||
| export const noPreviewDeploymentListMessage = (previewName: string) => | ||
| `There are currently no deployments for the Preview "${previewName}" - please create a Preview deployment.`; |
There was a problem hiding this comment.
| `There are currently no deployments for the Preview "${previewName}" - please create a Preview deployment.`; | |
| `There are currently no deployments for the Preview "${previewName}". Please create a Preview deployment.`; |
✨ consistency ✨
Fixes WC-5233
Use PATCH APIs for wrangler
preview secretcommands. Removing the dependence onpreview_defaults- all preview secret commands now patch secrets for the latest preview deployment. Also adjusted file conventions to match #14448 more closelyReviewable, but ask Patrick before merging - we'll be trying to time this release for next week
A picture of a cute animal (not mandatory, but encouraged)