Skip to content

Commit 7ecc702

Browse files
CCM-8861: Fix after bad rebase
1 parent 40b3c43 commit 7ecc702

File tree

8 files changed

+21
-42
lines changed

8 files changed

+21
-42
lines changed

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_sftp_poll.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ resource "aws_cloudwatch_event_rule" "sftp_poll" {
77

88
resource "aws_cloudwatch_event_target" "sftp_poll" {
99
for_each = { for k, v in var.letter_suppliers : k => v if v.polling_enabled }
10-
rule = aws_cloudwatch_event_rule.sftp_poll.name
11-
arn = module.lambda_sftp_poll.function_arn
10+
rule = aws_cloudwatch_event_rule.sftp_poll[each.key].name
11+
arn = module.lambda_sftp_poll.function_arn
1212

13-
input = {
14-
supplier: each.key
15-
}
13+
input = jsonencode({
14+
supplier : each.key
15+
})
1616
}
1717

1818
resource "aws_lambda_permission" "allow_cloudwatch" {
19-
for_each = { for k, v in var.letter_suppliers : k => v if v.polling_enabled }
20-
statement_id = "AllowExecutionFromCloudWatch"
19+
for_each = { for k, v in var.letter_suppliers : k => v if v.polling_enabled }
20+
statement_id = "AllowExecutionFromCloudWatch${each.key}"
2121
action = "lambda:InvokeFunction"
2222
function_name = module.lambda_sftp_poll.function_name
2323
principal = "events.amazonaws.com"
24-
source_arn = aws_cloudwatch_event_rule.sftp_poll.arn
24+
source_arn = aws_cloudwatch_event_rule.sftp_poll[each.key].arn
2525
}

infrastructure/terraform/modules/backend-api/module_lambda_sftp_poll.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ module "lambda_sftp_poll" {
1212
execution_role_policy_document = data.aws_iam_policy_document.sftp_poll.json
1313

1414
environment_variables = {
15-
CREDENTIALS_TTL_MS = 900 * 1000
16-
CSI = local.csi
17-
QUARANTINE_BUCKET_NAME = module.s3bucket_quarantine.id
18-
NODE_OPTIONS = "--enable-source-maps",
19-
REGION = var.region
20-
SFTP_ENVIRONMENT = local.sftp_environment
15+
CREDENTIALS_TTL_MS = 900 * 1000
16+
CSI = local.csi
17+
QUARANTINE_BUCKET_NAME = module.s3bucket_quarantine.id
18+
NODE_OPTIONS = "--enable-source-maps",
19+
REGION = var.region
20+
SFTP_ENVIRONMENT = local.sftp_environment
2121
}
2222

2323
timeout = 20

lambdas/sftp-letters/src/__tests__/infra/sftp-supplier-client-repository.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { GetParameterCommand, SSMClient } from '@aws-sdk/client-ssm';
22
import { createMockLogger } from 'nhs-notify-web-template-management-test-helper-utils/mock-logger';
3-
import { ICache } from 'nhs-notify-web-template-management-utils';
43
import { mock } from 'jest-mock-extended';
54
import 'aws-sdk-client-mock-jest';
65
import { mockClient } from 'aws-sdk-client-mock';
@@ -10,13 +9,6 @@ import {
109
SftpSupplierClientRepository,
1110
} from '../../infra/sftp-supplier-client-repository';
1211
import { SftpClient } from '../../infra/sftp-client';
13-
import {
14-
GetParameterCommand,
15-
GetParametersByPathCommand,
16-
SSMClient,
17-
} from '@aws-sdk/client-ssm';
18-
import { createMockLogger } from 'nhs-notify-web-template-management-test-helper-utils/mock-logger';
19-
import { mock } from 'jest-mock-extended';
2012
import NodeCache from 'node-cache';
2113

2214
jest.mock('../../infra/sftp-client');
@@ -77,7 +69,6 @@ describe('getClient', () => {
7769
sftpClient: mockSftpClient,
7870
baseUploadDir: 'upload/dir',
7971
baseDownloadDir: 'download/dir',
80-
name: 'SYNERTEC',
8172
});
8273

8374
expect(cache.get).toHaveBeenCalledWith(credKey);
@@ -126,7 +117,6 @@ describe('getClient', () => {
126117
sftpClient: mockSftpClient,
127118
baseUploadDir: 'upload/dir',
128119
baseDownloadDir: 'download/dir',
129-
name: 'SYNERTEC',
130120
});
131121

132122
expect(cache.get).toHaveBeenCalledWith(credKey);

lambdas/sftp-letters/src/config/config-poll.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import z from 'zod';
33
export function loadConfig() {
44
return z
55
.object({
6-
CREDENTIALS_TTL_MS: z.string().pipe(z.coerce.number()),
6+
CREDENTIALS_TTL_SECONDS: z.string().pipe(z.coerce.number()),
77
CSI: z.string(),
88
QUARANTINE_BUCKET_NAME: z.string(),
99
REGION: z.string(),
1010
SFTP_ENVIRONMENT: z.string(),
1111
})
1212
.transform((e) => ({
13-
credentialsTtlMs: e.CREDENTIALS_TTL_MS,
13+
credentialsTtlSeconds: e.CREDENTIALS_TTL_SECONDS,
1414
csi: e.CSI,
1515
quarantineBucketName: e.QUARANTINE_BUCKET_NAME,
1616
region: e.REGION,

lambdas/sftp-letters/src/container-poll.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import { SftpSupplierClientRepository } from './infra/sftp-supplier-client-repos
44
import { loadConfig } from './config/config-poll';
55
import { App } from './app/poll';
66
import { logger } from 'nhs-notify-web-template-management-utils/logger';
7-
import {
8-
InMemoryCache,
9-
S3Repository,
10-
} from 'nhs-notify-web-template-management-utils';
7+
import { S3Repository } from 'nhs-notify-web-template-management-utils';
8+
import NodeCache from 'node-cache';
119

1210
export function createContainer() {
1311
const {
1412
csi,
1513
quarantineBucketName,
16-
credentialsTtlMs,
14+
credentialsTtlSeconds,
1715
region,
1816
sftpEnvironment,
1917
} = loadConfig();
@@ -22,7 +20,7 @@ export function createContainer() {
2220

2321
const s3Client = new S3Client({ region });
2422

25-
const cache = new InMemoryCache({ ttl: credentialsTtlMs });
23+
const cache = new NodeCache({ stdTTL: credentialsTtlSeconds });
2624

2725
const sftpSupplierClientRepository = new SftpSupplierClientRepository(
2826
csi,

lambdas/sftp-letters/src/infra/sftp-supplier-client-repository.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export class SftpSupplierClientRepository {
6969
sftpClient: new SftpClient(host, username, privateKey, hostKey),
7070
baseUploadDir,
7171
baseDownloadDir,
72-
name: supplier,
7372
};
7473
}
7574
}

utils/utils/src/__tests__/s3-repository.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
PutObjectCommand,
3-
S3Client,
4-
} from '@aws-sdk/client-s3';
1+
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
52
import { mockClient } from 'aws-sdk-client-mock';
63
import 'aws-sdk-client-mock-jest';
74
import { mock } from 'jest-mock-extended';

utils/utils/src/s3-repository.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
PutObjectCommandInput,
44
PutObjectCommandOutput,
55
S3Client,
6-
_Object,
76
} from '@aws-sdk/client-s3';
87

98
export class S3Repository {
@@ -12,10 +11,6 @@ export class S3Repository {
1211
private readonly client: S3Client
1312
) {}
1413

15-
s3Path(key: string) {
16-
return `s3://${this.bucket}/${key}`;
17-
}
18-
1914
async putRawData(
2015
fileData: PutObjectCommandInput['Body'],
2116
key: string

0 commit comments

Comments
 (0)