fredriks/cloud-functions-runtime-config

Default credentials in Cloud Functions throws Not Found

martijnvdbrug opened this issue · 2 comments

Hi,

Very usefull library you have here, thanks for that.

This library worked fine for me, untill today. It seems to be related to a new Cloud Function environment:

Error: A Not Found error was returned while attempting to retrieve an accesstoken for the Compute Engine built-in service account. This may be because the Compute Engine instance does not have any permission scopes specified. Requested entity was not found. at createError (/user_code/node_modules/googleapis/node_modules/axios/lib/core/createError.js:16:15) at settle (/user_code/node_modules/googleapis/node_modules/axios/lib/core/settle.js:18:12) at IncomingMessage.handleStreamEnd (/user_code/node_modules/googleapis/node_modules/axios/lib/adapters/http.js:201:11) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

Even though this is probably related to the Cloud Function environment and not your library, it could still be usefull to have the option to pass a keyFile.json to your library, instead of using the env default credentials:

      const key = require('path/to/file.json');
      const jwtClient = new google.auth.JWT(
        key.client_email,
        null,
        key.private_key,
        ['https://www.googleapis.com/auth/cloud-platform',
          'https://www.googleapis.com/auth/cloudruntimeconfig'], // an array of auth scopes
        null
      );

      jwtClient.authorize(function (err, tokens) {
        if (err) {
          console.log(err);
          return;
        }
      });

      return Promise.resolve(jwtClient);
    }

Anyhow, thanks again for creating this library :)

Thanks! Supporting more auth options would be sweet as that should also make the library more usable in environments outside of Cloud Functions (though might have to rename it then 😆).

Havn't had to use anything other than the default credentials myself yet so don't have any implementations lying around but since the library is basically just calling into googleapi we could expose those bits to make it pluggable to support any authentication options. Pull requests are welcome!

Regarding your error though, it looks suspiciously similar to #5.

That does seem to be the same issue indeed :). I will close this one!