Skip to content

Environment Secrets have no value #1264

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

Closed
pjarnfelt opened this issue Oct 17, 2022 · 3 comments · Fixed by #1281
Closed

Environment Secrets have no value #1264

pjarnfelt opened this issue Oct 17, 2022 · 3 comments · Fixed by #1281

Comments

@pjarnfelt
Copy link

pjarnfelt commented Oct 17, 2022

[REQUIRED] Version info

node: v16.17.1

firebase-functions: 4.0.0

firebase-tools: 11.4.4

firebase-admin: 11.1.0

[REQUIRED] Test case

Firebase init
install latest version of admin/tools and functions. (as my versions)
import defineSecret
import { defineSecret } from "firebase-functions/params";
define functions to run with that secret
runWith({secrets:[my_secret]})
try to get the value inside the function

[REQUIRED] Steps to reproduce

import * as functions from "firebase-functions";
import { defineSecret } from "firebase-functions/params";

// Defined in GCloud or not, we just don't have access to its value!
const my_secret = defineSecret("my_secret");
// Remember to define runWith the secrets, (here only one in the array) 
// as it should only be pupulated at runtime from GCloud
export const helloWorld = functions.runWith({secrets:[my_secret]}).https.onRequest((request, response) => {
  my_secret.value(); // Property 'value' does not exist on type 'SecretParam'.ts(2339)
});

now
my_secret.value();
is undefined. SecretParam (the thing defineSecret returns) only has a .name parameter, no .value()

[REQUIRED] Expected behavior

Expected to be able to reference .value() method as per the documentation
https://firebase.google.com/docs/functions/config-env

[REQUIRED] Actual behavior

cannot access the value :(
*Property 'value' does not exist on type 'SecretParam'.ts(2339)

Were you able to successfully deploy your functions?

no

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@jhuleatt
Copy link
Contributor

Thanks for reporting this @pjarnfelt! I believe a temporary workaround could be to access the underlying environment variable directly:

import * as functions from "firebase-functions";
import { defineSecret } from "firebase-functions/params";

// Defined in GCloud or not, we just don't have access to its value!
const my_secret = defineSecret("my_secret");
// Remember to define runWith the secrets, (here only one in the array) 
// as it should only be pupulated at runtime from GCloud
export const helloWorld = functions.runWith({secrets:[my_secret]}).https.onRequest((request, response) => {
-  my_secret.value(); // Property 'value' does not exist on type 'SecretParam'.ts(2339)
+  const mySecretVal = process.env[my_secret.name]; 
});

@Berlioz, unlike the other param types (StringParam, IntParam, etc), SecretParam doesn't extend Param, so it doesn't pick up the value method from the Expression class. Therefore, at the moment it seems the only way to access the value of a secret param is to manually check the environment variable.

String:

export class StringParam extends Param<string> {

Secret:

export class SecretParam {

@jhuleatt
Copy link
Contributor

jhuleatt commented Nov 1, 2022

The fix for this was released in 4.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants