@@ -50,43 +50,44 @@ function Acl(options) {
50
50
/**
51
51
* Add access controls on a {module:storage/bucket} or {module:storage/file}.
52
52
*
53
- * @param {string } scope - Whose permissions will be updated .
54
- * @param {string } role - Permissions allowed for the defined scope .
55
- * @param {object= } options - Configuration object.
56
- * @param { int } options.generation - **File Objects Only** If present, selects a
57
- * specific revision of this object (as opposed to the latest version, the
58
- * default).
53
+ * @param {object } options - Configuration object .
54
+ * @param {string } options.scope - Whose permissions will be added .
55
+ * @param {string } options.role - Permissions allowed for the defined scope. See
56
+ * {module:storage#acl}.
57
+ * @param { int= } options.generation - **File Objects Only** Select a specific
58
+ * revision of this file (as opposed to the latest version, the default).
59
59
* @param {function } callback - The callback function.
60
60
*
61
61
* @example
62
- * var scope = '[email protected] ';
63
- * var role = 'owner';
64
- *
65
- * myBucket.acl.add(scope, role , function(err, aclObject) {});
62
+ * myBucket.acl.add({
63
+ * scope: 'user-useremail @example .com',
64
+ * role: storage.acl.OWNER_ROLE
65
+ * } , function(err, aclObject) {});
66
66
*
67
67
* //-
68
- * // For file ACL operations, an options object is also accepted .
68
+ * // For file ACL operations, you can also specify a `generation` property .
69
69
* //-
70
- * var options = {
70
+ * myFile.acl.add({
71
+ * scope: 'user-useremail@example .com',
72
+ * role: storage.acl.OWNER_ROLE,
71
73
* generation: 1
72
- * };
73
- *
74
- * myFile.acl.add(scope, role, options, function(err, aclObject) {});
74
+ * }, function(err, aclObject) {});
75
75
*/
76
- Acl . prototype . add = function ( scope , role , options , callback ) {
76
+ Acl . prototype . add = function ( options , callback ) {
77
77
var that = this ;
78
78
79
79
var body = {
80
- entity : scope ,
81
- role : role . toUpperCase ( )
80
+ entity : options . scope ,
81
+ role : options . role . toUpperCase ( )
82
82
} ;
83
83
84
- if ( util . is ( options , 'function' ) ) {
85
- callback = options ;
86
- options = null ;
87
- }
84
+ var query = null ;
88
85
89
- var query = options || null ;
86
+ if ( options . generation ) {
87
+ query = {
88
+ generation : options . generation
89
+ } ;
90
+ }
90
91
91
92
this . makeReq_ ( 'POST' , '' , query , body , function ( err , resp ) {
92
93
if ( err ) {
@@ -101,56 +102,54 @@ Acl.prototype.add = function(scope, role, options, callback) {
101
102
/**
102
103
* Delete access controls on a {module:storage/bucket} or {module:storage/file}.
103
104
*
104
- * @param {string } scope - Whose permissions will be revoked.
105
105
* @param {object= } options - Configuration object.
106
- * @param {int } options.generation - **File Objects Only** If present, selects a
107
- * specific revision of this object (as opposed to the latest version, the
108
- * default).
106
+ * @param {string } options.scope - Whose permissions will be revoked.
107
+ * @param { int= } options.generation - **File Objects Only** Select a specific
108
+ * revision of this file (as opposed to the latest version, the default).
109
109
* @param {function } callback - The callback function.
110
110
*
111
111
* @example
112
- * var scope = '[email protected] ';
113
- *
114
- * myBucket.acl.delete(scope , function(err) {});
112
+ * myBucket.acl.delete({
113
+ * scope: 'user-useremail @example .com'
114
+ * } , function(err) {});
115
115
*
116
116
* //-
117
117
* // For file ACL operations, an options object is also accepted.
118
118
* //-
119
- * var options = {
119
+ * myFile.acl.delete({
120
+ * scope: 'user-useremail@example .com',
120
121
* generation: 1
121
- * };
122
- *
123
- * myFile.acl.delete(scope, options, function(err) {});
122
+ * }, function(err) {});
124
123
*/
125
- Acl . prototype . delete = function ( scope , options , callback ) {
126
- var path = '/' + encodeURIComponent ( scope ) ;
127
-
128
- if ( util . is ( options , 'function' ) ) {
129
- callback = options ;
130
- options = null ;
124
+ Acl . prototype . delete = function ( options , callback ) {
125
+ var path = '/' + encodeURIComponent ( options . scope ) ;
126
+ var query = null ;
127
+
128
+ if ( options . generation ) {
129
+ query = {
130
+ generation : options . generation
131
+ } ;
131
132
}
132
133
133
- var query = options || null ;
134
-
135
134
this . makeReq_ ( 'DELETE' , path , query , null , callback ) ;
136
135
} ;
137
136
138
137
/**
139
138
* Get access controls on a {module:storage/bucket} or {module:storage/file}. If
140
- * an scope is omitted, you will receive an array of all applicable access
139
+ * a scope is omitted, you will receive an array of all applicable access
141
140
* controls.
142
141
*
143
- * @param {string= } scope - Whose permissions will be fetched.
144
- * @param { object= } options - Configuration object.
145
- * @param { int } options.generation - **File Objects Only** If present, selects a
146
- * specific revision of this object (as opposed to the latest version, the
147
- * default).
148
- * @param { function } callback - The callback function .
142
+ * @param {object|function } options - Configuration object. If you want to
143
+ * receive a list of all access controls, pass the callback function as the
144
+ * only argument.
145
+ * @param { string= } options.scope - Whose permissions will be fetched.
146
+ * @param { int= } options.generation - **File Objects Only** Select a specific
147
+ * revision of this file (as opposed to the latest version, the default) .
149
148
*
150
149
* @example
151
- * var scope = '[email protected] ';
152
- *
153
- * myBucket.acl.get(scope , function(err, aclObject) {});
150
+ * myBucket.acl.get({
151
+ * scope: 'user-useremail @example .com'
152
+ * } , function(err, aclObject) {});
154
153
*
155
154
* //-
156
155
* // Get all access controls.
@@ -167,35 +166,28 @@ Acl.prototype.delete = function(scope, options, callback) {
167
166
* //-
168
167
* // For file ACL operations, an options object is also accepted.
169
168
* //-
170
- * var options = {
169
+ * myFile.acl.get({
170
+ * scope: 'user-useremail@example .com',
171
171
* generation: 1
172
- * };
173
- *
174
- * myFile.acl.get(options, function(err, aclObjects) {});
175
- * myFile.acl.get(scope, options, function(err, aclObject) {});
172
+ * } function(err, aclObject) {});
176
173
*/
177
- Acl . prototype . get = function ( scope , options , callback ) {
174
+ Acl . prototype . get = function ( options , callback ) {
178
175
var that = this ;
179
176
var path = '' ;
180
-
181
- switch ( typeof scope ) {
182
- case 'function' :
183
- callback = scope ;
184
- break ;
185
- case 'string' :
186
- path = '/' + encodeURIComponent ( scope ) ;
187
- break ;
188
- case 'object' :
189
- options = scope ;
190
- break ;
191
- }
177
+ var query = null ;
192
178
193
179
if ( util . is ( options , 'function' ) ) {
194
180
callback = options ;
195
181
options = null ;
196
- }
182
+ } else {
183
+ path = '/' + encodeURIComponent ( options . scope ) ;
197
184
198
- var query = options || null ;
185
+ if ( options . generation ) {
186
+ query = {
187
+ generation : options . generation
188
+ } ;
189
+ }
190
+ }
199
191
200
192
this . makeReq_ ( 'GET' , path , query , null , function ( err , resp ) {
201
193
if ( err ) {
@@ -218,43 +210,45 @@ Acl.prototype.get = function(scope, options, callback) {
218
210
/**
219
211
* Update access controls on a {module:storage/bucket} or {module:storage/file}.
220
212
*
221
- * @param {string } scope - Whose permissions will be updated.
222
- * @param {string } role - Permissions allowed for the defined scope.
223
213
* @param {object= } options - Configuration object.
224
- * @param {int } options.generation - **File Objects Only** If present, selects a
225
- * specific revision of this object (as opposed to the latest version, the
226
- * default).
214
+ * @param {string } options.scope - Whose permissions will be added.
215
+ * @param {string } options.role - Permissions allowed for the defined scope. See
216
+ * {module:storage#acl}.
217
+ * @param {int= } options.generation - **File Objects Only** Select a specific
218
+ * revision of this file (as opposed to the latest version, the default).
227
219
* @param {function } callback - The callback function.
228
220
*
229
221
* @example
230
- * var scope = '[email protected] ';
231
- * var role = 'writer';
222
+ * var storage = gcloud.storage();
232
223
*
233
- * myBucket.acl.update(scope, role, function(err) {});
224
+ * myBucket.acl.update({
225
+ * scope: 'user-useremail@example .com',
226
+ * role: storage.acl.WRITER_ROLE
227
+ * }, function(err) {});
234
228
*
235
229
* //-
236
230
* // For file ACL operations, an options object is also accepted.
237
231
* //-
238
- * var options = {
232
+ * myFile.acl.update({
233
+ * scope: 'user-useremail@example .com',
234
+ * role: storage.acl.WRITER_ROLE,
239
235
* generation: 1
240
- * };
241
- *
242
- * myFile.acl.update(scope, role, options, function(err) {});
236
+ * }, function(err) {});
243
237
*/
244
- Acl . prototype . update = function ( scope , role , options , callback ) {
238
+ Acl . prototype . update = function ( options , callback ) {
245
239
var that = this ;
246
- var path = '/' + encodeURIComponent ( scope ) ;
240
+ var path = '/' + encodeURIComponent ( options . scope ) ;
241
+ var query = null ;
247
242
248
- var body = {
249
- role : role . toUpperCase ( )
250
- } ;
251
-
252
- if ( util . is ( options , 'function' ) ) {
253
- callback = options ;
254
- options = null ;
243
+ if ( options . generation ) {
244
+ query = {
245
+ generation : options . generation
246
+ } ;
255
247
}
256
248
257
- var query = options || null ;
249
+ var body = {
250
+ role : options . role . toUpperCase ( )
251
+ } ;
258
252
259
253
this . makeReq_ ( 'PUT' , path , query , body , function ( err , resp ) {
260
254
if ( err ) {
@@ -274,7 +268,7 @@ Acl.prototype.update = function(scope, role, options, callback) {
274
268
Acl . prototype . makeAclObject_ = function ( accessControlObject ) {
275
269
var obj = {
276
270
scope : accessControlObject . scope ,
277
- role : accessControlObject . role . toLowerCase ( )
271
+ role : accessControlObject . role
278
272
} ;
279
273
280
274
if ( accessControlObject . projectTeam ) {
0 commit comments