Skip to content

Commit

Permalink
Don't crash if no home directory in ensureDefaultCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
mbleigh committed Jan 29, 2018
1 parent 583febd commit f121d5b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/ensureDefaultCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var path = require('path');
var api = require('./api');
var configstore = require('./configstore');
var fsutils = require('./fsutils');
var logger = require('./logger');

var configDir = function() {
// Windows has a dedicated low-rights location for apps at ~/Application Data
Expand All @@ -15,14 +16,19 @@ var configDir = function() {
return process.env.HOME && path.resolve(process.env.HOME, '.config');
};

var GCLOUD_CREDENTIAL_DIR = path.resolve(configDir(), 'gcloud');
var GCLOUD_CREDENTIAL_PATH = path.join(GCLOUD_CREDENTIAL_DIR, 'application_default_credentials.json');

/*
Ensures that default credentials are available on the local machine, as specified by:
https://developers.google.com/identity/protocols/application-default-credentials
*/
module.exports = function() {
if (!configDir()) {
logger.debug('Cannot ensure default credentials, no home directory found.');
return;
}

var GCLOUD_CREDENTIAL_DIR = path.resolve(configDir(), 'gcloud');
var GCLOUD_CREDENTIAL_PATH = path.join(GCLOUD_CREDENTIAL_DIR, 'application_default_credentials.json');

if (fsutils.fileExistsSync(GCLOUD_CREDENTIAL_PATH)) { return; }
var credentials = {
client_id: api.clientId,
Expand Down

0 comments on commit f121d5b

Please sign in to comment.