2

I've just migrated to Cloud Functions 1.0 and am trying out Cloud Functions shell/emulator to run functions locally (using instructions at https://firebase.google.com/docs/functions/local-emulator)

One of the functions is using code below to upload a file to cloud storage and then then generate url for it....but am getting following error:

SigningError: Cannot sign data without client_email.

const bucket = gcs.bucket(bucketName);

bucket.upload(localFilePath, {destination: destinationPath})
    .then(data => {
      const file = data[0];
      return file.getSignedUrl({
        action: 'read',
        expires: '01-01-2099'
      });

I can work around this locally by explicitly setting keyFileName as shown below but seems like this should not be necessary

const gcs = require('@google-cloud/storage')({keyFilename: 'service-account.json'});

The link above mentions that "Cloud Firestore and Realtime Database triggers already have sufficient credentials, and do not require additional setup" (I'm triggering this code from db write). I'm setting GOOGLE_APPLICATION_CREDENTIALS env variable in any case but doesn't look like it's picking it up.

John O'Reilly
  • 10,000
  • 4
  • 41
  • 63
  • Use of getSignedUrl requires a service account anyway. – Doug Stevenson Apr 15 '18 at 17:26
  • @DougStevenson this issue is specific to when I use `firebase functions:shell` - it works ok when deployed. Also I am calling `getSignedUrl` as per code in question. – John O'Reilly Apr 15 '18 at 17:28
  • I don't believe you can set arbitrary env vars to be used in the emulator. That's managed by the CLI. – Doug Stevenson Apr 15 '18 at 17:30
  • @DougStevenson what do you mean by "arbitrary env vars" in this case? I guess putting it another way, what is recommended way of addressing this using Cloud Functions Shell. All other functionality seems to be working file (and am setting `GOOGLE_APPLICATION_CREDENTIALS` as per instructions in the link I mentioned) – John O'Reilly Apr 15 '18 at 17:32
  • I had seen the question you marked this as duplicate of before....but I believe this issue is different and is related to running functions locally (and perhaps with use of v1.0). – John O'Reilly Apr 15 '18 at 17:36
  • The recommendation is to initialize the SDK with service account credentials from a file (as you already know works), or configure them using env vars that are specific to Cloud Functions for Firebase. Don't try to set a shell env var. https://firebase.google.com/docs/functions/config-env – Doug Stevenson Apr 15 '18 at 17:40
  • I don't believe I'm trying to "set a shell env var"....the only env var I'm setting is GOOGLE_APPLICATION_CREDENTIALS to point to json file with service account info (as per https://firebase.google.com/docs/functions/local-emulator). – John O'Reilly Apr 15 '18 at 17:42
  • That *is* a shell env var. If you think there's a bug here, please file a bug report detailing the exact steps you're taking, and how it's not working the way you expect. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Apr 15 '18 at 17:49
  • 1
    If that's the case case doesn't "Don't try to set a shell env var" go against instructions in https://firebase.google.com/docs/functions/local-emulator (in the "To set up admin credentials for emulated functions" section). In any case, will keep investigating here (and have reasonable workaround in meantime> – John O'Reilly Apr 15 '18 at 17:51
  • It's not the approach I would take to build functions that work both locally and deployed to Cloud Functions, as you don't have any control over the shell environment in the latter. I suppose if you only wanted to run locally, the env vat approach might be helpful, but if I was only going to run locally, I wouldn't be using Cloud Functions anyway. – Doug Stevenson Apr 15 '18 at 17:55
  • "you don't have any control over the shell environment in the latter"....the point of my issue is that I'm trying actually to avoid having to do that....to *not* to have to set any local env vars/change code locally. Rather I want to run functions locally and for them to use/have access to implicit vars that are set when run in cloud (and it seems use of `GOOGLE_APPLICATION_CREDENTIALS` is recommended way of providing that sort of "abstraction" when running locally...along with use btw of `firebase functions:config:get > .runtimeconfig.json`). – John O'Reilly Apr 15 '18 at 18:16
  • Personally, I've never run into the need for that. – Doug Stevenson Apr 15 '18 at 18:22
  • Hi @John. Did you ever find out how to get this to work? I am running the local emulators of the Cloud Functions & Firebase Storage now, but I got the same error "Cannot sign data without `client_email`" I already follow the instruction from the docs to `set GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account.json"` but it doesn't seem to resolve the issue. – timthekoder May 28 '21 at 19:26

0 Answers0