Skip to content
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

Chore: [AEA-3864] - Enable OAuth authorisation for proxy #175

Merged
merged 23 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
404c6d8
[AEA-3864] updated auth to lvl 3 and misc cleanup
Orkastrated Apr 29, 2024
9f9000f
[AEA-3864] fixed package.json
Orkastrated Apr 29, 2024
7fd97f9
[AEA-3864] debugging pipeline
Orkastrated Apr 29, 2024
3354053
[AEA-3864] added securitySchema replacement to deploy_api
Orkastrated Apr 29, 2024
4d4d35b
[AEA-3864] debugging deployment
Orkastrated Apr 29, 2024
642eb46
[AEA-3864] update deploy_api to tweak proxy title for PR's
Orkastrated Apr 30, 2024
3e6d3b4
[AEA-3836] resolve merge conflict
Orkastrated Apr 30, 2024
d8004c8
[AEA-3864] resolving conflict
Orkastrated Apr 30, 2024
abb87d9
[AEA-3864] tweaking script for replacing title
Orkastrated May 1, 2024
c5305ea
Merge branch 'main' of github.com:NHSDigital/eps-prescription-status-…
Orkastrated May 1, 2024
e09d88d
[AEA-3864] tweaking title replacement
Orkastrated May 1, 2024
01faf87
[AEA-3864] initial auth script
Orkastrated May 8, 2024
d16c5b4
[AEA-3864] resolve conflict
Orkastrated May 8, 2024
a918eeb
[AEA-3864] added main commands to auth cli
Orkastrated May 8, 2024
b7cdc0f
[AEA-3864] added cred functions to cli
Orkastrated May 9, 2024
728823f
[AEA-3864] update resource names to be consistent with pfp
Orkastrated May 9, 2024
d115ece
[AEA-3864] resolve merge conflict
Orkastrated May 9, 2024
79d53ea
[AEA-3864] fixing cf issiues
Orkastrated May 9, 2024
175d75a
[AEA-3864] misc tweaks
Orkastrated May 9, 2024
a3d6834
trigger build
Orkastrated May 9, 2024
1324e63
[AEA-3864] moved cli into scripts folder
Orkastrated May 13, 2024
54dee9e
[AEA-3684] resolve conflict
Orkastrated May 13, 2024
5b4df99
trigger build
Orkastrated May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/scripts/deploy_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ else
fi
echo "Proxy instance: $instance"

# Find and replace the title
title=$(jq -r '.info.title' "$SPEC_PATH")
if [[ $STACK_NAME == psu-pr-* ]]; then
jq --arg title "[PR-$pr_id] $title" '.info.title = $title' "$SPEC_PATH" > temp.json && mv temp.json "$SPEC_PATH"
fi

# Find and replace the specification version number
jq --arg version "$VERSION_NUMBER" '.info.version = $version' "$SPEC_PATH" > temp.json && mv temp.json "$SPEC_PATH"

Expand All @@ -30,6 +36,12 @@ else
jq --arg env "$APIGEE_ENVIRONMENT" --arg inst "$instance" '.servers = [ { "url": "https://\($env).api.service.nhs.uk/\($inst)" } ]' "$SPEC_PATH" > temp.json && mv temp.json "$SPEC_PATH"
fi

# Find and replace securitySchemes
if [[ $APIGEE_ENVIRONMENT == prod ]]; then
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "$SPEC_PATH" > temp.json && mv temp.json "$SPEC_PATH"
else
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "$SPEC_PATH" > temp.json && mv temp.json "$SPEC_PATH"
fi
# Retrieve the proxygen private key and client private key and cert from AWS Secrets Manager
proxygen_private_key_arn=$(aws cloudformation list-exports --query "Exports[?Name=='account-resources:ProxgenPrivateKey'].Value" --output text)
client_private_key_arn=$(aws cloudformation list-exports --query "Exports[?Name=='account-resources:PsuClientKeySecret'].Value" --output text)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sam_package_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
cp .tool-versions ~/
rm -rf .aws-sam
export PATH=$PATH:$PWD/node_modules/.bin
make publish
make build-specification
make sam-build
cp Makefile .aws-sam/build/
cp samconfig_package_and_deploy.toml .aws-sam/build/
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ test: compile
npm run test --workspace packages/updatePrescriptionStatus
npm run test --workspace packages/gsul
npm run test --workspace packages/sandbox
npm run test --workspace packages/specification
npm run test --workspace packages/statusLambda

clean:
Expand All @@ -139,10 +138,8 @@ deep-clean: clean
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
poetry env remove --all

publish:
npm run resolve --workspace packages/specification 2> /dev/null
npm run compile --workspace packages/specification 2> /dev/null
npm run replace-components --workspace packages/specification 2> /dev/null
build-specification:
$(MAKE) --directory=packages/specification build

check-licenses: check-licenses-node check-licenses-python

Expand Down
32 changes: 16 additions & 16 deletions SAMtemplates/apis/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AWSTemplateFormatVersion: '2010-09-09'
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: |
PSU API's and related resources
Expand All @@ -7,32 +7,32 @@ Parameters:
StackName:
Type: String
Default: none

EnableMutualTLS:
Type: String

TruststoreVersion:
Type: String

UpdatePrescriptionStatusStateMachineName:
Type: String
Default: none

UpdatePrescriptionStatusStateMachineArn:
Type: String
Default: none

StatusLambdaFunctionName:
StatusFunctionName:
Type: String
Default: none

StatusLambdaFunctionArn:
StatusFunctionArn:
Type: String
Default: none

LogRetentionInDays:
Type: Number

EnableSplunk:
Type: String

Expand Down Expand Up @@ -77,7 +77,7 @@ Resources:
- - !Ref StackName
- !ImportValue eps-route53-resources:EPS-domain
RegionalCertificateArn: !Ref GenerateCertificate
EndpointConfiguration:
EndpointConfiguration:
Types:
- REGIONAL
SecurityPolicy: TLS_1_2
Expand All @@ -90,7 +90,7 @@ Resources:
- !Select
- 5
- !Split
- ':'
- ":"
- !ImportValue account-resources:TrustStoreBucket
- psu-truststore.pem
- !Ref AWS::NoValue
Expand Down Expand Up @@ -204,15 +204,15 @@ Resources:

$payload.Payload.body
MethodResponses:
- StatusCode: '200'
- StatusCode: "200"

StatusLambdaMethodResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref RestApiGateway
ParentId: !GetAtt RestApiGateway.RootResourceId
PathPart: _status

StatusLambdaMethod:
Type: AWS::ApiGateway::Method
Properties:
Expand All @@ -224,7 +224,7 @@ Resources:
Type: AWS_PROXY
Credentials: !GetAtt RestApiGatewayResources.Outputs.ApiGwRoleArn
IntegrationHttpMethod: POST
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StatusLambdaFunctionArn}/invocations
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StatusFunctionArn}/invocations

# *********************************************************************
# if you add a new endpoint, then change the name of this resource
Expand All @@ -250,7 +250,7 @@ Resources:
AccessLogSetting:
DestinationArn: !GetAtt RestApiGatewayResources.Outputs.ApiGwAccessLogsArn
Format: '{ "requestTime": "$context.requestTime", "apiId": "$context.apiId", "accountId": "$context.accountId", "resourcePath": "$context.resourcePath", "stage": "$context.stage", "requestId": "$context.requestId", "extendedRequestId": "$context.extendedRequestId", "status": "$context.status", "httpMethod": "$context.httpMethod", "protocol": "$context.protocol", "path": "$context.path", "responseLatency": "$context.responseLatency", "responseLength": "$context.responseLength", "domainName": "$context.domainName", "identity": { "sourceIp": "$context.identity.sourceIp", "userAgent": "$context.identity.userAgent", "clientCert":{ "subjectDN": "$context.identity.clientCert.subjectDN", "issuerDN": "$context.identity.clientCert.issuerDN", "serialNumber": "$context.identity.clientCert.serialNumber", "validityNotBefore": "$context.identity.clientCert.validity.notBefore", "validityNotAfter": "$context.identity.clientCert.validity.notAfter" }}, "integration":{ "error": "$context.integration.error", "integrationStatus": "$context.integration.integrationStatus", "latency": "$context.integration.latency", "requestId": "$context.integration.requestId", "status": "$context.integration.status" }}'

RestApiDomainMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
Expand All @@ -264,9 +264,9 @@ Resources:
Location: api_resources.yaml
Parameters:
AdditionalPolicies: !Join
- ','
- ","
- - Fn::ImportValue: !Sub ${StackName}:state-machines:${UpdatePrescriptionStatusStateMachineName}:ExecuteStateMachinePolicy
- Fn::ImportValue: !Sub ${StackName}:functions:${StatusLambdaFunctionName}:ExecuteLambdaPolicyArn
- Fn::ImportValue: !Sub ${StackName}:functions:${StatusFunctionName}:ExecuteLambdaPolicyArn
ApiName: !Sub ${StackName}-apigw
LogRetentionInDays: !Ref LogRetentionInDays
EnableSplunk: !Ref EnableSplunk
22 changes: 11 additions & 11 deletions SAMtemplates/functions/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ Resources:
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream

StatusLambdaFunction:
Status:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-statusLambda
FunctionName: !Sub ${StackName}-status
CodeUri: ../../packages
Handler: statusLambda.handler
Role: !GetAtt StatusLambdaFunctionResources.Outputs.LambdaRoleArn
Role: !GetAtt StatusResources.Outputs.LambdaRoleArn
Environment:
Variables:
VERSION_NUMBER: !Ref VersionNumber
Expand All @@ -140,14 +140,14 @@ Resources:
EntryPoints:
- statusLambda/src/statusLambda.ts

StatusLambdaFunctionResources:
StatusResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-statusLambda
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-statusLambda
LambdaName: !Sub ${StackName}-status
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-status
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
Expand Down Expand Up @@ -177,10 +177,10 @@ Outputs:
Export:
Name: !Sub ${StackName}:functions:GetStatusUpdates:FunctionArn

StatusLambdaFunctionName:
StatusFunctionName:
Description: The function name of the Status lambda
Value: !Ref StatusLambdaFunction
StatusLambdaFunctionArn:
Value: !Ref Status

StatusFunctionArn:
Description: The function ARN of the Status lambda
Value: !GetAtt StatusLambdaFunction.Arn
Value: !GetAtt Status.Arn
4 changes: 2 additions & 2 deletions SAMtemplates/main_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Resources:
TruststoreVersion: !Ref TruststoreVersion
UpdatePrescriptionStatusStateMachineName: !GetAtt StateMachines.Outputs.UpdatePrescriptionStatusStateMachineName
UpdatePrescriptionStatusStateMachineArn: !GetAtt StateMachines.Outputs.UpdatePrescriptionStatusStateMachineArn
StatusLambdaFunctionName: !GetAtt Functions.Outputs.StatusLambdaFunctionName
StatusLambdaFunctionArn: !GetAtt Functions.Outputs.StatusLambdaFunctionArn
StatusFunctionName: !GetAtt Functions.Outputs.StatusFunctionName
StatusFunctionArn: !GetAtt Functions.Outputs.StatusFunctionArn
LogRetentionInDays: !Ref LogRetentionInDays
EnableSplunk: !Ref EnableSplunk

Expand Down
15 changes: 15 additions & 0 deletions packages/specification/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SHELL=/bin/bash -euo pipefail

.PHONY: install build test publish release clean

install:
npm ci

clean:
rm -rf dist/

build:
mkdir -p dist
npm run lint
npm run resolve
ls -la dist
10 changes: 6 additions & 4 deletions packages/specification/eps-prescription-status-update-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ paths:
example:
$ref: examples/error-ods-code.json
security:
- app-level0: []
- app-level3: []
components:
securitySchemes:
app-level0:
$ref: https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level0
app-level3:
$ref: https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level3
parameters:
BearerAuthorisation:
in: header
Expand Down Expand Up @@ -295,13 +295,15 @@ components:
$ref: "schemas/components/ResponseBundle.yaml"
OperationOutcome:
$ref: schemas/resources/OperationOutcome.yaml
security:
- app-level3: []
x-nhsd-apim:
temporary: false
monitoring: false
access:
- title: Application Restricted
grants:
app-level0: []
app-level3: []
target:
type: external
healthcheck: /_status
Expand Down
3 changes: 0 additions & 3 deletions packages/specification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"unit": "POWERTOOLS_DEV=true NODE_OPTIONS=--experimental-vm-modules jest --no-cache --coverage",
"lint": "swagger-cli validate eps-prescription-status-update-api.yaml",
"resolve": "swagger-cli bundle eps-prescription-status-update-api.yaml -r -o dist/eps-prescription-status-update-api.resolved.json",
"replace-components": "node lib/src/replaceComponents.js",
"compile": "tsc",
"clean": "rm -rf lib coverage",
"test": "npm run clean && npm run resolve && npm run compile && npm run replace-components && npm run unit",
"check-licenses": "license-checker --failOn GPL --failOn LGPL --start ../.."
},
"author": "NHS Digital",
Expand Down
22 changes: 0 additions & 22 deletions packages/specification/src/replaceComponents.ts

This file was deleted.

39 changes: 0 additions & 39 deletions packages/specification/tests/testReplaceComponents.test.ts

This file was deleted.

Loading