diff --git a/README.md b/README.md index 890c6bf7d42..a2af3b5a0c0 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,13 @@ If you are not running this client on Google Compute Engine, you need a Google D * Google Cloud Storage JSON API * Google Cloud Pub/Sub * Once API access is enabled, switch back to "APIs & auth" section on the navigation panel and switch to "Credentials" page. -* Click on "Create new client ID" to create a new **service account**. Once the account is created, a p12 file will be auto downloaded. You need to run the following command to convert this file to a pem file. +* Click on "Create new client ID" to create a new **service account**. Once the account is created, click on "Generate new JSON key" to download +your private key. -~~~~ sh -openssl pkcs12 -in -nocerts -passin pass:notasecret -nodes -out -~~~~ - -The pem file is the private key you'll need for authorization. +The downloaded file contains credentials you'll need for authorization. * You'll the following for auth configuration: * Developers Console project's ID (e.g. bamboo-shift-455) - * Service account's email address (e.g. xxx@developer.gserviceaccount.com) - * The path to the pem file. + * The path to the JSON key file. ## Developer's Guide @@ -92,8 +88,7 @@ Elsewhere, initiate with project ID, service account's email and private key dow var gcloud = require('gcloud'), ds = new gcloud.datastore.Dataset({ projectId: YOUR_PROJECT_ID, - email: 'xxx@developer.gserviceaccount.com', - pemFilePath: '/path/to/the/pem/private/key.pem' + keyFilename: '/path/to/the/key.json' }); ~~~~ @@ -295,9 +290,8 @@ Elsewhere, initiate with bucket's name, service account's email and private key ~~~~ js var gcloud = require('gcloud'), bucket = new gcloud.storage.Bucket({ - bucketName: YOUR_BUCKET_NAME, - email: 'xxx@developer.gserviceaccount.com', - pemFilePath: '/path/to/the/pem/private/key.pem' + projectId: YOUR_PROJECT_ID, + keyFilename: '/path/to/the/key.json' }); ~~~~ diff --git a/lib/common/connection.js b/lib/common/connection.js index 850ac211ab7..792db331b8b 100644 --- a/lib/common/connection.js +++ b/lib/common/connection.js @@ -44,12 +44,13 @@ Token.prototype.isExpired = function() { }; /** - * @param {Object} opts Options. { email, privateKey, scopes } + * @param {Object} opts Options. */ function Connection(opts) { - // TODO: If no email and key is provided, use metaserver to retrieve a new token. - this.email = opts.email; // client email for the service account - this.privateKey = opts.privateKey; // contains the contents of a pem file + var credentials = opts.keyFilename && require(opts.keyFilename) || {}; + this.email = credentials['client_email']; // client email for the service account + this.privateKey = credentials['private_key']; // contains the contents of a pem file + this.scopes = opts.scopes || []; this.token = null; // existing access token, if exists @@ -106,7 +107,7 @@ Connection.prototype.fetchToken = function(callback) { } var gapi = new GAPIToken({ iss: this.email, - keyFile: this.privateKey, + key: this.privateKey, scope: this.scopes.join(' ') }, function(err) { if (err) { diff --git a/lib/datastore/index.js b/lib/datastore/index.js index cde919ac085..7d54d38ea1a 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -313,9 +313,9 @@ Transaction.prototype.makeReq = function(method, req, callback) { * Creates a new dataset with the provided options. * @param {object} opts Dataset identifier options. * @param {string} opts.id Dataset ID, this is your project ID - * from Google Developer Console. - * @param {string} opts.email Client email of the service account. - * @param {string} opts.pemFilepath The path to the pem file. + * from Google Developers Console. + * @param {string} opts.keyFilename Path to the JSON key file downloaded from + * Google Developers Console. */ function Dataset(opts) { opts = opts || {}; @@ -327,8 +327,7 @@ function Dataset(opts) { this.id = id; this.transaction = new Transaction(new conn.Connection({ - email: opts.email, - privateKey: opts.pemFilePath, + keyFilename: opts.keyFilename, scopes: SCOPES }), this.id); } diff --git a/lib/pubsub/index.js b/lib/pubsub/index.js index bac855e79dc..ebaeb838fdc 100644 --- a/lib/pubsub/index.js +++ b/lib/pubsub/index.js @@ -219,8 +219,7 @@ function Connection(opts) { this.id = id; this.conn = new conn.Connection({ - email: opts.email, - privateKey: opts.pemFilePath, + keyFilename: opts.keyFilename, scopes: SCOPES }); } diff --git a/lib/storage/index.js b/lib/storage/index.js index 33b30a5ee54..1959a28d7ad 100644 --- a/lib/storage/index.js +++ b/lib/storage/index.js @@ -148,8 +148,7 @@ ReadStream.prototype.pipe = function(dest, opts) { function Bucket(opts) { this.bucketName = opts.bucketName; this.conn = new conn.Connection({ - email: opts.email, - privateKey: opts.pemFilePath, + keyFilename: opts.keyFilename, scopes: SCOPES }); } diff --git a/regression/datastore.js b/regression/datastore.js index 2ab73c9fdc0..eb7c50ea656 100644 --- a/regression/datastore.js +++ b/regression/datastore.js @@ -14,18 +14,11 @@ * limitations under the License. */ -var env = require('./env.js'), - projectId = env.projectId, - email = env.serviceAccount, - pemFilePath = env.pemKey; +var env = require('./env.js'); var assert = require('assert'), datastore = require('../lib/datastore'), - ds = new datastore.Dataset({ - projectId: projectId, - email: email, - pemFilePath: pemFilePath - }); + ds = new datastore.Dataset(env); describe('datastore', function() { diff --git a/regression/env.js b/regression/env.js index c15ec8c3835..df20e9ec2fd 100644 --- a/regression/env.js +++ b/regression/env.js @@ -15,8 +15,7 @@ */ if (!process.env.GCLOUD_TESTS_PROJECT_ID && - !process.env.GCLOUD_TESTS_SERVICE_ACCOUNT && - !process.env.GCLOUD_TESTS_PEM_KEY) { + !process.env.GCLOUD_TESTS_KEY) { var error = ['To run the regression tests, you need to set the value of some environment variables.', 'Please check the README for instructions.' ].join('\n'); @@ -25,6 +24,5 @@ if (!process.env.GCLOUD_TESTS_PROJECT_ID && module.exports = { projectId: process.env.GCLOUD_TESTS_PROJECT_ID, - serviceAccount: process.env.GCLOUD_TESTS_SERVICE_ACCOUNT, - pemKey: process.env.GCLOUD_TESTS_PEM_KEY + keyFilename: process.env.GCLOUD_TESTS_KEY }; diff --git a/regression/pubsub.js b/regression/pubsub.js index a9518f1368d..add137e583f 100644 --- a/regression/pubsub.js +++ b/regression/pubsub.js @@ -29,11 +29,7 @@ var subscriptions = [{ ackDeadlineSeconds: 60 }]; -var conn = new gcloud.pubsub.Connection({ - projectId: env.projectId, - email: env.serviceAccount, - pemFilePath: env.pemKey, -}); +var conn = new gcloud.pubsub.Connection(env); before(function(done) { // TODO: Handle pagination.