-
Notifications
You must be signed in to change notification settings - Fork 59
Secret Manager Values in offline testing #255
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
Labels
Comments
Found an solution myself, in general I cannot understand why official packages do not support functions v2 when v1 is already deprectated... According to the firebase-functions implementation: export class SecretParam {
static type: ParamValueType = "secret";
name: string;
constructor(name: string) {
this.name = name;
}
/** @internal */
runtimeValue(): string {
const val = process.env[this.name];
if (val === undefined) {
logger.warn(
`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`
);
}
return val || "";
}
/** @internal */
toSpec(): ParamSpec<string> {
return {
type: "secret",
name: this.name,
};
}
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
value(): string {
if (process.env.FUNCTIONS_CONTROL_API === "true") {
throw new Error(
`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`
);
}
return this.runtimeValue();
}
} So just writing the variabled/secrets in const secretsFile = readFileSync('functions/.secret.local', {
encoding: 'utf-8',
});
const envFile = readFileSync('functions/.env.local', {
encoding: 'utf-8',
});
const secrets = secretsFile.split('\n').filter((line) => line.length);
const envVariables = envFile.split('\n').filter((line) => line.length);
for (const line of [...secrets, ...envVariables]) {
const [key, value] = line.split('=');
process.env[key] = value;
} |
Hi @A13k2, Thanks for reporting this issue! We’ve received it and are reviewing it. We’ll provide updates as soon as possible. |
This was referenced May 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
looking for an way to use values for the secret manager values while offline testing with firebase-functions-test.
Currently migrating to firebase functions v2. We previously used
mockConfig
with the runtimefile.The text was updated successfully, but these errors were encountered: