diff --git a/lib/storage/index.js b/lib/storage/index.js index 7464c2d142b..b2a71723a0b 100644 --- a/lib/storage/index.js +++ b/lib/storage/index.js @@ -184,11 +184,18 @@ Storage.prototype.bucket = function(name) { * Create a bucket. * * @resource [Buckets: insert API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/insert} + * @resource [Durable Reduced Availability]{@link https://cloud.google.com/storage/docs/durable-reduced-availability} + * @resource [Nearline]{@link https://cloud.google.com/storage/docs/nearline} + * @resource [Storage Classes]{@link https://cloud.google.com/storage/docs/storage-classes} * * @throws {Error} If a name is not provided. * * @param {string} name - Name of the bucket to create. * @param {object=} metadata - Metadata to set for the bucket. + * @param {boolean=} metadata.dra - Specify the storage class as + * [Durable Reduced Availability](https://goo.gl/26lthK). + * @param {boolean=} metadata.nearline - Specify the storage class as + * [Nearline](https://goo.gl/sN5wNh). * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request * @param {module:storage/bucket} callback.bucket - The newly created Bucket. @@ -209,7 +216,7 @@ Storage.prototype.bucket = function(name) { * //- * var metadata = { * location: 'US-CENTRAL1', - * storageClass: 'DURABLE_REDUCED_AVAILABILITY' + * dra: true * }; * * gcs.createBucket('new-bucket', metadata, callback); @@ -240,6 +247,17 @@ Storage.prototype.createBucket = function(name, metadata, callback) { var body = extend(metadata, { name: name }); + var storageClasses = { + dra: 'DURABLE_REDUCED_AVAILABILITY', + nearline: 'NEARLINE' + }; + + Object.keys(storageClasses).forEach(function(storageClass) { + if (body[storageClass]) { + body.storageClass = storageClasses[storageClass]; + delete body[storageClass]; + } + }); this.makeReq_('POST', '', query, body, function(err, resp) { if (err) { diff --git a/test/storage/index.js b/test/storage/index.js index 15e7470d3b7..9c3957e3734 100644 --- a/test/storage/index.js +++ b/test/storage/index.js @@ -173,6 +173,23 @@ describe('Storage', function() { done(); }); }); + + it('should expand the Nearline option', function(done) { + storage.makeReq_ = function(method, path, query, body) { + assert.strictEqual(body.storageClass, 'NEARLINE'); + done(); + }; + storage.createBucket(BUCKET_NAME, { nearline: true }, function() {}); + }); + + it('should expand the Durable Reduced Availability option', function(done) { + storage.makeReq_ = function(method, path, query, body) { + assert.strictEqual(body.storageClass, 'DURABLE_REDUCED_AVAILABILITY'); + done(); + }; + storage.createBucket(BUCKET_NAME, { dra: true }, function() {}); + }); + }); describe('getBuckets', function() {