Skip to content

Commit

Permalink
Merge pull request #13 from Notarise-gov-sg/chore/node-18
Browse files Browse the repository at this point in the history
Chore/node 18
  • Loading branch information
dchocoboo authored May 17, 2023
2 parents d070d48 + b00fdea commit 0cc13f4
Show file tree
Hide file tree
Showing 10 changed files with 13,611 additions and 7,762 deletions.
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy-peer-deps=true
engine-strict=false
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/fermium
lts/hydrogen
21,237 changes: 13,519 additions & 7,718 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 23 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,46 @@
"description": "OCSP Responder Reference Implementation",
"main": "serverless.ts",
"scripts": {
"postinstall": "sls dynamodb install",
"dev": "cross-env STAGE=dev sls offline start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": ">=14.15.0"
"node": ">=18",
"npm": ">=9"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.332.0",
"@aws-sdk/lib-dynamodb": "^3.332.0",
"@middy/core": "^3.0.3",
"@middy/http-cors": "^3.0.4",
"@middy/http-error-handler": "^3.0.3",
"@middy/http-json-body-parser": "^3.0.3",
"aws-sdk": "^2.1141.0",
"aws-sdk": "^2.1379.0",
"http-errors": "^2.0.0",
"serverless-stack-termination-protection": "^2.0.2",
"yargs": "^17.5.1"
"yargs": "^17.7.2"
},
"overrides": {
"dynamodb-localhost": {
"mocha": "^10.2.0"
}
},
"devDependencies": {
"@serverless/typescript": "^3.18.0",
"@types/aws-lambda": "^8.10.97",
"@serverless/typescript": "^3.30.1",
"@types/aws-lambda": "^8.10.115",
"@types/http-errors": "^1.8.2",
"@types/node": "^14.18.18",
"@types/node": "^20.1.7",
"cross-env": "^7.0.3",
"esbuild": "^0.14.39",
"json-schema-to-ts": "^2.5.1",
"serverless": "^3.18.2",
"serverless-bundle": "^5.3.0",
"esbuild": "^0.17.19",
"json-schema-to-ts": "^2.8.2",
"serverless": "^3.30.1",
"serverless-bundle": "^6.0.0",
"serverless-domain-manager": "^6.0.3",
"serverless-dynamodb-local": "^0.2.40",
"serverless-offline": "^8.8.0",
"serverless-slic-watch-plugin": "^1.2.0",
"serverless-vpc-discovery": "^4.0.2",
"ts-node": "^10.8.0",
"tsconfig-paths": "^4.0.0",
"serverless-offline": "^12.0.4",
"serverless-slic-watch-plugin": "^2.1.3",
"serverless-vpc-discovery": "^4.1.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.6.4"
},
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
Expand Down
2 changes: 1 addition & 1 deletion serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const serverlessConfiguration = async (): Promise<AWS> => {
provider: {
stage,
name: "aws",
runtime: "nodejs14.x",
runtime: "nodejs18.x",
region: "ap-southeast-1",
apiGateway: {
minimumCompressionSize: 1024,
Expand Down
13 changes: 6 additions & 7 deletions src/functions/insert/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import createError from "http-errors";
import type { ValidatedEventAPIGatewayProxyEvent } from "@libs/api-gateway";
import { formatJSONResponse } from "@libs/api-gateway";
import { middyfy } from "@libs/lambda";
import { client } from "@services/dynamoDb";
import { putItem } from "@services/dynamoDb";

import schema from "./schema";

Expand All @@ -18,15 +18,14 @@ const insert: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (event)
throw new createError.BadRequest(`Invalid reasonCode. Please use one of the following values: ${REASON_CODES}`);
}

await client
.put({
try{
await putItem({
TableName: process.env.REVOCATION_TABLE,
Item: { documentHash, reasonCode },
})
.promise()
.catch((e) => {
throw new createError.InternalServerError(e);
});
} catch (e){
throw new createError.InternalServerError(e);
}

return formatJSONResponse({
success: true,
Expand Down
17 changes: 9 additions & 8 deletions src/functions/query/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import createError from "http-errors";
import type { ValidatedEventAPIGatewayProxyEvent } from "@libs/api-gateway";
import { formatJSONResponse } from "@libs/api-gateway";
import { middyfy } from "@libs/lambda";
import { client } from "@services/dynamoDb";
import { getItem } from "@services/dynamoDb";

const query: ValidatedEventAPIGatewayProxyEvent<void> = async (event) => {
const { documentHash } = event.pathParameters;
Expand All @@ -12,23 +12,24 @@ const query: ValidatedEventAPIGatewayProxyEvent<void> = async (event) => {
throw new createError.BadRequest(`documentHash (string) required`);
}

const data = await client
.get({
let data: Record<string, any>;

try{
data = await getItem({
TableName: process.env.REVOCATION_TABLE,
Key: { documentHash },
})
.promise()
.catch((e) => {
throw new createError.InternalServerError(e);
});
} catch (e){
throw new createError.InternalServerError(e);
}

if (
// When no entry is found, an empty object is returned (E.g. `{}`)
Object.keys(data).length === 0 &&
Object.getPrototypeOf(data) === Object.prototype
) {
return formatJSONResponse({ revoked: false, documentHash });
} else if (data.Item && data.Item.documentHash && data.Item.reasonCode !== undefined) {
} else if (data && data.documentHash && data.Item.reasonCode !== undefined) {
return formatJSONResponse({
revoked: true,
documentHash: data.Item.documentHash,
Expand Down
15 changes: 7 additions & 8 deletions src/functions/remove/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import createError from "http-errors";
import type { ValidatedEventAPIGatewayProxyEvent } from "@libs/api-gateway";
import { formatJSONResponse } from "@libs/api-gateway";
import { middyfy } from "@libs/lambda";
import { client } from "@services/dynamoDb";
import { deleteItem } from "@services/dynamoDb";

const remove: ValidatedEventAPIGatewayProxyEvent<void> = async (event) => {
const { documentHash } = event.pathParameters;
Expand All @@ -12,15 +12,14 @@ const remove: ValidatedEventAPIGatewayProxyEvent<void> = async (event) => {
throw new createError.BadRequest(`documentHash (string) required`);
}

await client
.delete({
try {
await deleteItem({
TableName: process.env.REVOCATION_TABLE,
Key: { documentHash },
})
.promise()
.catch((e) => {
throw new createError.InternalServerError(e);
});
});
} catch (e) {
throw new createError.InternalServerError(e);
}

return formatJSONResponse({
success: true,
Expand Down
36 changes: 34 additions & 2 deletions src/services/dynamoDb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DynamoDB } from "aws-sdk";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand, GetCommand, QueryCommand, DeleteCommand } from "@aws-sdk/lib-dynamodb";

const options =
process.env.STAGE === "dev"
Expand All @@ -10,4 +11,35 @@ const options =
}
: {};

export const client = new DynamoDB.DocumentClient(options);
const dynamoDocumentDb = DynamoDBDocumentClient.from(new DynamoDBClient(options), {
marshallOptions: {
convertEmptyValues: true
}
});

export const putItem = async (params: any) => {
await dynamoDocumentDb.send(new PutCommand(params));
return true;
};

export const deleteItem = async (params: any) => {
await dynamoDocumentDb.send(new DeleteCommand(params));
return true;
};

export const getItem = async (params: any): Promise<Record<string, any>> => {
const result = await dynamoDocumentDb.send(new GetCommand(params));

if (result && result.Item) {
return result.Item;
}
return {};
};

export const queryItems = async (params: any) => {
const result = await dynamoDocumentDb.send(new QueryCommand(params));
if (result && result.Items) {
return result.Items;
}
return [];
};

0 comments on commit 0cc13f4

Please sign in to comment.