Skip to content

Commit

Permalink
updates based off feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealAmazonKendra committed Aug 29, 2024
1 parent 004e854 commit 463f0c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface IAws {
s3Client(options: ClientOptions): Promise<S3Client>;
ecrClient(options: ClientOptions): Promise<ECRClient>;
secretsManagerClient(options: ClientOptions): Promise<SecretsManagerClient>;
upload(params: PutObjectCommandInput, options: ClientOptions): Promise<CompleteMultipartUploadCommandOutput>
upload(params: PutObjectCommandInput, options?: ClientOptions): Promise<CompleteMultipartUploadCommandOutput>;
}

export interface ClientOptions {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class DefaultAwsClient implements IAws {
return new S3Client(await this.awsOptions(options));
}

public async upload(params: PutObjectCommandInput, options: ClientOptions): Promise<CompleteMultipartUploadCommandOutput> {
public async upload(params: PutObjectCommandInput, options: ClientOptions = {}): Promise<CompleteMultipartUploadCommandOutput> {
try {
const upload = new Upload({
client: await this.s3Client(options),
Expand Down
2 changes: 1 addition & 1 deletion lib/private/handlers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class FileAssetHandler implements IAssetHandler {
paramsEncryption
);

await this.host.aws.upload(params, {});
await this.host.aws.upload(params);
}

private async packageFile(source: FileSource): Promise<PackagedFileAsset> {
Expand Down
21 changes: 7 additions & 14 deletions test/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ test('upload with server side encryption AES256 header', async () => {
Key: 'some_key',
ContentType: 'application/octet-stream',
ServerSideEncryption: 'AES256',
}),
{}
})
);

// We'll just have to assume the contents are correct
Expand Down Expand Up @@ -211,8 +210,7 @@ test('upload with server side encryption aws:kms header and key id', async () =>
ContentType: 'application/octet-stream',
ServerSideEncryption: 'aws:kms',
SSEKMSKeyId: 'the-key-id',
}),
{}
})
);

// We'll just have to assume the contents are correct
Expand All @@ -235,15 +233,13 @@ test('no server side encryption header if access denied for bucket encryption',
expect(upload).toHaveBeenCalledWith(
expect.not.objectContaining({
ServerSideEncryption: 'aws:kms',
}),
{}
})
);

expect(upload).toHaveBeenCalledWith(
expect.not.objectContaining({
ServerSideEncryption: 'AES256',
}),
{}
})
);
});

Expand All @@ -260,17 +256,15 @@ test('correctly looks up content type', async () => {
Bucket: 'some_bucket',
Key: 'some_key.txt',
ContentType: 'text/plain',
}),
{}
})
);

expect(upload).toHaveBeenCalledWith(
expect.objectContaining({
Bucket: 'some_bucket',
Key: 'some_key.png',
ContentType: 'image/png',
}),
{}
})
);

// We'll just have to assume the contents are correct
Expand All @@ -287,8 +281,7 @@ test('upload file if new (list returns no key)', async () => {
expect.objectContaining({
Bucket: 'some_bucket',
Key: 'some_key',
}),
{}
})
);

// We'll just have to assume the contents are correct
Expand Down

0 comments on commit 463f0c5

Please sign in to comment.