Skip to content

Commit 473bda0

Browse files
AVaksmanJustinBeckwith
authored andcommitted
fix: add warning for unsupported keepAcl param in file#copy (#841)
1 parent 27fa02f commit 473bda0

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/file.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export interface FileOptions {
295295

296296
export interface CopyOptions {
297297
destinationKmsKeyName?: string;
298+
keepAcl?: string;
298299
predefinedAcl?: string;
299300
token?: string;
300301
userProject?: string;
@@ -858,6 +859,8 @@ class File extends ServiceObject<File> {
858859
* `projects/my-project/locations/location/keyRings/my-kr/cryptoKeys/my-key`,
859860
* that will be used to encrypt the object. Overwrites the object
860861
* metadata's `kms_key_name` value, if any.
862+
* @property {string} [keepAcl] This parameter is not supported and will be
863+
* removed in the next major.
861864
* @property {string} [predefinedAcl] Set the ACL for the new file.
862865
* @property {string} [token] A previously-returned `rewriteToken` from an
863866
* unfinished rewrite request.
@@ -984,6 +987,11 @@ class File extends ServiceObject<File> {
984987
options = optionsOrCallback;
985988
}
986989

990+
if (options.hasOwnProperty('keepAcl')) {
991+
// TODO: remove keepAcl from interface in next major.
992+
emitWarning();
993+
}
994+
987995
options = extend(true, {}, options);
988996
callback = callback || util.noop;
989997

@@ -3416,6 +3424,17 @@ promisifyAll(File, {
34163424
],
34173425
});
34183426

3427+
let warned = false;
3428+
export function emitWarning() {
3429+
if (!warned) {
3430+
warned = true;
3431+
process.emitWarning(
3432+
'keepAcl parameter is not supported and will be removed in the next major',
3433+
'DeprecationWarning'
3434+
);
3435+
}
3436+
}
3437+
34193438
/**
34203439
* Reference to the {@link File} class.
34213440
* @name module:@google-cloud/storage.File

test/file.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,65 @@ describe('File', () => {
345345
});
346346

347347
describe('copy', () => {
348+
describe('depricate `keepAcl`', () => {
349+
// tslint:disable-next-line: no-any
350+
let STORAGE2: any;
351+
// tslint:disable-next-line: no-any
352+
let BUCKET2: any;
353+
// tslint:disable-next-line: no-any
354+
let file2: any;
355+
beforeEach(() => {
356+
STORAGE2 = {
357+
createBucket: util.noop,
358+
request: util.noop,
359+
// tslint:disable-next-line: no-any
360+
makeAuthenticatedRequest(req: {}, callback: any) {
361+
if (callback) {
362+
(callback.onAuthenticated || callback)(null, req);
363+
}
364+
},
365+
bucket(name: string) {
366+
return new Bucket(this, name);
367+
},
368+
};
369+
BUCKET2 = new Bucket(STORAGE, 'bucket-name');
370+
file2 = new File(BUCKET, FILE_NAME);
371+
});
372+
373+
it('should warn if `keepAcl` parameter is passed', done => {
374+
file.request = util.noop;
375+
376+
// since --throw-deprication is enabled using try=>catch block
377+
try {
378+
file.copy('newFile', {keepAcl: 'private'}, assert.ifError);
379+
} catch (err) {
380+
assert.strictEqual(
381+
err.message,
382+
'keepAcl parameter is not supported and will be removed in the next major'
383+
);
384+
assert.strictEqual(err.name, 'DeprecationWarning');
385+
done();
386+
}
387+
});
388+
389+
it('should warn only once `keepAcl` parameter is passed', done => {
390+
file.request = util.noop;
391+
392+
// since --throw-deprication is enabled using try=>catch block
393+
try {
394+
file.copy('newFile', {keepAcl: 'private'}, assert.ifError);
395+
} catch (err) {
396+
assert.strictEqual(
397+
err.message,
398+
'keepAcl parameter is not supported and will be removed in the next major'
399+
);
400+
assert.strictEqual(err.name, 'DeprecationWarning');
401+
}
402+
file2.copy('newFile2', {keepAcl: 'private'}, assert.ifError);
403+
done();
404+
});
405+
});
406+
348407
it('should throw if no destination is provided', () => {
349408
assert.throws(() => {
350409
file.copy();

0 commit comments

Comments
 (0)