From 13de7089377f30ba6fcb1bd5b7321e48229e7ce2 Mon Sep 17 00:00:00 2001 From: Tomer Eskenazi Date: Mon, 15 Jun 2020 12:05:26 +0300 Subject: [PATCH] PR comments --- services/src/modules/resource-repository/s3.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/services/src/modules/resource-repository/s3.ts b/services/src/modules/resource-repository/s3.ts index 55863949..297f8eb0 100644 --- a/services/src/modules/resource-repository/s3.ts +++ b/services/src/modules/resource-repository/s3.ts @@ -11,6 +11,8 @@ interface S3ResourceRepositoryConfig { objectKey: string; policyAttachmentsKeyPrefix: string; } +type FileDetails = {filename: string; updatedAt: Date}; + export class S3ResourceRepository implements ResourceRepository { protected current?: {etag?: string; rg: ResourceGroup}; protected policyAttachments: {[filename: string]: Buffer} = {}; @@ -118,29 +120,29 @@ export class S3ResourceRepository implements ResourceRepository { this.policyAttachmentsRefreshedAt = newRefreshedAt; } - private shouldRefreshPolicyAttachment({filename, updatedAt}: {filename: string; updatedAt: Date}) { + private shouldRefreshPolicyAttachment({filename, updatedAt}: FileDetails) { if (!this.policyAttachments[filename]) return true; if (!this.policyAttachmentsRefreshedAt) return true; return updatedAt > this.policyAttachmentsRefreshedAt; } - private async getPolicyAttachmentsList(): Promise<{filename: string; updatedAt: Date}[]> { - const attachments: {filename: string; updatedAt: Date}[] = []; + private async getPolicyAttachmentsList(): Promise { + const attachments: FileDetails[] = []; let isTruncated = true; let continuationToken; while (isTruncated) { - const params: any = { + const params: AWS.S3.Types.ListObjectsV2Request = { Bucket: this.config.bucketName, MaxKeys: 1000, Prefix: this.config.policyAttachmentsKeyPrefix, }; - if (continuationToken) params['ContinuationToken'] = continuationToken; + if (continuationToken) params.ContinuationToken = continuationToken; const listResult = await this.config.s3.listObjectsV2(params).promise(); const keys = listResult.Contents || []; - const newAttachments = keys.map(k => ({ + const newAttachments: FileDetails[] = keys.map(k => ({ filename: this.getPolicyAttachmentFilenameByKey(k.Key!), updatedAt: k.LastModified!, }));