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

fix: add warning for unsupported keepAcl param in file#copy #841

Merged
10 changes: 10 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export interface FileOptions {

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

if (options.hasOwnProperty('keepAcl')) {
// TODO: remove keepAcl from interface in next major.
console.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is scary to me, because we've always considered our chance to communicate dev-only messages is pre-installation via the changelog, but not at runtime. That could potentially interrupt their users, since we are commonly a base layer in more complex applications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @bcoe @callmehiphop for thoughts!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misremembering, but I seem to recall using the console to warn users about deprecated methods in the auth client as well (paging @JustinBeckwith). I'm ok with this, but think we should take a hard stance of how we communicate this kind of change across the board.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been known to use this approach in yargs:

https://github.com/yargs/yargs/blob/5d7ad989a851398587a0349cdd15344769b4cd79/yargs.js#L1035

And haven't received many complaints; my general thinking has been.

  • it's less disruptive to start by warning folks than throwing.
  • it draws attention to a change that will eventually be breaking.
  • Node itself has done this for a lot of features, e.g., Buffer, so the community is accustomed to it.

In this case, my gut was that only a small percentage of folks would be explicitly setting keepAcl so it's probably fairly low impact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 I have opinions here!
https://github.com/googleapis/google-auth-library-nodejs/blob/master/src/messages.ts

A few thoughts:

As with all things, final say here is deferred to @bcoe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the right move is to switch to process.emitWarning 👍 and let's land this.

For this specific case, I don't have a strong opinion about including an error code; seems smart in the case of an HTTP response or a file operation going off the rails, but not quite sure what a good option would be for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks
@JustinBeckwith could I trouble you to look over the switch to process.emitWarning once per process (last commit).

'keepAcl parameter is not supported and will be removed in the next major'
);
}

options = extend(true, {}, options);
callback = callback || util.noop;

Expand Down
12 changes: 12 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ describe('File', () => {
});

describe('copy', () => {
it('should warn if `keepAcl` parameter is passed', () => {
const consoleStub = sinon.stub(console, 'warn');
file.request = util.noop;
file.copy('newFile', {keepAcl: 'private'}, assert.ifError);
assert.ok(
consoleStub.calledWith(
'keepAcl parameter is not supported and will be removed in the next major'
)
);
sinon.restore();
});

it('should throw if no destination is provided', () => {
assert.throws(() => {
file.copy();
Expand Down