Skip to content

Commit 0b901c1

Browse files
Merge pull request #787 from callmehiphop/storage-class
storage: add storage class enums
2 parents 173c5f9 + 5dd3151 commit 0b901c1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/storage/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,18 @@ Storage.prototype.bucket = function(name) {
184184
* Create a bucket.
185185
*
186186
* @resource [Buckets: insert API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/insert}
187+
* @resource [Durable Reduced Availability]{@link https://cloud.google.com/storage/docs/durable-reduced-availability}
188+
* @resource [Nearline]{@link https://cloud.google.com/storage/docs/nearline}
189+
* @resource [Storage Classes]{@link https://cloud.google.com/storage/docs/storage-classes}
187190
*
188191
* @throws {Error} If a name is not provided.
189192
*
190193
* @param {string} name - Name of the bucket to create.
191194
* @param {object=} metadata - Metadata to set for the bucket.
195+
* @param {boolean=} metadata.dra - Specify the storage class as
196+
* [Durable Reduced Availability](https://goo.gl/26lthK).
197+
* @param {boolean=} metadata.nearline - Specify the storage class as
198+
* [Nearline](https://goo.gl/sN5wNh).
192199
* @param {function} callback - The callback function.
193200
* @param {?error} callback.err - An error returned while making this request
194201
* @param {module:storage/bucket} callback.bucket - The newly created Bucket.
@@ -209,7 +216,7 @@ Storage.prototype.bucket = function(name) {
209216
* //-
210217
* var metadata = {
211218
* location: 'US-CENTRAL1',
212-
* storageClass: 'DURABLE_REDUCED_AVAILABILITY'
219+
* dra: true
213220
* };
214221
*
215222
* gcs.createBucket('new-bucket', metadata, callback);
@@ -240,6 +247,17 @@ Storage.prototype.createBucket = function(name, metadata, callback) {
240247
var body = extend(metadata, {
241248
name: name
242249
});
250+
var storageClasses = {
251+
dra: 'DURABLE_REDUCED_AVAILABILITY',
252+
nearline: 'NEARLINE'
253+
};
254+
255+
Object.keys(storageClasses).forEach(function(storageClass) {
256+
if (body[storageClass]) {
257+
body.storageClass = storageClasses[storageClass];
258+
delete body[storageClass];
259+
}
260+
});
243261

244262
this.makeReq_('POST', '', query, body, function(err, resp) {
245263
if (err) {

test/storage/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ describe('Storage', function() {
173173
done();
174174
});
175175
});
176+
177+
it('should expand the Nearline option', function(done) {
178+
storage.makeReq_ = function(method, path, query, body) {
179+
assert.strictEqual(body.storageClass, 'NEARLINE');
180+
done();
181+
};
182+
storage.createBucket(BUCKET_NAME, { nearline: true }, function() {});
183+
});
184+
185+
it('should expand the Durable Reduced Availability option', function(done) {
186+
storage.makeReq_ = function(method, path, query, body) {
187+
assert.strictEqual(body.storageClass, 'DURABLE_REDUCED_AVAILABILITY');
188+
done();
189+
};
190+
storage.createBucket(BUCKET_NAME, { dra: true }, function() {});
191+
});
192+
176193
});
177194

178195
describe('getBuckets', function() {

0 commit comments

Comments
 (0)