-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: Migrate Node-1st-gen samples from functions.config to params #1229
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
feat: Migrate Node-1st-gen samples from functions.config to params #1229
Conversation
Migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder that use the functions.config API to the new params API.
This includes:
- Replacing `functions.config()` with `defineString` for non-sensitive data and `defineSecret` for sensitive data.
- Updating function definitions with `runWith({secrets: [...]})` where necessary.
- Moving API client initializations from the global scope into function handlers to ensure that parameter values are available at runtime.
- Updating all relevant README.md files and code comments to reflect the new configuration methods.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
| const mailTransport = nodemailer.createTransport({ | ||
| service: 'gmail', | ||
| auth: { | ||
| user: GMAIL_EMAIL.value(), | ||
| pass: GMAIL_PASSWORD.value(), | ||
| }, | ||
| }); |
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.
keep this initialization global as it used to be. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| const client = new Client({ | ||
| cloud: { | ||
| id: ELASTIC_ID.value(), | ||
| username: ELASTIC_USERNAME.value(), | ||
| password: ELASTIC_PASSWORD.value(), | ||
| } | ||
| }); |
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 one global instance of elastic client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| // Update the search index every time a blog post is written. | ||
| exports.onNoteCreated = functions.firestore.document('notes/{noteId}').onCreate((snap, context) => { | ||
| exports.onNoteCreated = functions.runWith({secrets: ["ALGOLIA_ID", "ALGOLIA_ADMIN_KEY"]}).firestore.document('notes/{noteId}').onCreate((snap, context) => { | ||
| const client = algoliasearch(ALGOLIA_ID.value(), ALGOLIA_ADMIN_KEY.value()); |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| // Update the search index every time a blog post is written. | ||
| exports.onNoteWritten = functions.firestore.document('notes/{noteId}').onWrite(async (snap, context) => { | ||
| exports.onNoteWritten = functions.runWith({secrets: ["TYPESENSE_ADMIN_API_KEY"]}).firestore.document('notes/{noteId}').onWrite(async (snap, context) => { | ||
| const client = new Typesense.Client({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| exports.indexentry = functions.database.ref('/blog-posts/{blogid}/text').onWrite( | ||
| exports.indexentry = functions.runWith({secrets: ["ALGOLIA_APP_ID", "ALGOLIA_API_KEY"]}).database.ref('/blog-posts/{blogid}/text').onWrite( | ||
| async (data, context) => { | ||
| const client = algoliasearch(ALGOLIA_APP_ID.value(), ALGOLIA_API_KEY.value()); |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| // visit the URL for this Function to request tokens | ||
| exports.authgoogleapi = functions.https.onRequest((req, res) => { | ||
| exports.authgoogleapi = functions.runWith({secrets: ["GOOGLEAPI_CLIENT_ID", "GOOGLEAPI_CLIENT_SECRET"]}).https.onRequest((req, res) => { | ||
| const functionsOauthClient = new OAuth2Client(GOOGLEAPI_CLIENT_ID.value(), GOOGLEAPI_CLIENT_SECRET.value(), |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
|
|
||
| const accessToken = match[1]; | ||
| try { | ||
| const oktaJwtVerifier = new OktaJwtVerifier({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| exports.pay = functions.https.onRequest((req, res) => { | ||
| exports.pay = functions.runWith({secrets: ["PAYPAL_CLIENT_ID", "PAYPAL_CLIENT_SECRET"]}).https.onRequest((req, res) => { | ||
| // Configure your environment | ||
| paypal.configure({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
|
|
||
| // Sends a welcome email to the given user. | ||
| async function sendWelcomeEmail(email, displayName) { | ||
| const mailTransport = nodemailer.createTransport({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| */ | ||
| exports.redirect = functions.https.onRequest((req, res) => { | ||
| exports.redirect = functions.runWith({secrets: ["SPOTIFY_CLIENT_ID", "SPOTIFY_CLIENT_SECRET"]}).https.onRequest((req, res) => { | ||
| const Spotify = new SpotifyWebApi({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| */ | ||
| exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => { | ||
| exports.createStripeCustomer = functions.runWith({secrets: ["STRIPE_SECRET"]}).auth.user().onCreate(async (user) => { | ||
| const stripe = new Stripe(STRIPE_SECRET.value(), { |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| * Sends an email pointing to the Upgraded App survey. | ||
| */ | ||
| async function sendSurveyEmail(email, name) { | ||
| const mailTransport = nodemailer.createTransport( |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| // Shorten URL written to /links/{linkID}. | ||
| exports.shortenUrl = functions.database.ref('/links/{linkID}').onCreate(async (snap) => { | ||
| exports.shortenUrl = functions.runWith({secrets: ["BITLY_ACCESS_TOKEN"]}).database.ref('/links/{linkID}').onCreate(async (snap) => { | ||
| const bitly = new BitlyClient(BITLY_ACCESS_TOKEN.value()); |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
| exports.getChannelInfo = functions.https.onRequest( | ||
| exports.getChannelInfo = functions.runWith({secrets: ["YOUTUBE_KEY"]}).https.onRequest( | ||
| async (request, response) => { | ||
| const youtube = google.youtube({ |
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 one global instance of this client instead of initializing each time the function runs. In order to access param values, you need to do this inside of an onInit hook https://firebase.google.com/docs/functions/config-env#init-fn
Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API. - Updates all instances of functions.config() to use defineString() or defineSecret(). - Moves client initializations that depend on params into the function bodies. - Updates variable names to lowerCamelCase to follow the recommended style. - Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set. - Verifies that all 1st-gen samples compile successfully after the changes.
Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API. - Updates all instances of functions.config() to use defineString() or defineSecret(). - Moves client initializations that depend on params into the function bodies. - Updates variable names to lowerCamelCase to follow the recommended style. - Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set. - Verifies that all 1st-gen samples compile successfully after the changes. - Corrects the `runWith` secrets configuration to pass the secret objects directly. - Refactors all client initializations to use the `onInit` hook. - Fixes the `google-sheet-sync` trigger. - Fixes inconsistent naming in `okta-auth` and `testlab-to-slack`. - Fixes inefficient `cors` initialization in `okta-auth`.
* use the test build of functions v7 * use 7.0.0 * feat: Migrate Node-1st-gen samples from functions.config to params (#1229) * feat: Migrate Node-1st-gen samples from functions.config to params Migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder that use the functions.config API to the new params API. This includes: - Replacing `functions.config()` with `defineString` for non-sensitive data and `defineSecret` for sensitive data. - Updating function definitions with `runWith({secrets: [...]})` where necessary. - Moving API client initializations from the global scope into function handlers to ensure that parameter values are available at runtime. - Updating all relevant README.md files and code comments to reflect the new configuration methods. * feat(Node-1st-gen): Migrate functions.config to params Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API. - Updates all instances of functions.config() to use defineString() or defineSecret(). - Moves client initializations that depend on params into the function bodies. - Updates variable names to lowerCamelCase to follow the recommended style. - Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set. - Verifies that all 1st-gen samples compile successfully after the changes. * feat(Node-1st-gen): Migrate functions.config to params Migrates all 1st-gen Node.js samples from the deprecated functions.config API to the new params API. - Updates all instances of functions.config() to use defineString() or defineSecret(). - Moves client initializations that depend on params into the function bodies. - Updates variable names to lowerCamelCase to follow the recommended style. - Updates all relevant README.md files to reflect the new configuration method using .env files and firebase functions:secrets:set. - Verifies that all 1st-gen samples compile successfully after the changes. - Corrects the `runWith` secrets configuration to pass the secret objects directly. - Refactors all client initializations to use the `onInit` hook. - Fixes the `google-sheet-sync` trigger. - Fixes inconsistent naming in `okta-auth` and `testlab-to-slack`. - Fixes inefficient `cors` initialization in `okta-auth`. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This change migrates all Cloud Functions for Firebase samples in the Node-1st-gen folder from the deprecated
functions.config()API to the newparamsAPI.The following changes were made:
functions.config()withdefineStringfor non-sensitive configuration anddefineSecretfor sensitive values like API keys and passwords.runWith({secrets: [...]})to grant them access to the defined secrets at runtime.README.mdfiles to replacefirebase functions:config:setcommands with the new instructions for either creating a.envfile or usingfirebase functions:secrets:set.functions.config()variables.PR created automatically by Jules for task 6616826145812791659 started by @jhuleatt