Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpaige committed Dec 19, 2024
1 parent 73df0ab commit e2f4b33
Show file tree
Hide file tree
Showing 31 changed files with 994 additions and 1,543 deletions.
38 changes: 2 additions & 36 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: disable
name: Deploy

on:
Expand All @@ -6,6 +7,7 @@ on:
- "*"
- "!skipci*"

# yaml-language-server: $schema: https://json.schemastore.org/github-workflow.json
concurrency:
group: ${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}-group

Expand Down Expand Up @@ -188,42 +190,6 @@ jobs:
uses: stelligent/[email protected]
with:
input_path: cftemplates
resources:
runs-on: ubuntu-20.04
needs:
- deploy
environment:
name: ${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: ./.github/actions/setup

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
role-duration-seconds: 10800

- name: Get AWS Stage Resources
id: stage-resources
run: |
mkdir -p resources
resourceData=()
stackList=(`aws cloudformation describe-stacks --query "Stacks[?Tags[?Key=='STAGE' && Value=='$STAGE_NAME'] && Tags[?Key=='PROJECT' && Value=='$PROJECT']].StackName" --output text`)
for stack in "${stackList[@]}"; do
resources=$(aws cloudformation list-stack-resources --stack-name "$stack" --query "StackResourceSummaries[].{PhysicalResourceId:PhysicalResourceId, ResourceType:ResourceType, ResourceStatus:ResourceStatus, LogicalResourceId:LogicalResourceId, LastUpdatedTimestamp:LastUpdatedTimestamp}" --output json)
resourceData+=( $(echo "$resources" | jq -c --arg stack_name "$stack" '.[] + { StackName: $stack_name }') )
done
join_by() { local IFS="$1"; shift; echo "$*"; }
echo "["$(join_by "," "${resourceData[@]}")"]" > "resources/aws-resources.json"
- name: Archive stage resources
uses: actions/upload-artifact@v3
with:
name: aws-resources-${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}
path: resources/aws-resources.json

release:
runs-on: ubuntu-20.04
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ node_modules
cdk.out
cdk.context.json
.turbo
.yarn_install

build_run
.build_run
DS_Store
Expand All @@ -22,3 +22,4 @@ DS_Store
# tests
coverage
__snapshots__
.repo_ignore
13 changes: 13 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends: default

rules:
document-start: disable
line-length: disable
truthy:
allowed-values: ['true', 'false', 'on', 'off', 'yes', 'no']
comments:
min-spaces-from-content: 1

ignore: |
node_modules/
.github/
37 changes: 7 additions & 30 deletions bin/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
runCommand,
project,
region,
writeUiEnvFile,
} from "../lib/";
import path from "path";
import { checkIfAuthenticated, runCommand, project, region, writeUiEnvFile } from "../lib/";
import * as path from "path";
import { execSync } from "child_process";
import {
CloudFrontClient,
CreateInvalidationCommand,
} from "@aws-sdk/client-cloudfront";
import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront";
import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";

export const deploy = {
Expand All @@ -22,11 +13,7 @@ export const deploy = {
},
handler: async (options: { stage: string; stack?: string }) => {
await checkIfAuthenticated();
await runCommand(
"cdk",
["deploy", "-c", `stage=${options.stage}`, "--all"],
".",
);
await runCommand("cdk", ["deploy", "-c", `stage=${options.stage}`, "--all"], ".");

await writeUiEnvFile(options.stage);

Expand Down Expand Up @@ -57,16 +44,8 @@ export const deploy = {
// There's a mime type issue when aws s3 syncing files up
// Empirically, this issue never presents itself if the bucket is cleared just before.
// Until we have a neat way of ensuring correct mime types, we'll remove all files from the bucket.
await runCommand(
"aws",
["s3", "rm", `s3://${s3BucketName}/`, "--recursive"],
".",
);
await runCommand(
"aws",
["s3", "sync", buildDir, `s3://${s3BucketName}/`],
".",
);
await runCommand("aws", ["s3", "rm", `s3://${s3BucketName}/`, "--recursive"], ".");
await runCommand("aws", ["s3", "sync", buildDir, `s3://${s3BucketName}/`], ".");

const cloudfrontClient = new CloudFrontClient({
region,
Expand All @@ -82,9 +61,7 @@ export const deploy = {
},
};

await cloudfrontClient.send(
new CreateInvalidationCommand(invalidationParams),
);
await cloudfrontClient.send(new CreateInvalidationCommand(invalidationParams));

console.log(
`Deployed UI to S3 bucket ${s3BucketName} and invalidated CloudFront distribution ${cloudfrontDistributionId}`,
Expand Down
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
1 change: 0 additions & 1 deletion lib/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@aws-sdk/client-s3": "^3.600.0",
"@aws-sdk/client-sfn": "^3.600.0",
"@aws-sdk/s3-request-presigner": "^3.600.0",
"@haftahave/serverless-ses-template": "^6.1.0",
"base-64": "^1.0.0",
"cfn-response-async": "^1.0.0",
"mssql": "^11.0.0",
Expand Down
92 changes: 92 additions & 0 deletions lib/lambda/processEmails.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { describe, it, expect, vi } from "vitest";
import { handler as processEmailsHandler } from "./processEmails";

vi.mock("aws-sdk/clients/sqs", () => {
return {
SQS: vi.fn().mockImplementation(() => {
return {
sendMessage: vi.fn().mockReturnValue({ promise: () => Promise.resolve({}) })
};
})
};
});

vi.mock("../processEmails", async () => {
const actual = await vi.importActual("../processEmails");
return {
...actual,
// If needed, mock internal functions
};
});

describe("processEmails handler", () => {
it("should gracefully handle an empty records set", async () => {
const event = {
records: {}
};
const res = await processEmailsHandler(event as any, {} as any, () => {});
// no error means passed
expect(res).toBeUndefined();
});

it("should process a valid record without errors", async () => {
const event = {
records: {
"test-topic": [
{
key: Buffer.from("testKey").toString("base64"),
value: Buffer.from(JSON.stringify({ event: "new-medicaid-submission", authority: "Medicaid SPA", origin: "mako" })).toString("base64"),
timestamp: Date.now(),
}
]
}
};
const res = await processEmailsHandler(event as any, {} as any, () => {});
expect(res).toBeUndefined();
});
});
40 changes: 40 additions & 0 deletions40
lib/lambda/__tests__/sinkMain.test.ts
Viewed
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, it, expect, vi } from "vitest";
import { handler as sinkMainHandler } from "../sinkMain";

vi.mock("../sinkMainProcessors", () => {
return {
insertOneMacRecordsFromKafkaIntoMako: vi.fn(() => Promise.resolve()),
insertNewSeatoolRecordsFromKafkaIntoMako: vi.fn(() => Promise.resolve()),
syncSeatoolRecordDatesFromKafkaWithMako: vi.fn(() => Promise.resolve())
};
});

describe("sinkMain handler", () => {
it("handles empty event gracefully", async () => {
const event = {
records: {}
};
const res = await sinkMainHandler(event as any, {} as any, () => {});
expect(res).toBeUndefined();
});

it("handles unknown topic gracefully", async () => {
const event = {
records: {
"unknown-topic": [
{
key: "base64Key",
value: "base64Value",
topic: "unknown-topic",
partition: 0,
offset: 0,
timestamp: Date.now(),
timestampType: "CREATE_TIME",
headers: {}
}
]
}
};
await expect(sinkMainHandler(event as any, {} as any, () => {})).rejects.toThrow();
});
});
Loading

0 comments on commit e2f4b33

Please sign in to comment.