Skip to content

Commit 09b8fa4

Browse files
AVaksmanBenjamin E. Coe
authored andcommitted
fix: pass predefined acl as destinationPredefinedAcl to qs (#872)
1 parent 12a99e9 commit 09b8fa4

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/file.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ interface CopyQuery {
323323
rewriteToken?: string;
324324
userProject?: string;
325325
destinationKmsKeyName?: string;
326+
destinationPredefinedAcl?: string;
326327
}
327328

328329
interface FileQuery {
@@ -833,7 +834,10 @@ class File extends ServiceObject<File> {
833834
});
834835
}
835836

836-
copy(destination: string | Bucket | File): Promise<CopyResponse>;
837+
copy(
838+
destination: string | Bucket | File,
839+
options?: CopyOptions
840+
): Promise<CopyResponse>;
837841
copy(destination: string | Bucket | File, callback: CopyCallback): void;
838842
copy(
839843
destination: string | Bucket | File,
@@ -1031,6 +1035,10 @@ class File extends ServiceObject<File> {
10311035
query.userProject = options.userProject;
10321036
delete options.userProject;
10331037
}
1038+
if (options.predefinedAcl !== undefined) {
1039+
query.destinationPredefinedAcl = options.predefinedAcl;
1040+
delete options.predefinedAcl;
1041+
}
10341042

10351043
newFile = newFile! || destBucket.file(destName);
10361044

system-test/storage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,16 @@ describe('storage', () => {
25972597
await Promise.all([file.delete, copiedFile.delete()]);
25982598
});
25992599

2600+
it('should respect predefined Acl at file#copy', async () => {
2601+
const opts = {destination: 'CloudLogo'};
2602+
const [file] = await bucket.upload(FILES.logo.path, opts);
2603+
const copyOpts = {predefinedAcl: 'publicRead'};
2604+
const [copiedFile] = await file.copy('CloudLogoCopy', copyOpts);
2605+
const publicAcl = await isFilePublicAsync(copiedFile);
2606+
assert.strictEqual(publicAcl, true);
2607+
await Promise.all([file.delete, copiedFile.delete()]);
2608+
});
2609+
26002610
it('should copy a large file', async () => {
26012611
const otherBucket = storage.bucket(generateName());
26022612
const file = bucket.file('Big');

test/file.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,23 @@ describe('File', () => {
550550
file.copy(newFile, {destinationKmsKeyName}, assert.ifError);
551551
});
552552

553+
it('should accept predefined Acl', done => {
554+
const options = {
555+
predefinedAcl: 'authenticatedRead',
556+
};
557+
const newFile = new File(BUCKET, 'new-file');
558+
file.request = (reqOpts: DecorateRequestOptions) => {
559+
assert.strictEqual(
560+
reqOpts.qs.destinationPredefinedAcl,
561+
options.predefinedAcl
562+
);
563+
assert.strictEqual(reqOpts.json.destinationPredefinedAcl, undefined);
564+
done();
565+
};
566+
567+
file.copy(newFile, options, assert.ifError);
568+
});
569+
553570
it('should favor the option over the File KMS name', done => {
554571
const newFile = new File(BUCKET, 'new-file');
555572
newFile.kmsKeyName = 'incorrect-kms-key-name';

0 commit comments

Comments
 (0)