Project Id should be taken from credentials.json
See original GitHub issueIs your feature request related to a problem? Please describe. Yes. If just using
const credentials = require('./cred.json'); // cred from IAM service account key
new PubSub({credentials})
the following error will be thrown:
UnhandledPromiseRejectionWarning: Error: Unable to detect a Project Id in the current environment.
To learn more about authentication and Google APIs, visit:
https://cloud.google.com/docs/authentication/getting-started
at /home/hb/Dev/Contador-de-Clientes-Firebase/admin/node_modules/google-auth-library/build/src/auth/googleauth.js:87:31
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:216511) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:216511) [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.
Describe the solution you’d like
It should use the project_id
from the service account credentials.json
Describe alternatives you’ve considered
I am, as workaround, using credentials.project_id
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Figure out projectID for GCS automatically from credentials. ...
project ID is currently mandatory in the command line. Your Environment. Version used ( minio version ):; Environment name and version (e.g. ...
Read more >Create and manage service account keys - IAM
Note: You can create service account keys in JSON or PKCS#12 (P12) format. ... your service account, and PROJECT_ID is the ID of...
Read more >python - How do I get projectId from GoogleCredentials?
Given that the projectId exists in the JSON keyfile I had hoped I could obtain it simply be interrogating a property of the...
Read more >Create access credentials | Google Workspace
OAuth client ID credentials · In the Google Cloud console, go to Menu menu > APIs & Services > Credentials. · Click Create...
Read more >File: AUTHENTICATION — Gcloud
The Project ID and Credentials JSON can be placed in environment variables instead of declaring them directly in code. Each service has its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I wonder if there has been a change in recommendation since this issue first opened. Last I heard, using a service key file was the right way to do it, but that may not be needed in e.g. GKE. I know with a recent test project I was able to use
gcloud auth login
and thenkubectl apply
to get a container running with access to my project.I don’t think many people are around today but I can post the question to see if anyone knows more.
There hasn’t been much more traffic on this one (and I think the answers above are the right path), so I’m going to close it out.