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

fix: initialization of NotifyClient is not working because of the way we pass the API key #576

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const TEMPLATE_ID = process.env.TEMPLATE_ID;

if (!KEY_ARN || !KEY_ALIAS || !TEMPLATE_ID) {
throw new Error(
`Missing Environment Variables: ${KEY_ARN ? "" : "Key ARN"} ${KEY_ALIAS ? "" : "Key Alias"} ${
TEMPLATE_ID ? "" : "Template ID"
`Missing Environment Variables: ${KEY_ARN ? "" : "Key ARN"} ${KEY_ALIAS ? "" : "Key Alias"} ${TEMPLATE_ID ? "" : "Template ID"
}`
);
}
Expand All @@ -19,7 +18,7 @@ const client = new SecretsManagerClient();
const command = new GetSecretValueCommand({ SecretId: process.env.NOTIFY_API_KEY });
console.log("Retrieving Notify API Key from Secrets Manager");
const notifyApiKey = await client.send(command);
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey);
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey.SecretString);

export const handler: Handler = async (event) => {
// setup the encryptionSDK's key ring
Expand Down
2 changes: 1 addition & 1 deletion aws/lambdas/code/nagware/lib/emailNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new SecretsManagerClient();
const command = new GetSecretValueCommand({ SecretId: process.env.NOTIFY_API_KEY });
console.log("Retrieving Notify API Key from Secrets Manager");
const notifyApiKey = await client.send(command);
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey);
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey.SecretString);

export async function notifyFormOwner(
formID: string,
Expand Down
17 changes: 3 additions & 14 deletions aws/lambdas/code/reliability/lib/notifyProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@ import convertMessage from "./markdown.js";
import { extractFileInputResponses, notifyProcessed } from "./dataLayer.js";
import { retrieveFilesFromReliabilityStorage } from "./s3FileInput.js";
import { FormSubmission } from "./types.js";
import { ClientRequest } from "http";
import { AxiosError } from "axios";
import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";

const client = new SecretsManagerClient();
const command = new GetSecretValueCommand({ SecretId: process.env.NOTIFY_API_KEY });
console.log("Retrieving Notify API Key from Secrets Manager");
const notifyApiKey = await client.send(command);
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey);

type NetworkError = {
request?: ClientRequest;
response?: {
data: {
errors?: unknown[];
};
status: string;
};
};
const notifyClient = new NotifyClient("https://api.notification.canada.ca", notifyApiKey.SecretString);

export default async (
submissionID: string,
Expand Down Expand Up @@ -61,8 +50,8 @@ export default async (
? formSubmission.deliveryOption.emailSubjectFr
: formSubmission.form.titleFr
: formSubmission.deliveryOption.emailSubjectEn
? formSubmission.deliveryOption.emailSubjectEn
: formSubmission.form.titleEn;
? formSubmission.deliveryOption.emailSubjectEn
: formSubmission.form.titleEn;

await notifyClient.sendEmail(templateID, formSubmission.deliveryOption.emailAddress, {
personalisation: {
Expand Down
Loading