-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Prompt for which functions to update during functions:secrets:set #10843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,10 +4,11 @@ import * as tty from "tty"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { logger } from "../logger"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FirebaseError } from "../error"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ensureValidKey, ensureSecret, validateJsonSecret } from "../functions/secrets"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { isFirebaseManaged } from "../deploymentTool"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Command } from "../command"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { requirePermissions } from "../requirePermissions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Options } from "../options"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { confirm } from "../prompt"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { confirm, checkbox, Choice } from "../prompt"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { logBullet, logSuccess, logWarning, readSecretValue } from "../utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { needProjectId, needProjectNumber } from "../projectUtils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -92,8 +93,9 @@ export const command = new Command("functions:secrets:set <KEY>") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let haveBackend = await backend.existingBackend({ projectId } as args.Context); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const endpointsToUpdate = backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let endpointsToUpdate = backend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .allEndpoints(haveBackend) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter((e) => isFirebaseManaged(e.labels ?? [])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter((e) => secrets.inUse({ projectId, projectNumber }, secret, e)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (endpointsToUpdate.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,6 +122,32 @@ export const command = new Command("functions:secrets:set <KEY>") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (endpointsToUpdate.length > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole if + indentation is unnecessary since you early exited if length === 0 and the value cannot be negative. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const choices = endpointsToUpdate.map((e): Choice<string> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentVersion = secrets.getSecretVersions(e)[secret.name]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: `${e.id}(${e.region}) - current secret version: ${currentVersion ?? "unknown"}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: e.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checked: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const selectedEndpointIds = await checkbox<string>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Which functions do you want to re-deploy?" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Press Space to select functions, then Enter to confirm your choices.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| choices: choices, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endpointsToUpdate = endpointsToUpdate.filter((e) => selectedEndpointIds.includes(e.id)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+125
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a fair critique only because the UI allowed you to select a function per region. Given that all functions with the same ID share the same source code (unless they're in different codebases for some reason???) I'm OK with just making this selecting ID irrespective of region. Or you can do Gemini's suggestion much easier by just making it a Choice, setting value to e, and you no longer need to filter. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (endpointsToUpdate.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logBullet(`No functions confirmed for automatic re-deployment.`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logBullet( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Please deploy your functions for the change to take effect by running:\n\t" + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clc.bold("firebase deploy --only functions"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updateOps = endpointsToUpdate.map(async (e) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logBullet(`Updating function ${e.id}(${e.region})...`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updated = await secrets.updateEndpointSecret( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing an empty array
[]as a fallback fore.labelsis a type mismatch becauseisFirebaseManagedexpects an object of type{ [key: string]: any }. Under strict TypeScript compilation, this will cause a type error. Use an empty object{}instead.References
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True bug. Labels are not hashtags, they're key value pairs