-
Notifications
You must be signed in to change notification settings - Fork 902
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
Secret parameters cannot be overridden using .secret.local
when using the Functions Emulator
#5520
Comments
--project
with demo-
prefix ignoring .secret.local
--project
with demo-
prefix ignoring .secret.local
Hey @fedenusy. It looks like there is an issue with using secret parameters with the emulator. I'd recommend making the following change to unblock your setup: import * as functions from "firebase-functions";
import { defineSecret } from "firebase-functions/params";
--defineSecret('SUPA_SECRET')
export const helloWorld = functions.runWith({ secrets: ['SUPA_SECRET'] }).https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
}); In the meantime, I'm going to update the title of this bug to be more generic. |
--project
with demo-
prefix ignoring .secret.local
.secret.local
when using the Functions Emulator
Hey @taeold just to be sure I understood the issue correctly and no longer have to search for errors in my configuration: |
I ran into the same issue. In-case you want to keep a syntax similar to const slackWebhookUrl = { name: 'SLACK_WEBHOOK_URL', value: () => process.env.SLACK_WEBHOOK_URL as string }
export const handler = region('europe-west1')
.runWith({ secrets: [slackWebhookUrl].map((secret) => secret.name) })
.https.onCall(async (name, context) => {
// …
await sendSlackMessage(slackWebhookUrl.value(), { /* … */ })
}) Works as expected in emulator with |
I also can't use .secret.local. Using version 12.2.1. I have tried a lot of different ways to setup that file, (as a dotenv, json, and more), but always get a validation error when emulator are trying to read it.
Example of file: secret_pass=1112222 How should I can use that file? |
Same issue here... What is the status? How can we use secrets if we cannot test them? Please solve this ASAP... |
@zariweyo, have you tried writing the secret name in uppercase? Like SECRET_PASS=1112222? It worked for me. |
Oh my god, it works!!!!. Thanks @coehne |
This is happening with v2 functions and the emulator with tools version 12.6.0. import { https } from 'firebase-functions/v2'
import { defineSecret } from 'firebase-functions/params'
const secretItem = defineSecret('SECRET_ITEM')
https.onCall({secrets: [secretItem]}, () => 200); Is the advice to not define the secret when emulating? Is there an easy way to branch that logic? It doesn't seem like it... |
Ran into the same problem after migrating my code to functions v2 with // functions/webhook.js
const { onRequest } = require('firebase-functions/v2/https')
const { defineSecret } = require('firebase-functions/params')
const stripeKey = defineSecret('STRIPE_KEY')
exports.webhook = onRequest(
{ region: EUROPE, secrets: [stripeKey] },
async (req, res) => {
res.json({ received: true })
}
) # functions/.env
# empty value just to have this variable present for the emulator
STRIPE_KEY= # functions/.secret.local
# actual secret value
STRIPE_KEY=sk_test_*** After that Emulator won't throw that configuration error and run the function as expected |
Waiting on this. Now bypassed the block with adding variables to .env |
I also just ran into this, but happy to hear that .env works at least! Personally, I use |
If someone is using There is also a workaround described in this issue firebase/firebase-functions-test#196 (comment) until |
[REQUIRED] Environment info
firebase-tools: 11.23.1
Platform: ubuntu
[REQUIRED] Test case
helloWorld
function and make itrunWith
any secretfunctions/.secret.local
containing a value for the secret--project
withdemo-
prefixhelloWorld
function from getting loaded.[REQUIRED] Steps to reproduce
mkdir test && cd test
firebase init
> functions > any existing project > typescriptfunctions/src/index.ts
to what's shown below.functions/.secret.local
as shown below.cd functions && npm run build && firebase emulators:start --only functions --project demo-project-id
functions/src/index.ts
:functions/.secret.local
:NB: I also tried placing
.secret.local
at the repo root, and got the same result.[REQUIRED] Expected behavior
Emulators should pick up
.secret.local
.[REQUIRED] Actual behavior
The text was updated successfully, but these errors were encountered: