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

Credentials path fails to expand tilde to home directory on Windows. #99

Open
JadenH opened this issue Apr 9, 2018 · 2 comments
Open

Comments

@JadenH
Copy link

JadenH commented Apr 9, 2018

References: nodejs/node#684
Node Version: 9.5.0

googleProvider.js

let credentials = this.serverless.service.provider.credentials;
const credParts = credentials.split(path.sep);

if (credParts[0] === '~') {
  credParts[0] = os.homedir();
  credentials = credParts.reduce((memo, part) => path.join(memo, part), '');
}

const keyFileContent = fs.readFileSync(credentials).toString();
const key = JSON.parse(keyFileContent);

credentials.split(path.sep) does not appear to be splitting the path as expected.

C:\> node --version
v9.5.0
C:\> node
> let credentials = "~/.gcloud/keyfile.json"
undefined
> const credParts = credentials.split(path.sep);
undefined
> credParts
[ '~/.gcloud/keyfile.json' ]
> credParts[0]
'~/.gcloud/keyfile.json'
> const keyFileContent = fs.readFileSync(credentials).toString();
Error: ENOENT: no such file or directory, open 'C:\~\.gcloud\keyfile.json'
    at Object.fs.openSync (fs.js:663:18)
    at Object.fs.readFileSync (fs.js:568:33)
@aaronkchsu
Copy link

YA this would be super nice to look into.. because it is causing me a lot of problems!

@dobromyslov
Copy link

This occurs because path.sep is \ when Node.js is running on Windows.
You have to change path separator in your credentials "~/.gcloud/keyfile.json" from / to windows-style \ like below.

serverless.yml:

provider:
  name: google
  ...
  #credentials: ~/.gcloud/keyfile.json # Unix-style path
  credentials: ~\.gcloud\keyfile.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants