fredriks/cloud-functions-runtime-config

Add GCLOUD_PROJECT to README.md and throw error if missing

joshunger opened this issue · 11 comments

It would be helpful to add GCLOUD_PROJECT to README.md and also throw an error if this is undefined. Thanks for the instructions and project! Working great.

Happy to! Never heard of it though so I'd appreciate any documentation references for how it is used and when it applies 😄

Created a PR for the throwing a new error #9

I guess GOOGLE_CLOUD_PROJECT is the new variable to be used and GCLOUD_PROJECT is being deprecated?

See Jon Skeet's comment in googleapis/gax-dotnet#218

In what context is this environment variable used? That seem to be the .NET extensions whereas this is nodejs. Is this value always available in the CF environment?

Great question. Does this answer it -

https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/src/utils/detectProjectId.js

Oddly, they favored GCLOUD_PROJECT over GOOGLE_CLOUD_PROJECT for some reason? Any ideas?

Here are the examples I was looking at for you -

https://github.com/search?l=JavaScript&q=org%3AGoogleCloudPlatform+GOOGLE_CLOUD_PROJECT&type=Code

Interesting! Thanks for providing the references, I'll have a look!

What was the context where you needed to provide the value and what error (if any) did you run into?

Ah good question.

I never ran gcloud auth application-default login or glcoud init since I downloaded service account .json credentials.

So, when I ran your code it tried to use undefined in the URL.

You get this exception -

(node:40972) UnhandledPromiseRejectionWarning: Error: Permission denied on resource project undefined.
    at createError (webpack:////Users/junger/dev/pencilled/node_modules/axios/lib/core/createError.js?:16:15)
    at settle (webpack:////Users/junger/dev/pencilled/node_modules/axios/lib/core/settle.js?:18:12)
    at IncomingMessage.handleStreamEnd (webpack:////Users/junger/dev/pencilled/node_modules/axios/lib/adapters/http.js?:201:11)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)
(node:40972) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:40972) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Perfect, thanks for this!

Seeing that the variable doesn't seem to be documented in any of the official Cloud Functions docs and that the backing libraries throw an exception anyway I'm inclined to not enforce it but rather add this info to the README as you suggest. Either a section for "How to run locally/outside GCP" or "Troubleshooting" for when the above error presents itself. A reminder to run gcloud auth application-default login, gcloud init or to set GCLOUD_PROJECT in cases where it is expected.

What do you think?

Sounds good to me.