GeezerVison is showing github.com — keyFilename makes 12-factor app style deployment difficult · Issue #136 · googleapis/google-cloud-node
keyFilename makes 12-factor app style deployment difficult #136Labels 🚨This issue needs some love.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionI'm trying to use cloud storage which the documentation says I should initialize as such:
var gcloud = require('gcloud'),
bucket = new gcloud.storage.Bucket({
bucketName: YOUR_BUCKET_NAME,
keyFilename: '/path/to/the/key.json'
});
I dug into the code and this keyFilename option seems to be the only way to specify this required info, and it expects a filepath string. This makes storing the key's JSON as an environmental variable pretty complicated since I'd have to write the env value to a file, then pass the path to gcloud.
This seems to be a similar issue someone faced with Google APIs, a key file, and Heroku: http://ar.zu.my/how-to-store-private-key-files-in-heroku/
As he outlines, it seems there are four options, none super simple:
- Include the private key in my git repository.
- Store it in S3, and pull it when needed.
- Use custom build-pack which will include the key.
- Store it as config vars.
Even just having the option to pass this information in as a Javascript object (which makes sense for a node library) would be nice. Reacted by Michael Prentice Activityrakyll commented on Aug 26, 2014 We should never assume that key file will be read from disk. We should require it to be passed as a plain object. Any other opinions? added this to the This milestone has been deleted milestone on Aug 26, 2014silvolu commented on Aug 26, 2014 I would add a key option to pass the object, but keep the keyFilename is as well.
Some people like the 'download the key and pass the path to the constructor'™ approach, mostly in the getting started experience context. rakyll commented on Aug 26, 2014 SGTM as we discussed offline. ryanseys commented on Aug 26, 2014 Yes, both options is best. keyFilename: 'path/goes/here.json' should more or less just be an alias for key: require('path/goes/here.json') where key accepts a plain JavaScript object. rakyll commented on Aug 26, 2014 keyFilename should work the way it works (without require), otherwise it becomes impossible to specify relative paths to keyFilename. See 7641028. ryanseys commented on Aug 26, 2014 Interesting... I've never had issues with relative paths + require but I've never pushed it to its limits either. 😄
fs.readFile is definitely better anyway because it's async and won't automagically cache. 👍
hulbert commented on Aug 26, 2014 Just an end-user perspective/question, is the entire JSON really needed or is it just using the private_key value? If you were to add a key option I would potentially be confused if this is to the whole object or just the value specified for the key private_key in the downloaded JSON file.
This confusion might be worsened in my example of using environmental variables as I would likely break the JSON file into four ENV variables like so:
declared environmental vars:
GOOGLE_CLOUD_private_key_id=value
GOOGLE_CLOUD_private_key=value
GOOGLE_CLOUD_client_email=value
GOOGLE_CLOUD_client_id=value
GOOGLE_CLOUD_type=value
Initializing gcloud-node:
var gcloud = require('gcloud'),
bucket = new gcloud.storage.Bucket({
bucketName: YOUR_BUCKET_NAME,
key: {
"private_key_id": process.env.GOOGLE_CLOUD_private_key_id,
"private_key": process.env.GOOGLE_CLOUD_private_key,
"client_email": process.env.GOOGLE_CLOUD_client_email,
"client_id": process.env.GOOGLE_CLOUD_client_id,
"type": process.env.GOOGLE_CLOUD_type
}
});rakyll commented on Aug 26, 2014 We can rename the key to credentials which is basically what Connection object is doing at the moment. It's reading the file from keyFilename, parse and set it to Connection.prototype.credentials.
Btw, you only need to provide private_key and client_email.
var gcloud = require('gcloud'),
bucket = new gcloud.storage.Bucket({
bucketName: YOUR_BUCKET_NAME,
credentials: {
"private_key": process.env.GOOGLE_CLOUD_private_key,
"client_email": process.env.GOOGLE_CLOUD_client_email,
}
});hulbert commented on Aug 27, 2014 @rakyll 👍 your example would address my original issue added 3 commits that reference this issue on Aug 27, 2014This issue will close once commit a553164 is merged into the 'master' branch.a553164 This issue will close once commit 4f1313c is merged into the 'master' branch.4f1313c This issue will close once commit de4136b is merged into the 'master' branch.de4136b
MetadataMetadata🚨This issue needs some love.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|