Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeresk committed Jun 15, 2020
1 parent 7a56282 commit 13de708
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions services/src/modules/resource-repository/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} = {};
Expand Down Expand Up @@ -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<FileDetails[]> {
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!,
}));
Expand Down

0 comments on commit 13de708

Please sign in to comment.