Skip to content

Commit 0ebc202

Browse files
committed
Merge branch 'main' of https://github.com/NHSDigital/eps-assist-me into AEA-5671-trigger-document-ingestion
2 parents bf7911e + aeb5e30 commit 0ebc202

34 files changed

+1786
-384
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"AmazonWebServices.aws-toolkit-vscode",
2929
"redhat.vscode-yaml",
3030
"ms-python.python",
31+
"ms-python.black-formatter",
3132
"ms-python.flake8",
3233
"eamodio.gitlens",
3334
"github.vscode-pull-request-github",
@@ -51,9 +52,18 @@
5152
"python.analysis.extraPaths": [],
5253
"python.testing.unittestEnabled": false,
5354
"python.testing.pytestEnabled": true,
55+
"python.testing.pytestArgs": [
56+
"packages/slackBotFunction",
57+
"packages/createIndexFunction"
58+
],
5459
"python.linting.pylintEnabled": false,
5560
"python.linting.flake8Enabled": true,
5661
"python.linting.enabled": true, // required to format on save
62+
"python.formatting.provider": "black",
63+
"black-formatter.args": ["--line-length=120"],
64+
"[python]": {
65+
"editor.defaultFormatter": "ms-python.black-formatter"
66+
},
5767
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
5868
"editor.formatOnPaste": false, // required
5969
"editor.formatOnType": false, // required
@@ -62,7 +72,7 @@
6272
"cSpell.words": ["fhir", "Formik", "pino", "serialisation"],
6373
"eslint.useFlatConfig": true,
6474
"eslint.format.enable": true
65-
}
75+
}
6676
}
6777
},
6878
"postCreateCommand": "rm -f ~/.docker/config.json; git config --global --add safe.directory /workspaces/eps-assist-me; make install; direnv allow ."

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
max-line-length = 120
3-
exclude = .*,venv,node_modules
3+
exclude = .*,venv,node_modules,cdk.out
44
max-complexity = 10
5-
ignore = F821
5+
ignore = F821,E203

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/newman/
55
**/public/
66
**/coverage/
7+
.coverage
78
**/node_modules/
89
.#*
910
__pycache__/

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ repos:
2121
hooks:
2222
- id: flake8
2323

24+
- repo: https://github.com/psf/black
25+
rev: "24.10.0"
26+
hooks:
27+
- id: black
28+
language_version: python3
29+
args: [--line-length=120]
30+
2431
- repo: local
2532
hooks:
2633
- id: lint-githubactions

Makefile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ install: install-python install-hooks install-node
1010

1111
install-python:
1212
poetry install
13+
cd packages/slackBotFunction && pip install -r requirements.txt && pip install -r requirements-test.txt
14+
cd packages/createIndexFunction && pip install -r requirements.txt && pip install -r requirements-test.txt
1315

1416
install-hooks: install-python
1517
poetry run pre-commit install --install-hooks --overwrite
@@ -27,7 +29,7 @@ git-secrets-docker-setup:
2729
export LOCAL_WORKSPACE_FOLDER=$(pwd)
2830
docker build -f https://raw.githubusercontent.com/NHSDigital/eps-workflow-quality-checks/refs/tags/v4.0.4/dockerfiles/nhsd-git-secrets.dockerfile -t git-secrets .
2931

30-
lint: lint-githubactions lint-githubaction-scripts
32+
lint: lint-githubactions lint-githubaction-scripts lint-black lint-flake8
3133

3234
lint-githubactions:
3335
actionlint
@@ -36,12 +38,23 @@ lint-githubaction-scripts:
3638
shellcheck ./scripts/*.sh
3739
shellcheck .github/scripts/*.sh
3840

39-
test: compile-node
40-
npm run test --workspace packages/cdk
41+
lint-black:
42+
poetry run black .
43+
44+
lint-flake8:
45+
poetry run flake8 .
46+
47+
test:
48+
cd packages/slackBotFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage python -m pytest
49+
cd packages/createIndexFunction && PYTHONPATH=. COVERAGE_FILE=coverage/.coverage python -m pytest
4150

4251
clean:
4352
rm -rf packages/cdk/coverage
4453
rm -rf packages/cdk/lib
54+
rm -rf packages/slackBotFunction/coverage
55+
rm -rf packages/slackBotFunction/.coverage
56+
rm -rf packages/createIndexFunction/coverage
57+
rm -rf packages/createIndexFunction/.coverage
4558
rm -rf cdk.out
4659
rm -rf .build
4760

@@ -66,7 +79,7 @@ aws-login:
6679
cfn-guard:
6780
./scripts/run_cfn_guard.sh
6881

69-
cdk-deploy: guard-stack_name
82+
cdk-deploy: guard-STACK_NAME
7083
REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \
7184
VERSION_NUMBER="$${VERSION_NUMBER:-undefined}" && \
7285
COMMIT_ID="$${COMMIT_ID:-undefined}" && \
@@ -76,7 +89,7 @@ cdk-deploy: guard-stack_name
7689
--ci true \
7790
--require-approval $${REQUIRE_APPROVAL} \
7891
--context accountId=$$ACCOUNT_ID \
79-
--context stackName=$$stack_name \
92+
--context stackName=$$STACK_NAME \
8093
--context versionNumber=$$VERSION_NUMBER \
8194
--context commitId=$$COMMIT_ID \
8295
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS \
@@ -100,12 +113,12 @@ cdk-diff:
100113
npx cdk diff \
101114
--app "npx ts-node --prefer-ts-exts packages/cdk/bin/EpsAssistMeApp.ts" \
102115
--context accountId=$$ACCOUNT_ID \
103-
--context stackName=$$stack_name \
116+
--context stackName=$$STACK_NAME \
104117
--context versionNumber=$$VERSION_NUMBER \
105118
--context commitId=$$COMMIT_ID \
106119
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS
107120

108-
cdk-watch: guard-stack_name
121+
cdk-watch: guard-STACK_NAME
109122
REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \
110123
VERSION_NUMBER="$${VERSION_NUMBER:-undefined}" && \
111124
COMMIT_ID="$${COMMIT_ID:-undefined}" && \
@@ -116,7 +129,7 @@ cdk-watch: guard-stack_name
116129
--ci true \
117130
--require-approval $${REQUIRE_APPROVAL} \
118131
--context accountId=$$ACCOUNT_ID \
119-
--context stackName=$$stack_name \
132+
--context stackName=$$STACK_NAME \
120133
--context versionNumber=$$VERSION_NUMBER \
121134
--context commitId=$$COMMIT_ID \
122135
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS \

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ When the token expires, you may need to reauthorise using `make aws-login`
105105
For deployment, the following environment variables are required:
106106

107107
- `ACCOUNT_ID`: AWS Account ID
108-
- `stack_name`: Name of the CloudFormation stack
108+
- `STACK_NAME`: Name of the CloudFormation stack
109109
- `VERSION_NUMBER`: Version number for the deployment
110110
- `COMMIT_ID`: Git commit ID
111111
- `LOG_RETENTION_IN_DAYS`: CloudWatch log retention period
@@ -139,10 +139,10 @@ There are `make` commands that are run as part of the CI pipeline and help alias
139139
#### CDK targets
140140
These are used to do common commands related to cdk
141141

142-
- `cdk-deploy` Builds and deploys the code to AWS. Requires `stack_name` environment variable.
142+
- `cdk-deploy` Builds and deploys the code to AWS. Requires `STACK_NAME` environment variable.
143143
- `cdk-synth` Converts the CDK code to cloudformation templates.
144144
- `cdk-diff` Runs cdk diff, comparing the deployed stack with the local CDK code to identify differences.
145-
- `cdk-watch` Syncs the code and CDK templates to AWS. This keeps running and automatically uploads changes to AWS. Requires `stack_name` environment variable.
145+
- `cdk-watch` Syncs the code and CDK templates to AWS. This keeps running and automatically uploads changes to AWS. Requires `STACK_NAME` environment variable.
146146

147147
#### Clean and deep-clean targets
148148

@@ -152,9 +152,11 @@ These are used to do common commands related to cdk
152152
#### Linting and testing
153153

154154
- `lint` Runs lint for GitHub Actions and scripts.
155+
- `lint-black` Runs black formatter on Python code.
156+
- `lint-flake8` Runs flake8 linter on Python code.
155157
- `lint-githubactions` Lints the repository's GitHub Actions workflows.
156158
- `lint-githubaction-scripts` Lints all shell scripts in `.github/scripts` using ShellCheck.
157-
- `test` Runs unit tests for CDK code.
159+
- `test` Runs unit tests for Lambda functions.
158160
- `cfn-guard` Runs cfn-guard against CDK resources.
159161
- `pre-commit` Runs pre-commit hooks on all files.
160162

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {Construct} from "constructs"
2+
import {RemovalPolicy} from "aws-cdk-lib"
3+
import {
4+
TableV2,
5+
AttributeType,
6+
Billing,
7+
TableEncryptionV2
8+
} from "aws-cdk-lib/aws-dynamodb"
9+
import {Key} from "aws-cdk-lib/aws-kms"
10+
11+
export interface DynamoDbTableProps {
12+
readonly tableName: string
13+
readonly partitionKey: {
14+
name: string
15+
type: AttributeType
16+
}
17+
readonly timeToLiveAttribute?: string
18+
}
19+
20+
export class DynamoDbTable extends Construct {
21+
public readonly table: TableV2
22+
public readonly kmsKey: Key
23+
24+
constructor(scope: Construct, id: string, props: DynamoDbTableProps) {
25+
super(scope, id)
26+
27+
this.kmsKey = new Key(this, "TableKey", {
28+
enableKeyRotation: true,
29+
description: `KMS key for ${props.tableName} DynamoDB table encryption`,
30+
removalPolicy: RemovalPolicy.DESTROY
31+
})
32+
this.kmsKey.addAlias(`alias/${props.tableName}-dynamodb-key`)
33+
34+
this.table = new TableV2(this, props.tableName, {
35+
tableName: props.tableName,
36+
partitionKey: props.partitionKey,
37+
billing: Billing.onDemand(),
38+
timeToLiveAttribute: props.timeToLiveAttribute,
39+
pointInTimeRecovery: true,
40+
removalPolicy: RemovalPolicy.DESTROY,
41+
encryption: TableEncryptionV2.customerManagedKey(this.kmsKey)
42+
})
43+
}
44+
}

packages/cdk/constructs/OpenSearchCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {Construct} from "constructs"
22
import {CfnCollection, CfnSecurityPolicy, CfnAccessPolicy} from "aws-cdk-lib/aws-opensearchserverless"
33

44
export interface OpenSearchCollectionProps {
5-
collectionName: string
6-
principals: Array<string>
5+
readonly collectionName: string
6+
readonly principals: Array<string>
77
}
88

99
export class OpenSearchCollection extends Construct {

packages/cdk/constructs/S3Bucket.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,33 @@ import {
99
import {Key} from "aws-cdk-lib/aws-kms"
1010

1111
export interface S3BucketProps {
12-
bucketName: string
13-
kmsKey: Key
14-
versioned: boolean
12+
readonly bucketName: string
13+
readonly versioned: boolean
1514
}
1615

1716
export class S3Bucket extends Construct {
1817
public readonly bucket: Bucket
19-
public readonly kmsKey?: Key
18+
public readonly kmsKey: Key
2019

2120
constructor(scope: Construct, id: string, props: S3BucketProps) {
2221
super(scope, id)
2322

23+
this.kmsKey = new Key(this, "BucketKey", {
24+
enableKeyRotation: true,
25+
description: `KMS key for ${props.bucketName} S3 bucket encryption`,
26+
removalPolicy: RemovalPolicy.DESTROY
27+
})
28+
this.kmsKey.addAlias(`alias/${props.bucketName}-s3-key`)
29+
2430
this.bucket = new Bucket(this, props.bucketName, {
2531
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
2632
encryption: BucketEncryption.KMS,
27-
encryptionKey: props.kmsKey,
33+
encryptionKey: this.kmsKey,
2834
removalPolicy: RemovalPolicy.DESTROY,
2935
autoDeleteObjects: true,
3036
enforceSSL: true,
3137
versioned: props.versioned ?? false,
3238
objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED
3339
})
34-
35-
this.kmsKey = props.kmsKey
3640
}
3741
}

packages/cdk/constructs/SecretWithParameter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {StringParameter, ParameterTier} from "aws-cdk-lib/aws-ssm"
44
import {Secret} from "aws-cdk-lib/aws-secretsmanager"
55

66
export interface SecretWithParameterProps {
7-
secretName: string
8-
parameterName: string
9-
description: string
10-
secretValue: string
7+
readonly secretName: string
8+
readonly parameterName: string
9+
readonly description: string
10+
readonly secretValue: string
1111
}
1212

1313
export class SecretWithParameter extends Construct {

0 commit comments

Comments
 (0)