-
Notifications
You must be signed in to change notification settings - Fork 5
Authoriser lambda #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Authoriser lambda #230
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
5c6ded5
add product id header
nhsd-david-wass 8921a0a
Merge branch 'main' into feature/CCM-11600-API-GW-Authorizer
masl2 59082b9
Merge branch 'main' into feature/CCM-11600-API-GW-Authorizer
masl2 153c9b2
Merge branch 'main' into feature/CCM-11600-API-GW-Authorizer
masl2 9299143
CCM-11600: supplier repository and table
masl2 d8587e1
CCM-11600: cli interface for supplier repo
masl2 fecb456
CCM-11600: lock for new packages
masl2 b0d773d
Update .gitleaksignore
timireland 98fa540
CCM-11600: fix some imports
masl2 ead65de
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-API…
stevebux 00ea227
Add certificate expiry check
stevebux 04da14d
Added supplier ID lookup
stevebux d184791
Test fix
stevebux 12be555
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-API…
stevebux 0121de0
Further development
stevebux a616c06
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-API…
stevebux acc043a
Fix dependencies
stevebux 02802bf
Temp commit to force cloudwatch logging
stevebux 680ae81
Removed Cloudwatch client
stevebux 58fc378
Tidy up packages
stevebux 95631c8
CCM-11600: correct target attr
masl2 f31a572
CCM-11600: header name, targets, add alarm
masl2 4b82152
Merge branch 'main' into feature/CCM-11600-SB
masl2 035ef65
CCM-11600: correct env ref
masl2 8214c5f
CCM-11600: fix header lookup
masl2 f2de703
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-SB
masl2 78f1441
lockfile
masl2 ca4cf9a
remove placeholder blurb
masl2 0e00a0a
fix copy pasta
masl2 918d058
workspace refs
masl2 096fe7d
lock
masl2 ae4553a
CCM-11600: header references, format, name consistency
masl2 906f465
Merge branch 'main' into feature/CCM-11600-SB
masl2 1aff0f9
revert runner node to 22
masl2 bc5f6ed
fix configs, gen schema
masl2 c3db8ca
add no version param to proxy internal call
masl2 d814180
gitleaksignore readme example
masl2 b319bd8
bad param
masl2 8e9ba8e
test should mismatch header key on case
masl2 61ee8d1
revert redocly version
masl2 632c3c4
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-SB
masl2 23a9e05
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-SB
francisco-videira-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
infrastructure/terraform/components/api/cloudwatch_metric_alarm_apim_auth_cert_expirty.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| resource "aws_cloudwatch_metric_alarm" "alm-apim-client-certificate-near-expiry" { | ||
| alarm_name = "${local.csi}-alm-apim-client-certificate-near-expiry" | ||
| alarm_description = "RELIABILITY: An APIM client certificate is due to expire soon" | ||
|
|
||
| metric_name = "apim-client-certificate-near-expiry" | ||
| namespace = "comms-apim-authorizer" | ||
|
|
||
| dimensions = { | ||
| Environment = var.environment | ||
| } | ||
|
|
||
| period = 60 * 60 * 4 //4 hours | ||
| comparison_operator = "GreaterThanThreshold" | ||
| threshold = "0" | ||
| evaluation_periods = "1" | ||
| statistic = "Sum" | ||
| treat_missing_data = "notBreaching" | ||
|
|
||
| actions_enabled = "false" | ||
| alarm_actions = [] | ||
| ok_actions = [] | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
infrastructure/terraform/components/api/ddb_table_suppliers.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| resource "aws_dynamodb_table" "suppliers" { | ||
| name = "${local.csi}-suppliers" | ||
| billing_mode = "PAY_PER_REQUEST" | ||
|
|
||
| hash_key = "id" | ||
| range_key = "apimId" | ||
|
|
||
| ttl { | ||
| attribute_name = "ttl" | ||
| enabled = false | ||
| } | ||
|
|
||
| global_secondary_index { | ||
| name = "supplier-apim-index" | ||
| hash_key = "apimId" | ||
| projection_type = "ALL" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "id" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "apimId" | ||
| type = "S" | ||
| } | ||
|
|
||
| point_in_time_recovery { | ||
| enabled = true | ||
| } | ||
|
|
||
| tags = var.default_tags | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
internal/datastore/src/__test__/supplier-repository.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { Logger } from "pino"; | ||
| import { createTables, DBContext, deleteTables, setupDynamoDBContainer } from "./db"; | ||
| import { createTestLogger, LogStream } from "./logs"; | ||
| import { SupplierRepository } from "../supplier-repository"; | ||
| import { Supplier } from "../types"; | ||
| import { v4 as uuidv4 } from 'uuid'; | ||
|
|
||
| function createSupplier(status: 'ENABLED' | 'DISABLED', apimId = uuidv4()): Omit<Supplier, 'updatedAt'> { | ||
| return { | ||
| id: uuidv4(), | ||
| name: 'Supplier One', | ||
| apimId, | ||
| status | ||
| } | ||
| } | ||
|
|
||
| // Database tests can take longer, especially with setup and teardown | ||
| jest.setTimeout(30000); | ||
|
|
||
| describe('SupplierRepository', () => { | ||
| let db: DBContext; | ||
| let supplierRepository: SupplierRepository; | ||
| let logStream: LogStream; | ||
| let logger: Logger; | ||
|
|
||
| beforeAll(async () => { | ||
| db = await setupDynamoDBContainer(); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await createTables(db); | ||
| ( | ||
| { logStream, logger } = createTestLogger() | ||
| ); | ||
|
|
||
| supplierRepository = new SupplierRepository(db.docClient, logger, db.config); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await deleteTables(db); | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await db.container.stop(); | ||
| }); | ||
|
|
||
| test('creates an enabled supplier with provided values and timestamps', async () => { | ||
| jest.useFakeTimers(); | ||
| // Month is zero-indexed in JS Date | ||
| jest.setSystemTime(new Date(2020, 1, 1)); | ||
|
|
||
| const supplier = createSupplier('ENABLED'); | ||
|
|
||
| const persistedSupplier = await supplierRepository.putSupplier(supplier); | ||
|
|
||
| expect(persistedSupplier).toEqual(expect.objectContaining({ | ||
| ...supplier, | ||
| updatedAt: '2020-02-01T00:00:00.000Z', | ||
| })); | ||
| }); | ||
|
|
||
| test('fetches a supplier by its ID', async () => { | ||
| const supplier = createSupplier('DISABLED') | ||
| await supplierRepository.putSupplier(supplier); | ||
|
|
||
| const fetched = await supplierRepository.getSupplierById(supplier.id); | ||
|
|
||
| expect(fetched).toEqual(expect.objectContaining({ | ||
| ...supplier | ||
| })); | ||
| }); | ||
|
|
||
| test('throws an error fetching a supplier that does not exist', async () => { | ||
| await expect(supplierRepository.getSupplierById('non-existent-id')) | ||
| .rejects.toThrow('Supplier with id non-existent-id not found'); | ||
| }); | ||
|
|
||
| test('overwrites an existing supplier entry', async () => { | ||
| const supplier = createSupplier('DISABLED'); | ||
|
|
||
| const original = await supplierRepository.putSupplier(supplier); | ||
| expect(original.status).toBe('DISABLED'); | ||
|
|
||
| supplier.status = 'ENABLED'; | ||
| const updated = await supplierRepository.putSupplier(supplier); | ||
| expect(updated.status).toBe('ENABLED'); | ||
| }); | ||
|
|
||
| test('rethrows errors from DynamoDB when creating a letter', async () => { | ||
| const misconfiguredRepository = new SupplierRepository(db.docClient, logger, { | ||
| ...db.config, | ||
| suppliersTableName: 'nonexistent-table' | ||
| }); | ||
| await expect(misconfiguredRepository.putSupplier(createSupplier('ENABLED'))) | ||
| .rejects.toThrow('Cannot do operations on a non-existent table'); | ||
| }); | ||
|
|
||
| test('fetches a supplier by apimId', async () => { | ||
| const supplier = createSupplier('ENABLED'); | ||
|
|
||
| await supplierRepository.putSupplier(supplier); | ||
|
|
||
| const fetched = await supplierRepository.getSupplierByApimId(supplier.apimId); | ||
| expect(fetched).toEqual(expect.objectContaining({ | ||
| ...supplier | ||
| })); | ||
| }); | ||
|
|
||
| test('throws an error fetching a supplier by apimId that does not exist', async () => { | ||
| await expect(supplierRepository.getSupplierByApimId('non-existent-apim-id')) | ||
| .rejects.toThrow('Supplier with apimId non-existent-apim-id not found'); | ||
| }); | ||
|
|
||
| test('throws an error fetching a supplier by apimId when multiple exist', async () => { | ||
| const apimId = 'duplicate-apim-id'; | ||
| const supplier1 = createSupplier('ENABLED', apimId); | ||
| const supplier2 = createSupplier('DISABLED', apimId); | ||
|
|
||
| await supplierRepository.putSupplier(supplier1); | ||
| await supplierRepository.putSupplier(supplier2); | ||
|
|
||
| await expect(supplierRepository.getSupplierByApimId(apimId)) | ||
| .rejects.toThrow(`Multiple suppliers found with apimId ${apimId}`); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './types'; | ||
| export * from './mi-repository'; | ||
| export * from './letter-repository'; | ||
| export * from './supplier-repository'; | ||
| export * from './types'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.