- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
BREAKING: Rewrite functions:config:export command #9341
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: next
Are you sure you want to change the base?
Conversation
Target the new defineJsonSecret API as migration target for functions.config() usage. The new API is a simpler migration target for existing functions.config() use cases.
Example flow:
$ firebase functions:config:export
i  This command retrieves your Runtime Config values (accessed via functions.config()) and exports them as a Secret Manager secret.
i  Fetching your existing functions.config() from danielylee-90...
✔  Fetched your existing functions.config().
i  Configuration to be exported:
⚠  This may contain sensitive data. Do not share this output.
{
   <CONFIG>
}
✔ What would you like to name the new secret for your configuration? RUNTIME_CONFIG
✔  Created new secret version projects/XXX/secrets/RUNTIME_CONFIG/versions/1
i  To complete the migration, update your code:
  // Before:
  const functions = require('firebase-functions');
  exports.myFunction = functions.https.onRequest((req, res) => {
    const apiKey = functions.config().service.key;
    // ...
  });
  // After:
  const functions = require('firebase-functions');
  const { defineJsonSecret } = require('firebase-functions/params');
  const config = defineJsonSecret("RUNTIME_CONFIG");
  exports.myFunction = functions
    .runWith({ secrets: [config] })  // Bind secret here
    .https.onRequest((req, res) => {
      const apiKey = config.value().service.key;
      // ...
    });
i  Note: defineJsonSecret requires firebase-functions v6.6.0 or later. Update your package.json if needed.
i  Then deploy your functions:
  firebase deploy --only functions
    | Summary of ChangesHello @taeold, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant update to the  Highlights
 Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either  
 Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a  Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
 | 
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.
Code Review
This pull request is a great initiative to modernize the functions:config:export command by integrating with Secret Manager. The implementation looks solid, and the interactive prompts and migration guide are very helpful for users.
However, a significant concern is the removal of existing tests (src/functions/runtimeConfigExport.spec.ts) without the addition of new tests for the rewritten functionality. For a breaking change of this magnitude, comprehensive test coverage is crucial to ensure correctness, handle edge cases, and prevent future regressions. I strongly recommend adding unit and/or integration tests for the new command logic before merging.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…se-tools into dl-cfg-export-v2
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.
This is a really cool idea!
| if (result.passed) { | ||
| // We should've been able to fetch the config but couldn't. Ask the user to try export command again. | ||
| export const command = new Command("functions:config:export") | ||
| .description("export environment config as a JSON secret to store in Cloud Secret Manager") | 
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.
| .description("export environment config as a JSON secret to store in Cloud Secret Manager") | |
| .description("export functions.config() values as JSON and store it as a single secret in Cloud Secret Manager") | 
| // We should've been able to fetch the config but couldn't. Ask the user to try export command again. | ||
| export const command = new Command("functions:config:export") | ||
| .description("export environment config as a JSON secret to store in Cloud Secret Manager") | ||
| .option("--secret <name>", "name of the secret to create (default: RUNTIME_CONFIG)") | 
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.
use the defaultSecretName variable here
| if (!sdkVersion || semver.lt(sdkVersion, "6.6.0")) { | ||
| logBullet( | ||
| clc.bold("Note: ") + | ||
| "defineJsonSecret requires firebase-functions v6.6.0 or later. " + | ||
| "Update your package.json if needed.", | ||
| ); | ||
| } | 
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.
| if (!sdkVersion || semver.lt(sdkVersion, "6.6.0")) { | |
| logBullet( | |
| clc.bold("Note: ") + | |
| "defineJsonSecret requires firebase-functions v6.6.0 or later. " + | |
| "Update your package.json if needed.", | |
| ); | |
| } | |
| if (!sdkVersion || semver.lt(sdkVersion, "6.6.0")) { | |
| logBullet( | |
| clc.bold("Note: ") + | |
| "defineJsonSecret requires firebase-functions v6.6.0 or later. " + | |
| `Update to a newer version with ${clc.bold("npm i firebase-functions@latest")}${!sdkVersion ? " if needed." : ""}.`, | |
| ); | |
| } | 
adds a bit of complexity, but this way we can be a bit more assertive if we know someone isn't on the right version
Target the new defineJsonSecret API as migration target for functions.config() usage. The new API is a simpler migration target for existing functions.config() use cases.
Example flow: