aboutsummaryrefslogtreecommitdiff
path: root/services/docker/mail-server/relay/aws/context.ts
diff options
context:
space:
mode:
Diffstat (limited to 'services/docker/mail-server/relay/aws/context.ts')
-rw-r--r--services/docker/mail-server/relay/aws/context.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/services/docker/mail-server/relay/aws/context.ts b/services/docker/mail-server/relay/aws/context.ts
new file mode 100644
index 0000000..c4f67bc
--- /dev/null
+++ b/services/docker/mail-server/relay/aws/context.ts
@@ -0,0 +1,41 @@
+import {
+ CopyObjectCommand,
+ DeleteObjectCommand,
+ S3Client,
+} from "@aws-sdk/client-s3";
+import { FetchHttpHandler } from "@smithy/fetch-http-handler";
+
+import { getConfigValue } from "../config.ts";
+
+export class AwsContext {
+ readonly credentials = () =>
+ Promise.resolve({
+ accessKeyId: getConfigValue("awsAccessKeyId"),
+ secretAccessKey: getConfigValue("awsSecretAccessKey"),
+ });
+ readonly requestHandler = new FetchHttpHandler();
+
+ get region() {
+ return getConfigValue("awsRegion");
+ }
+}
+
+export async function s3MoveObject(
+ client: S3Client,
+ bucket: string,
+ path: string,
+ newPath: string,
+): Promise<void> {
+ const copyCommand = new CopyObjectCommand({
+ Bucket: bucket,
+ Key: newPath,
+ CopySource: `${bucket}/${path}`,
+ });
+ await client.send(copyCommand);
+
+ const deleteCommand = new DeleteObjectCommand({
+ Bucket: bucket,
+ Key: path,
+ });
+ await client.send(deleteCommand);
+}