Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
feat: add useHapiValidator CFN parameter (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
carvantes authored Mar 9, 2021
1 parent 910352c commit b7c1137
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions javaHapiValidatorLambda/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ target

# Serverless directories
.serverless
/src/main/resources/implementationGuides/
22 changes: 22 additions & 0 deletions serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ custom:
region: ${opt:region, self:provider.region}
oauthRedirect: ${opt:oauthRedirect, 'http://localhost'}
config: ${file(serverless_config.json)}
useHapiValidator: ${opt:useHapiValidator, 'false'}

provider:
name: aws
Expand All @@ -42,6 +43,11 @@ provider:
!Join ['', ['https://', !Ref UserPoolDomain, !Sub '.auth.${AWS::Region}.amazoncognito.com/oauth2']]
EXPORT_RESULTS_BUCKET: !Ref BulkExportResultsBucket
EXPORT_RESULTS_SIGNER_ROLE_ARN: !GetAtt ExportResultsSignerRole.Arn
VALIDATOR_LAMBDA_ALIAS:
!If
- isUsingHapiValidator
- Fn::ImportValue: "fhir-service-validator-lambda-${self:custom.stage}"
- !Ref AWS::NoValue
apiKeys:
- name: 'developer-key-${self:custom.stage}' # Full name must be known at package-time
description: Key for developer to access the FHIR Api
Expand Down Expand Up @@ -183,9 +189,17 @@ resources:
Type: Number
Default: 5
Description: Number of Glue workers to use during an Export job.
UseHapiValidator:
Type: String
Default: ${self:custom.useHapiValidator}
AllowedValues:
- 'true'
- 'false'
Description: whether or not to use an already deployed HAPI Validator
- Conditions:
isDev: !Equals [!Ref Stage, 'dev']
isNotDev: !Not [Condition: isDev]
isUsingHapiValidator: !Equals [!Ref UseHapiValidator, 'true']
- Resources:
ResourceDynamoDBTableV2:
Type: AWS::DynamoDB::Table
Expand Down Expand Up @@ -413,6 +427,14 @@ resources:
- 'states:StartExecution'
Resource:
- !Ref BulkExportStateMachine
- !If
- isUsingHapiValidator
- Effect: Allow
Action:
- 'lambda:InvokeFunction'
Resource:
- Fn::ImportValue: "fhir-service-validator-lambda-${self:custom.stage}"
- !Ref AWS::NoValue
DdbToEsLambdaRole:
Type: AWS::IAM::Role
Properties:
Expand Down
23 changes: 21 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { FhirConfig, FhirVersion, stubs, BASE_R4_RESOURCES, BASE_STU3_RESOURCES } from 'fhir-works-on-aws-interface';
import {
FhirConfig,
FhirVersion,
stubs,
BASE_R4_RESOURCES,
BASE_STU3_RESOURCES,
Validator,
} from 'fhir-works-on-aws-interface';
import { ElasticSearchService } from 'fhir-works-on-aws-search-es';
import { RBACHandler } from 'fhir-works-on-aws-authz-rbac';
import {
Expand All @@ -14,6 +21,7 @@ import {
DynamoDbUtil,
} from 'fhir-works-on-aws-persistence-ddb';
import JsonSchemaValidator from 'fhir-works-on-aws-routing/lib/router/validation/jsonSchemaValidator';
import HapiFhirLambdaValidator from 'fhir-works-on-aws-routing/lib/router/validation/hapiFhirLambdaValidator';
import RBACRules from './RBACRules';
import { loadImplementationGuides } from './implementationGuides/loadCompiledIGs';

Expand All @@ -24,6 +32,17 @@ const baseResources = fhirVersion === '4.0.1' ? BASE_R4_RESOURCES : BASE_STU3_RE
const authService = IS_OFFLINE ? stubs.passThroughAuthz : new RBACHandler(RBACRules(baseResources), fhirVersion);
const dynamoDbDataService = new DynamoDbDataService(DynamoDb);
const dynamoDbBundleService = new DynamoDbBundleService(DynamoDb);

// Configure the input validators. Validators run in the order that they appear on the array. Use an empty array to disable input validation.
const validators: Validator[] = [];
if (process.env.VALIDATOR_LAMBDA_ALIAS) {
// The HAPI FHIR Validator must be deployed separately. It is the recommended choice when using implementation guides.
validators.push(new HapiFhirLambdaValidator(process.env.VALIDATOR_LAMBDA_ALIAS));
} else {
// The JSON Schema Validator is simpler and is a good choice for testing the FHIR server with minimal configuration.
validators.push(new JsonSchemaValidator(fhirVersion));
}

const esSearch = new ElasticSearchService(
[
{
Expand Down Expand Up @@ -74,7 +93,7 @@ export const fhirConfig: FhirConfig = {
// Unused at this point
level: 'error',
},
validators: [new JsonSchemaValidator(fhirVersion)],
validators,
profile: {
systemOperations: ['transaction'],
bundle: dynamoDbBundleService,
Expand Down

0 comments on commit b7c1137

Please sign in to comment.