Skip to content

Commit

Permalink
feat: support metadata updates from makePrivate() methods (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Dec 7, 2020
1 parent 55732db commit 3db1e83
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export type GetNotificationsResponse = [Notification[], Metadata];
export interface MakeBucketPrivateOptions {
includeFiles?: boolean;
force?: boolean;
metadata?: Metadata;
userProject?: string;
}

Expand Down Expand Up @@ -2657,6 +2658,8 @@ class Bucket extends ServiceObject {
* @typedef {object} MakeBucketPrivateOptions
* @param {boolean} [includeFiles=false] Make each file in the bucket
* private.
* @param {Metadata} [metadata] Define custom metadata properties to define
* along with the operation.
* @param {boolean} [force] Queue errors occurred while making files
* private until all files have been processed.
* @param {string} [userProject] The ID of the project which will be
Expand Down Expand Up @@ -2752,14 +2755,11 @@ class Bucket extends ServiceObject {
query.userProject = options.userProject;
}

this.setMetadata(
{
// You aren't allowed to set both predefinedAcl & acl properties on
// a bucket so acl must explicitly be nullified.
acl: null,
},
query
)
// You aren't allowed to set both predefinedAcl & acl properties on a bucket
// so acl must explicitly be nullified.
const metadata = extend({}, options.metadata, {acl: null});

this.setMetadata(metadata, query)
.then(() => {
if (options.includeFiles) {
return promisify(this.makeAllFilesPublicPrivate_).call(this, options);
Expand Down
19 changes: 9 additions & 10 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export interface CreateWriteStreamOptions extends CreateResumableUploadOptions {
}

export interface MakeFilePrivateOptions {
metadata?: Metadata;
strict?: boolean;
userProject?: string;
}
Expand Down Expand Up @@ -2977,6 +2978,8 @@ class File extends ServiceObject<File> {
): void;
/**
* @typedef {object} MakeFilePrivateOptions Configuration options for File#makePrivate().
* @property {Metadata} [metadata] Define custom metadata properties to define
* along with the operation.
* @property {boolean} [strict] If true, set the file to be private to
* only the owner user. Otherwise, it will be private to the project.
* @property {string} [userProject] The ID of the project which will be
Expand Down Expand Up @@ -3043,16 +3046,12 @@ class File extends ServiceObject<File> {
query.userProject = options.userProject;
}

this.setMetadata(
{
// You aren't allowed to set both predefinedAcl & acl properties on a
// file, so acl must explicitly be nullified, destroying all previous
// acls on the file.
acl: null,
},
query,
callback!
);
// You aren't allowed to set both predefinedAcl & acl properties on a file,
// so acl must explicitly be nullified, destroying all previous acls on the
// file.
const metadata = extend({}, options.metadata, {acl: null});

this.setMetadata(metadata, query, callback!);
}

makePublic(): Promise<MakeFilePublicResponse>;
Expand Down
16 changes: 16 additions & 0 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,22 @@ describe('Bucket', () => {
});
});

it('should accept metadata', done => {
const options = {
metadata: {a: 'b', c: 'd'},
};
bucket.setMetadata = (metadata: {}) => {
assert.deepStrictEqual(metadata, {
acl: null,
...options.metadata,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.strictEqual(typeof (options.metadata as any).acl, 'undefined');
done();
};
bucket.makePrivate(options, assert.ifError);
});

it('should accept userProject', done => {
const options = {
userProject: 'user-project-id',
Expand Down
16 changes: 16 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3429,6 +3429,22 @@ describe('File', () => {
file.makePrivate({strict: true}, util.noop);
});

it('should accept metadata', done => {
const options = {
metadata: {a: 'b', c: 'd'},
};
file.setMetadata = (metadata: {}) => {
assert.deepStrictEqual(metadata, {
acl: null,
...options.metadata,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.strictEqual(typeof (options.metadata as any).acl, 'undefined');
done();
};
file.makePrivate(options, assert.ifError);
});

it('should accept userProject', done => {
const options = {
userProject: 'user-project-id',
Expand Down

0 comments on commit 3db1e83

Please sign in to comment.