From 545ee225aa31ef7a90600ee517e8e9a26436c2a6 Mon Sep 17 00:00:00 2001 From: m5r Date: Wed, 13 Oct 2021 21:42:23 +0200 Subject: [PATCH] extract s3 to integrations --- app/settings/api/queue/notify-email-change.ts | 4 ++-- app/settings/api/queue/subscription-created.ts | 2 +- app/settings/api/queue/subscription-updated.ts | 2 +- db/backup.ts | 14 ++------------ integrations/aws-s3.ts | 11 +++++++++++ integrations/{ses.ts => aws-ses.ts} | 0 6 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 integrations/aws-s3.ts rename integrations/{ses.ts => aws-ses.ts} (100%) diff --git a/app/settings/api/queue/notify-email-change.ts b/app/settings/api/queue/notify-email-change.ts index 18aa3f7..945dafc 100644 --- a/app/settings/api/queue/notify-email-change.ts +++ b/app/settings/api/queue/notify-email-change.ts @@ -1,7 +1,7 @@ import { Queue } from "quirrel/blitz"; -import appLogger from "../../../../integrations/logger"; -import { sendEmail } from "../../../../integrations/ses"; +import appLogger from "integrations/logger"; +import { sendEmail } from "integrations/aws-ses"; const logger = appLogger.child({ queue: "notify-email-change" }); diff --git a/app/settings/api/queue/subscription-created.ts b/app/settings/api/queue/subscription-created.ts index 535ae96..ac6447a 100644 --- a/app/settings/api/queue/subscription-created.ts +++ b/app/settings/api/queue/subscription-created.ts @@ -4,7 +4,7 @@ import type { PaddleSdkSubscriptionCreatedEvent } from "@devoxa/paddle-sdk"; import db, { MembershipRole } from "db"; import appLogger from "integrations/logger"; -import { sendEmail } from "integrations/ses"; +import { sendEmail } from "integrations/aws-ses"; import type { Metadata } from "integrations/paddle"; import { translateSubscriptionStatus } from "integrations/paddle"; diff --git a/app/settings/api/queue/subscription-updated.ts b/app/settings/api/queue/subscription-updated.ts index dfddaaf..2883fc6 100644 --- a/app/settings/api/queue/subscription-updated.ts +++ b/app/settings/api/queue/subscription-updated.ts @@ -4,7 +4,7 @@ import { PaddleSdkSubscriptionUpdatedEvent } from "@devoxa/paddle-sdk"; import db, { MembershipRole } from "db"; import appLogger from "integrations/logger"; -import { sendEmail } from "integrations/ses"; +import { sendEmail } from "integrations/aws-ses"; import type { Metadata } from "integrations/paddle"; import { translateSubscriptionStatus } from "integrations/paddle"; diff --git a/db/backup.ts b/db/backup.ts index f473831..4820d48 100644 --- a/db/backup.ts +++ b/db/backup.ts @@ -2,19 +2,9 @@ import url from "url"; import querystring from "querystring"; import { spawn } from "child_process"; import { PassThrough } from "stream"; -import { getConfig } from "blitz"; -import AWS from "aws-sdk"; -import { sendEmail } from "../integrations/ses"; -const { serverRuntimeConfig } = getConfig(); - -const s3 = new AWS.S3({ - credentials: new AWS.Credentials({ - accessKeyId: serverRuntimeConfig.awsS3.accessKeyId, - secretAccessKey: serverRuntimeConfig.awsS3.secretAccessKey, - }), - region: serverRuntimeConfig.awsS3.region, -}); +import { sendEmail } from "integrations/aws-ses"; +import { s3 } from "integrations/aws-s3"; export default async function backup(schedule: "daily" | "weekly" | "monthly") { const s3Bucket = `shellphone-${schedule}-backup`; diff --git a/integrations/aws-s3.ts b/integrations/aws-s3.ts new file mode 100644 index 0000000..15f8568 --- /dev/null +++ b/integrations/aws-s3.ts @@ -0,0 +1,11 @@ +import { Credentials, S3 } from "aws-sdk"; +import { getConfig } from "blitz"; + +const { serverRuntimeConfig } = getConfig(); + +const credentials = new Credentials({ + accessKeyId: serverRuntimeConfig.awsSes.accessKeyId, + secretAccessKey: serverRuntimeConfig.awsSes.secretAccessKey, +}); + +export const s3 = new S3({ region: serverRuntimeConfig.awsS3.region, credentials }); diff --git a/integrations/ses.ts b/integrations/aws-ses.ts similarity index 100% rename from integrations/ses.ts rename to integrations/aws-ses.ts