Skip to content
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

"Could not load the default credentials" when using custom apiEndpoint. #1373

Closed
jpambrun opened this issue Jan 4, 2021 · 3 comments · Fixed by #1459
Closed

"Could not load the default credentials" when using custom apiEndpoint. #1373

jpambrun opened this issue Jan 4, 2021 · 3 comments · Fixed by #1459
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@jpambrun
Copy link

jpambrun commented Jan 4, 2021

  • OS: Linux
  • Node.js version: v12.19.0
  • npm version: 6.14.8
  • @google-cloud/storage version: 5.7.0

Steps to reproduce

  1. Start the GCP emulator docker image fsouza/fake-gcs-server with sh - c 'mkdir -p /data/bucketname && touch /data/bucketname/.keep && /bin/fake-gcs-server -scheme http -port 80 -data /data' as entrypoint.
  2. Run
const {Storage} = require('@google-cloud/storage');
storage = new Storage({
        apiEndpoint: 'http://google-cloud-storage.gcp-emu', // whatever IP/domain needed to reach the emulator of step 1.
        projectId: 'gcp-emu-prj',
});

(async () => {
        const [files] = await storage.bucket('vision-poc').getFiles();
        console.log(files) // works, I can see the .keep file.
        await storage.bucket('vision-poc').file('my-file').save('test from js');
})();

On the save() call I get:

(node:958) UnhandledPromiseRejectionWarning: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.getApplicationDefaultAsync (/root/node_modules/google-auth-library/build/src/auth/googleauth.js:157:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async GoogleAuth.getClient (/root/node_modules/google-auth-library/build/src/auth/googleauth.js:490:17)
    at async GoogleAuth.request (/root/node_modules/google-auth-library/build/src/auth/googleauth.js:543:24)
    at async Upload.makeRequest (/root/node_modules/gcs-resumable-upload/build/src/index.js:320:21)
    at async Upload.createURIAsync (/root/node_modules/gcs-resumable-upload/build/src/index.js:145:22)
(node:958) 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)

I don't expect any attempt to load credentials since I am supplying a custom API endpoint.
Maybe related to fsouza/fake-gcs-server#218, #898, #1315.

It looks like #1316 was meant to fix it?

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Jan 4, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Jan 5, 2021
@shaffeeullah shaffeeullah added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 7, 2021
@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Jan 7, 2021
@ashokkumarsand
Copy link

I am also facing the same issue.

@shaffeeullah shaffeeullah added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 31, 2021
@shaffeeullah
Copy link
Contributor

This error is occurring because authentication bypass for resumable uploads is not currently supported. A potential workaround for this issue is to add {resumable: false} as the second parameter to your File.save call.

@KieranHarper
Copy link

I have noticed this occurring in version 6.0.1 today when using getSignedUrl for an upload. It will only succeed in giving you a url if you have credentials. Other calls are respecting apiEndpoint. My quick workaround was to manually construct a fake url instead, because this is just for a test env using fsouza/fake-gcs-server as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants