-
Notifications
You must be signed in to change notification settings - Fork 1.2k
ext:inspect command to display currently deployed Extensions configuration #10583
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
Open
Berlioz
wants to merge
13
commits into
main
Choose a base branch
from
vsfan_ext_inspect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−0
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
266c13b
firebase ext:inspect
Berlioz 9981ecd
commander options
Berlioz 6e31ef1
types
Berlioz ab85e8e
lint
Berlioz 1029c65
changelog.md
Berlioz 3860802
ext:inspect => ext:instances:get
Berlioz 257485c
Merge branch 'main' into vsfan_ext_inspect
Berlioz 8feb3a2
actually support secrets
Berlioz 35da1b2
Merge branch 'vsfan_ext_inspect' of github.com:firebase/firebase-tool…
Berlioz 6efca42
Merge remote-tracking branch 'origin' into vsfan_ext_inspect
Berlioz 0676f35
move to internaltesting experiment
Berlioz b6e01f8
Merge branch 'main' into vsfan_ext_inspect
Berlioz d50b9c4
Merge remote-tracking branch 'origin' into vsfan_ext_inspect
Berlioz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Adds the ext:inspect command to retrieve currently running extension configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { checkMinRequiredVersion } from "../checkMinRequiredVersion"; | ||
| import { Command } from "../command"; | ||
| import { needProjectId } from "../projectUtils"; | ||
| import { ensureExtensionsApiEnabled } from "../extensions/extensionsHelper"; | ||
| import { requirePermissions } from "../requirePermissions"; | ||
| import { listInstances } from "../extensions/extensionsApi"; | ||
| import { last, logLabeledBullet } from "../utils"; | ||
| import { logPrefix } from "../extensions/extensionsHelper"; | ||
| import { FirebaseError } from "../error"; | ||
|
|
||
| import * as clc from "colorette"; | ||
|
|
||
| export const command = new Command("ext:inspect [extensionInstanceId]") | ||
| .description("shows the current configuration for a currently installed Extension") | ||
| .option("--with-secrets", "shows the parameter name (but not value) of SECRET-type params") | ||
| .before(requirePermissions, ["firebaseextensions.instances.list"]) | ||
| .before(requirePermissions, ["firebaseextensions.instances.get"]) | ||
| .before(ensureExtensionsApiEnabled) | ||
| .before(checkMinRequiredVersion, "extMinVersion") | ||
| .action(async (wantInstanceId: string, options: any) => { | ||
| const listAll = !wantInstanceId; | ||
| const projectId = needProjectId(options); | ||
| const instances = await listInstances(projectId); | ||
| if (instances.length < 1) { | ||
| logLabeledBullet( | ||
| logPrefix, | ||
| `there are no extensions installed on project ${clc.bold(projectId)}.`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| let found = false; | ||
| instances.forEach((instance) => { | ||
| const instanceId = last(instance.name.split("/")) ?? ""; | ||
| if (!listAll && instanceId !== wantInstanceId) { | ||
| return; | ||
| } | ||
|
|
||
| found = true; | ||
| const liveParams = instance.config.params || []; | ||
| const liveSystemParams = instance.config.systemParams || []; | ||
| const specParams = instance.config.source.spec.params || []; | ||
| const specSystemParams = instance.config.source.spec.systemParams || []; | ||
|
|
||
| if (listAll) { | ||
| console.log("# " + instanceId); | ||
| } | ||
|
|
||
| // Every user param must be available, so we replicate the spec's default behavior if not present | ||
| specParams.forEach((specParam) => { | ||
| if (specParam.type === "SECRET") { | ||
| if (options.withSecrets) { | ||
| console.log("# " + specParam.param + " stored in Cloud Secret Manager"); | ||
| } | ||
| } else if (specParam.param in liveParams) { | ||
| console.log(specParam.param + "=" + liveParams[specParam.param]); | ||
| } else if ("default" in specParam) { | ||
| console.log(specParam.param + "=" + specParam.default); | ||
| } else { | ||
| console.log(specParam.param + '=""'); | ||
| } | ||
| }); | ||
|
|
||
| // System params aren't necessarily defined in the spec, but we do respect any defaults | ||
| Object.entries(liveSystemParams).forEach(([sysParamName, sysParamValue]) => { | ||
| const renamed = sysParamName.replace( | ||
| "firebaseextensions.v1beta.function/", | ||
| "extensions_system_", | ||
| ); | ||
| console.log(renamed + "=" + sysParamValue); | ||
| }); | ||
| specSystemParams.forEach((specSystemParam) => { | ||
| if (specSystemParam.param in liveSystemParams) { | ||
| return; | ||
| } | ||
| if ("default" in specSystemParam) { | ||
| const renamed = specSystemParam.param.replace( | ||
| "firebaseextensions.v1beta.function/", | ||
| "extensions_system_", | ||
| ); | ||
| console.log(renamed + "=" + specSystemParam.default); | ||
| } | ||
| }); | ||
| }); | ||
| if (!found) { | ||
| throw new FirebaseError( | ||
| `Could not find extension instance ${wantInstanceId} in active extensions`, | ||
| ); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.