From 43133f40c7aedeb55add9dbe52dd70a12bc7402b Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Mon, 26 Feb 2024 11:25:35 +0800 Subject: [PATCH] remove unused code (#372) --- serverless/aws/src/aws_region.test.ts | 52 --------------------------- serverless/aws/src/aws_region.ts | 48 ------------------------- 2 files changed, 100 deletions(-) delete mode 100644 serverless/aws/src/aws_region.test.ts delete mode 100644 serverless/aws/src/aws_region.ts diff --git a/serverless/aws/src/aws_region.test.ts b/serverless/aws/src/aws_region.test.ts deleted file mode 100644 index c917b82..0000000 --- a/serverless/aws/src/aws_region.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -import assert from "node:assert"; -import { test } from "node:test"; - -import { getRegion } from "./aws_region"; - -test("one bucket", () => { - const result = getRegion( - "us-west-1", - { bucket: "mybucket", region: "us-west-1" }, - [] - ); - assert.deepEqual(result, { bucket: "mybucket", region: "us-west-1" }); -}); - -test("unknown region", () => { - const result = getRegion( - "us-nullisland-1", - { bucket: "mybucket", region: "us-west-1" }, - [] - ); - assert.deepEqual(result, { bucket: "mybucket", region: "us-west-1" }); -}); - -test("exact region match", () => { - let result = getRegion( - "us-west-1", - { bucket: "mybucket", region: "us-west-1" }, - [{ bucket: "mybucket-ap-south-1", region: "ap-south-1" }] - ); - assert.deepEqual(result, { bucket: "mybucket", region: "us-west-1" }); - result = getRegion( - "ap-south-1", - { bucket: "mybucket", region: "us-west-1" }, - [{ bucket: "mybucket-ap-south-1", region: "ap-south-1" }] - ); - assert.deepEqual(result, { - bucket: "mybucket-ap-south-1", - region: "ap-south-1", - }); -}); - -test("priority match", () => { - const result = getRegion( - "us-west-1", - { bucket: "mybucket", region: "ap-south-1" }, - [{ bucket: "mybucket-us-west-2", region: "us-west-2" }] - ); - assert.deepEqual(result, { - bucket: "mybucket-us-west-2", - region: "us-west-2", - }); -}); diff --git a/serverless/aws/src/aws_region.ts b/serverless/aws/src/aws_region.ts deleted file mode 100644 index 85f6225..0000000 --- a/serverless/aws/src/aws_region.ts +++ /dev/null @@ -1,48 +0,0 @@ -interface Bucket { - bucket: string; - region: string; -} - -const REGION_MATRIX: Record = { - "us-east-2": ["us-east-1"], // ohio - "us-east-1": ["us-east-2"], // virginia - "us-west-2": ["us-west-1"], // oregon - "us-west-1": ["us-west-2"], // california - "ap-south-1": ["ap-southeast-1"], // mumbai - "ap-southeast-1": ["ap-southeast-2", "ap-northeast-1", "ap-northeast-2"], // singapore - "ap-southeast-2": ["ap-southeast-1"], // sydney - "ap-northeast-2": ["ap-northeast-1", "ap-southeast-1"], // seoul - "ap-northeast-1": ["ap-northeast-2", "ap-southeast-1"], // tokyo - "eu-central-1": ["eu-west-1", "eu-west-2"], // frankfurt - "eu-west-1": ["eu-west-2", "eu-central-1"], // dublin - "eu-west-2": ["eu-west-1", "eu-central-1"], // london - "sa-east-1": ["us-east-1", "us-east-2"], // sao paulo -}; - -export const getRegion = ( - execRegion: string, - primary: Bucket, - replicas: Bucket[] -): Bucket => { - if (primary.region === execRegion) { - return primary; - } - - for (const replica of replicas) { - if (replica.region === execRegion) { - return replica; - } - } - - if (execRegion in REGION_MATRIX) { - for (const region of REGION_MATRIX[execRegion]) { - for (const replica of replicas) { - if (replica.region === region) { - return replica; - } - } - } - } - - return primary; -};