Skip to content

Commit b398773

Browse files
update tests + docs
1 parent b8f2b2f commit b398773

2 files changed

Lines changed: 187 additions & 145 deletions

File tree

lib/storage/bucket.js

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ Bucket.prototype.getMetadata = function(callback) {
411411
};
412412

413413
/**
414-
* Make the bucket publicly readable.
414+
* Make the bucket listing private.
415415
*
416-
* You may also choose to make the contents of the bucket publicly readable by
417-
* specifying `includeFiles: true`. This will automatically run
418-
* {module:storage/file#makePublic} for every file in the bucket.
416+
* You may also choose to make the contents of the bucket private by specifying
417+
* `includeFiles: true`. This will automatically run
418+
* {module:storage/file#makePrivate} for every file in the bucket.
419419
*
420420
* When specifying `includeFiles: true`, use `force: true` to delay execution of
421421
* your callback until all files have been processed. By default, the callback
@@ -427,51 +427,51 @@ Bucket.prototype.getMetadata = function(callback) {
427427
* requests. Use with caution.
428428
*
429429
* @param {object=} options - The configuration object.
430-
* @param {boolean} options.includeFiles - Make each file in the bucket publicly
431-
* readable. Default: `false`.
430+
* @param {boolean} options.includeFiles - Make each file in the bucket private.
431+
* Default: `false`.
432432
* @param {boolean} options.force - Queue errors occurred while making files
433-
* public until all files have been processed.
433+
* private until all files have been processed.
434434
* @param {function} callback - The callback function.
435435
*
436436
* @example
437437
* //-
438-
* // Make the bucket publicly readable.
438+
* // Make the bucket private.
439439
* //-
440-
* bucket.makePublic(function(err) {});
440+
* bucket.makePrivate(function(err) {});
441441
*
442442
* //-
443-
* // Make the bucket and its contents publicly readable.
443+
* // Make the bucket and its contents private.
444444
* //-
445445
* var opts = {
446446
* includeFiles: true
447447
* };
448448
*
449-
* bucket.makePublic(opts, function(err, files) {
449+
* bucket.makePrivate(opts, function(err, files) {
450450
* // `err`:
451451
* // The first error to occur, otherwise null.
452452
* //
453453
* // `files`:
454-
* // Array of files successfully made public in the bucket.
454+
* // Array of files successfully made private in the bucket.
455455
* });
456456
*
457457
* //-
458-
* // Make the bucket and its contents publicly readable, using force to
459-
* // suppress errors until all files have been processed.
458+
* // Make the bucket and its contents private, using force to suppress errors
459+
* // until all files have been processed.
460460
* //-
461461
* var opts = {
462462
* includeFiles: true,
463463
* force: true
464464
* };
465465
*
466-
* bucket.makePublic(opts, function(errors, files) {
466+
* bucket.makePrivate(opts, function(errors, files) {
467467
* // `errors`:
468468
* // Array of errors if any occurred, otherwise null.
469469
* //
470470
* // `files`:
471-
* // Array of files successfully made public in the bucket.
471+
* // Array of files successfully made private in the bucket.
472472
* });
473473
*/
474-
Bucket.prototype.makePublic = function(options, callback) {
474+
Bucket.prototype.makePrivate = function(options, callback) {
475475
var self = this;
476476

477477
if (util.is(options, 'function')) {
@@ -480,27 +480,15 @@ Bucket.prototype.makePublic = function(options, callback) {
480480
}
481481

482482
options = options || {};
483-
options.public = true;
483+
options.private = true;
484484

485-
async.parallel([
486-
setPredefinedAcl,
487-
addAclPermissions,
488-
makeFilesPublic
489-
], callback);
485+
async.parallel([setPredefinedAcl, makeFilesPrivate], callback);
490486

491487
function setPredefinedAcl(done) {
492488
self.setPredefinedAcl_(options, done);
493489
}
494490

495-
function addAclPermissions(done) {
496-
// Allow reading bucket contents while preserving original permissions.
497-
self.acl.default.add({
498-
entity: 'allUsers',
499-
role: 'READER'
500-
}, done);
501-
}
502-
503-
function makeFilesPublic(done) {
491+
function makeFilesPrivate(done) {
504492
if (!options.includeFiles) {
505493
done();
506494
return;
@@ -511,11 +499,11 @@ Bucket.prototype.makePublic = function(options, callback) {
511499
};
512500

513501
/**
514-
* Make the bucket listing private.
502+
* Make the bucket publicly readable.
515503
*
516-
* You may also choose to make the contents of the bucket private by specifying
517-
* `includeFiles: true`. This will automatically run
518-
* {module:storage/file#makePrivate} for every file in the bucket.
504+
* You may also choose to make the contents of the bucket publicly readable by
505+
* specifying `includeFiles: true`. This will automatically run
506+
* {module:storage/file#makePublic} for every file in the bucket.
519507
*
520508
* When specifying `includeFiles: true`, use `force: true` to delay execution of
521509
* your callback until all files have been processed. By default, the callback
@@ -527,51 +515,51 @@ Bucket.prototype.makePublic = function(options, callback) {
527515
* requests. Use with caution.
528516
*
529517
* @param {object=} options - The configuration object.
530-
* @param {boolean} options.includeFiles - Make each file in the bucket private.
531-
* Default: `false`.
518+
* @param {boolean} options.includeFiles - Make each file in the bucket publicly
519+
* readable. Default: `false`.
532520
* @param {boolean} options.force - Queue errors occurred while making files
533-
* private until all files have been processed.
521+
* public until all files have been processed.
534522
* @param {function} callback - The callback function.
535523
*
536524
* @example
537525
* //-
538-
* // Make the bucket private.
526+
* // Make the bucket publicly readable.
539527
* //-
540-
* bucket.makePrivate(function(err) {});
528+
* bucket.makePublic(function(err) {});
541529
*
542530
* //-
543-
* // Make the bucket and its contents private.
531+
* // Make the bucket and its contents publicly readable.
544532
* //-
545533
* var opts = {
546534
* includeFiles: true
547535
* };
548536
*
549-
* bucket.makePrivate(opts, function(err, files) {
537+
* bucket.makePublic(opts, function(err, files) {
550538
* // `err`:
551539
* // The first error to occur, otherwise null.
552540
* //
553541
* // `files`:
554-
* // Array of files successfully made private in the bucket.
542+
* // Array of files successfully made public in the bucket.
555543
* });
556544
*
557545
* //-
558-
* // Make the bucket and its contents private, using force to suppress errors
559-
* // until all files have been processed.
546+
* // Make the bucket and its contents publicly readable, using force to
547+
* // suppress errors until all files have been processed.
560548
* //-
561549
* var opts = {
562550
* includeFiles: true,
563551
* force: true
564552
* };
565553
*
566-
* bucket.makePrivate(opts, function(errors, files) {
554+
* bucket.makePublic(opts, function(errors, files) {
567555
* // `errors`:
568556
* // Array of errors if any occurred, otherwise null.
569557
* //
570558
* // `files`:
571-
* // Array of files successfully made private in the bucket.
559+
* // Array of files successfully made public in the bucket.
572560
* });
573561
*/
574-
Bucket.prototype.makePrivate = function(options, callback) {
562+
Bucket.prototype.makePublic = function(options, callback) {
575563
var self = this;
576564

577565
if (util.is(options, 'function')) {
@@ -580,15 +568,27 @@ Bucket.prototype.makePrivate = function(options, callback) {
580568
}
581569

582570
options = options || {};
583-
options.private = true;
571+
options.public = true;
584572

585-
async.parallel([setPredefinedAcl, makeFilesPrivate], callback);
573+
async.parallel([
574+
setPredefinedAcl,
575+
addAclPermissions,
576+
makeFilesPublic
577+
], callback);
586578

587579
function setPredefinedAcl(done) {
588580
self.setPredefinedAcl_(options, done);
589581
}
590582

591-
function makeFilesPrivate(done) {
583+
function addAclPermissions(done) {
584+
// Allow reading bucket contents while preserving original permissions.
585+
self.acl.default.add({
586+
entity: 'allUsers',
587+
role: 'READER'
588+
}, done);
589+
}
590+
591+
function makeFilesPublic(done) {
592592
if (!options.includeFiles) {
593593
done();
594594
return;
@@ -765,6 +765,23 @@ Bucket.prototype.upload = function(localPath, options, callback) {
765765
}
766766
};
767767

768+
/**
769+
* Iterate over all of a bucket's files, calling `file.makePublic()` (public)
770+
* or `file.makePrivate()` (private) on each.
771+
*
772+
* Operations are performed in parallel, up to 10 at once. The first error
773+
* breaks the loop, and will execute the provided callback with it. Specify
774+
* `{ force: true }` to suppress the errors.
775+
*
776+
* @private
777+
*
778+
* @param {object} options - Configuration object.
779+
* @param {boolean} options.force - Supress errors until all files have been
780+
* processed.
781+
* @param {boolean} options.private - Make files private.
782+
* @param {boolean} options.public - Make files public.
783+
* @param {function} callback - The callback function.
784+
*/
768785
Bucket.prototype.makeAllFilesPublicPrivate_ = function(options, callback) {
769786
var self = this;
770787

@@ -831,6 +848,18 @@ Bucket.prototype.makeAllFilesPublicPrivate_ = function(options, callback) {
831848
}
832849
};
833850

851+
/**
852+
* Set the predefinedAcl for this bucket to `publicRead` (public) or
853+
* `projectPrivate` (private).
854+
*
855+
* This will also update the metadata on the object with the APIresponse.
856+
*
857+
* @private
858+
*
859+
* @param {object} options - Configuration object.
860+
* @param {boolean} options.private - Set the predefinedAcl to projectPrivate.
861+
* @param {boolean} options.public - Set the predefinedAcl to publicRead.
862+
*/
834863
Bucket.prototype.setPredefinedAcl_ = function(options, callback) {
835864
var self = this;
836865

0 commit comments

Comments
 (0)