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

storage: add storage class enums #787

Merged
merged 1 commit into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions test/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down