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

CMDCT-4247 - v4 serverless upgrade #15041

Merged
merged 8 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 2 additions & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ COGNITO_USER_POOL_CLIENT_ID=op://mdct_devs/seds_secrets/COGNITO_USER_POOL_CLIENT
COGNITO_USER_POOL_CLIENT_DOMAIN=placeholder
COGNITO_REDIRECT_SIGNIN=http://localhost:3000/
COGNITO_REDIRECT_SIGNOUT=http://localhost:3000/

SERVERLESS_LICENSE_KEY=op://mdct_devs/seds_secrets/SERVERLESS_LICENSE_KEY
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ permissions:
id-token: write
contents: read
actions: read

env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}

jobs:
deploy:
runs-on: ubuntu-latest
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
"dotenv": "^8.2.0",
"nightwatch": "3.1.2",
"prettier": "2.2.1",
"serverless": "^3.39.0",
"serverless-bundle": "^6.0.0",
"serverless": "^4.4.18",
"serverless-dotenv-plugin": "^4.0.0",
"serverless-iam-helper": "github:Enterprise-CMCS/serverless-iam-helper",
"serverless-offline": "^13.5.0",
"serverless-offline": "^14.4.0",
"serverless-online": "Enterprise-CMCS/macpro-serverless-online",
"serverless-plugin-scripts": "^1.0.2",
"serverless-s3-bucket-helper": "github:Enterprise-CMCS/serverless-s3-bucket-helper#0.1.1",
"serverless-stack-termination-protection": "^2.0.2",
"typescript": "^4.0.5",
"yargs": "^16.1.1"
Expand Down
8 changes: 4 additions & 4 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ if ! which yarn > /dev/null ; then
fi

# check serverless is installed globally.
if ! which serverless > /dev/null ; then
echo "installing serverless globally"
yarn global add serverless@3.38.0
if ! which serverless > /dev/null || [[ "$(serverless --version | cut -d'.' -f1)" != "4" ]]; then
echo "installing serverless v4 globally"
yarn global add serverless@4.4.18
peoplespete marked this conversation as resolved.
Show resolved Hide resolved
export PATH="$PATH:$(yarn global bin)"
fi

Expand Down Expand Up @@ -76,4 +76,4 @@ fi

# build and run run.ts
# tsc is configured to build what we expect in tsconfig.json
./node_modules/.bin/tsc && node ./build_dev/run.js "${ARGS[@]-}"
./node_modules/.bin/tsc && node ./build_dev/run.js "${ARGS[@]-}"
2 changes: 1 addition & 1 deletion services/app-api/auth/authConditions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentUserInfo } from "../auth/cognito-auth";
import { getCurrentUserInfo } from "../auth/cognito-auth.js";

/** Throws an exception unless the current user is authenticated. */
export const authorizeAnyUser = async (event) => {
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/auth/cognito-auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getUserDetailsFromEvent } from "../libs/authorization";
import { obtainUserByEmail } from "../handlers/users/post/obtainUserByEmail";
import { getUserDetailsFromEvent } from "../libs/authorization.js";
import { obtainUserByEmail } from "../handlers/users/post/obtainUserByEmail.js";

export const getCurrentUserInfo = async (event) => {
const user = await getUserDetailsFromEvent(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdmin } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

/**
* Returns a single form template
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdmin } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAdmin(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdmin } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAdmin(event);
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/forms/get.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "./../../libs/handler-lib";
import dynamoDb from "./../../libs/dynamodb-lib";
import { authorizeAdminOrUserForState } from "../../auth/authConditions";
import handler from "./../../libs/handler-lib.js";
import dynamoDb from "./../../libs/dynamodb-lib.js";
import { authorizeAdminOrUserForState } from "../../auth/authConditions.js";

export const main = handler(async (event, context) => {
// Deconstruct variables from URL string
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/forms/get/getFormTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAnyUser } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAnyUser } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAnyUser(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import {
getFormDescriptions,
getQuestionsByYear,
getStatesList,
findExistingStateForms,
fetchOrCreateQuestions,
getAnswersSet,
} from "../../shared/sharedFunctions";
import { authorizeAdmin } from "../../../auth/authConditions";
} from "../../shared/sharedFunctions.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

/** Called from the API; admin access required */
export const main = handler(async (event, context) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authorizeAdminOrUserForState } from "../../../auth/authConditions";
import dynamodbLib from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib";
import { authorizeAdminOrUserForState } from "../../../auth/authConditions.js";
import dynamodbLib from "../../../libs/dynamodb-lib.js";
import handler from "../../../libs/handler-lib.js";

/**
* Returns list of all forms based on state
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/forms/post/obtainFormsList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdminOrUserForState } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdminOrUserForState } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
const data = JSON.parse(event.body);
Expand Down
8 changes: 4 additions & 4 deletions services/app-api/handlers/forms/post/saveForm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import cloneDeepWith from "lodash/cloneDeepWith";
import { authorizeUserForState } from "../../../auth/authConditions";
import { getCurrentUserInfo } from "../../../auth/cognito-auth";
import { authorizeUserForState } from "../../../auth/authConditions.js";
import { getCurrentUserInfo } from "../../../auth/cognito-auth.js";

/**
* This handler will loop through a question array and save each row
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/kafka/get/forceKafkaSync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import chunk from "lodash/chunk";

const tableNames = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import KafkaSourceLib from "../../../libs/kafka-source-lib";
import KafkaSourceLib from "../../../libs/kafka-source-lib.js";

class DataConnectTransform extends KafkaSourceLib {
topicPrefix = "aws.mdct.seds.cdc";
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/handlers/kafka/post/postKafkaData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import KafkaSourceLib from "../../../libs/kafka-source-lib";
import KafkaSourceLib from "../../../libs/kafka-source-lib.js";

class PostKafkaData extends KafkaSourceLib {
topicPrefix = "aws.mdct.seds.cdc";
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/notification/businessUsers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import handler from "./../../libs/handler-lib";
import handler from "./../../libs/handler-lib.js";
import {
getUsersEmailByRole,
getUncertifiedStatesAndForms,
} from "../shared/sharedFunctions";
} from "../shared/sharedFunctions.js";
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";

const client = new SESClient({ region: "us-east-1" });
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/notification/stateUsers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import handler from "./../../libs/handler-lib";
import handler from "./../../libs/handler-lib.js";
import {
getUsersEmailByRole,
getUncertifiedStates,
} from "../shared/sharedFunctions";
} from "../shared/sharedFunctions.js";
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";

const client = new SESClient({ region: "us-east-1" });
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/notification/uncertified.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "./../../libs/handler-lib";
import dynamoDb from "./../../libs/dynamodb-lib";
import { authorizeStateUser } from "../../auth/authConditions";
import handler from "./../../libs/handler-lib.js";
import dynamoDb from "./../../libs/dynamodb-lib.js";
import { authorizeStateUser } from "../../auth/authConditions.js";
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";

const client = new SESClient({ region: "us-east-1" });
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/handlers/shared/sharedFunctions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dynamoDb from "../../libs/dynamodb-lib";
import dynamoDb from "../../libs/dynamodb-lib.js";

export async function getUsersEmailByRole(role) {
const params = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdmin } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAdmin(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeUserForState } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeUserForState } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
// Get year and quarter from request
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/users/get/getUserById.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import {
authorizeAdminOrUserWithEmail,
authorizeAnyUser,
} from "../../../auth/authConditions";
} from "../../../auth/authConditions.js";

export const main = handler(async (event) => {
await authorizeAnyUser(event);
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/users/get/getUsername.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "../../../libs/handler-lib";
import { getCurrentUserInfo } from "../../../auth/cognito-auth";
import handler from "../../../libs/handler-lib.js";
import { getCurrentUserInfo } from "../../../auth/cognito-auth.js";

export const main = handler(async (event) => {
let currentUser = await getCurrentUserInfo(event);
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/users/get/listUsers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { authorizeAdmin } from "../../../auth/authConditions";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { authorizeAdmin } from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAdmin(event);
Expand Down
8 changes: 4 additions & 4 deletions services/app-api/handlers/users/post/createUser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { obtainUserByUsername } from "./obtainUserByUsername";
import { getUserDetailsFromEvent } from "../../../libs/authorization";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { obtainUserByUsername } from "./obtainUserByUsername.js";
import { getUserDetailsFromEvent } from "../../../libs/authorization.js";

export const main = handler(async (event, context) => {
const userData = await getUserDetailsFromEvent(event);
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/users/post/deleteUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";

export const main = handler(async (event, context) => {
const data = JSON.parse(event.body);
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/handlers/users/post/obtainUserByEmail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import {
authorizeAdminOrUserWithEmail,
authorizeAnyUser,
} from "../../../auth/authConditions";
} from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
let data = JSON.parse(event.body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import {
authorizeAnyUser,
authorizeAdminOrUserWithEmail,
} from "../../../auth/authConditions";
} from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAnyUser(event);
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/handlers/users/post/obtainUsernameBySub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";

export const main = handler(async (event, context) => {
let data = JSON.parse(event.body);
Expand Down
8 changes: 4 additions & 4 deletions services/app-api/handlers/users/post/updateUser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { obtainUserByEmail } from "./obtainUserByEmail";
import handler from "../../../libs/handler-lib.js";
import dynamoDb from "../../../libs/dynamodb-lib.js";
import { obtainUserByEmail } from "./obtainUserByEmail.js";
import {
authorizeAdmin,
authorizeAdminOrUserWithEmail,
authorizeAnyUser,
} from "../../../auth/authConditions";
} from "../../../auth/authConditions.js";

export const main = handler(async (event, context) => {
await authorizeAnyUser(event);
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/libs/authorization.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";
import jwt_decode from "jwt-decode";
import { CognitoJwtVerifier } from "aws-jwt-verify";
import * as logger from "./debug-lib";
import * as logger from "./debug-lib.js";
import { SimpleJwksCache } from "aws-jwt-verify/jwk";
import { SimpleJsonFetcher } from "aws-jwt-verify/https";

Expand Down
2 changes: 1 addition & 1 deletion services/app-api/libs/dynamodb-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ScanCommand,
UpdateCommand,
} from "@aws-sdk/lib-dynamodb";
import { logger } from "./debug-lib";
import { logger } from "./debug-lib.js";

const localConfig = {
endpoint: process.env.DYNAMODB_URL,
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/libs/handler-lib.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as logger from "./debug-lib";
import * as logger from "./debug-lib.js";

export default function handler(lambda) {
return async function (event, context) {
Expand Down
8 changes: 3 additions & 5 deletions services/app-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
"minimist": "^1.2.5"
},
"main": "handler.js",
"scripts": {
"test": "serverless-bundle test --unhandled-rejections=warn"
},
"type": "module",
"scripts": {},
"author": "",
"license": "CC0-1.0",
"repository": {
"type": "git",
"url": "https://github.com/AnomalyInnovations/serverless-nodejs-starter.git"
},
"devDependencies": {
"serverless-associate-waf": "^1.2.1",
"serverless-offline-ssm": "^6.2.0"
"serverless-associate-waf": "^1.2.1"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.709.0",
Expand Down
Loading
Loading