question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Project Id should be taken from credentials.json

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
feywindcommented, Nov 25, 2021

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 then kubectl 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.

0reactions
feywindcommented, Mar 24, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found