From 6891ae8ca2343c7060065a9173ab079f11faee8e Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Thu, 3 Jan 2019 22:01:08 +0100 Subject: [PATCH 1/6] Add eu-west-2 and eu-west-3 missing regions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Those Europe regions were missing, and I needed them 🙂 --- Sources/Storage/Utilities/S3.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index b289cc2..a5f0dd2 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -9,6 +9,8 @@ public enum Region: String { case usWest1 = "us-west-1" case usWest2 = "us-west-2" case euWest1 = "eu-west-1" + case euWest2 = "eu-west-2" + case euWest3 = "eu-west-3" case euCentral1 = "eu-central-1" case apSouth1 = "ap-south-1" case apSoutheast1 = "ap-southeast-1" @@ -24,6 +26,8 @@ public enum Region: String { case .usWest1: return "s3-us-west-1.amazonaws.com" case .usWest2: return "s3-us-west-2.amazonaws.com" case .euWest1: return "s3-eu-west-1.amazonaws.com" + case .euWest2: return "s3-eu-west-2.amazonaws.com" + case .euWest3: return "s3-eu-west-3.amazonaws.com" case .euCentral1: return "s3.eu-central-1.amazonaws.com" case .apSouth1: return "s3.ap-south-1.amazonaws.com" case .apSoutheast1: return "s3-ap-southeast-1.amazonaws.com" From ab3689abf57f10c18fa01b095a74af20965ee489 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Thu, 3 Jan 2019 22:13:13 +0100 Subject: [PATCH 2/6] Expand the region possibilities by adding a custom one --- Sources/Storage/Utilities/S3.swift | 54 +++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index a5f0dd2..5276eb3 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -3,21 +3,22 @@ import Vapor import Crypto import Foundation -public enum Region: String { - case usEast1 = "us-east-1" - case usEast2 = "us-east-2" - case usWest1 = "us-west-1" - case usWest2 = "us-west-2" - case euWest1 = "eu-west-1" - case euWest2 = "eu-west-2" - case euWest3 = "eu-west-3" - case euCentral1 = "eu-central-1" - case apSouth1 = "ap-south-1" - case apSoutheast1 = "ap-southeast-1" - case apSoutheast2 = "ap-southeast-2" - case apNortheast1 = "ap-northeast-1" - case apNortheast2 = "ap-northeast-2" - case saEast1 = "sa-east-1" +public enum Region { + case usEast1 + case usEast2 + case usWest1 + case usWest2 + case euWest1 + case euWest2 + case euWest3 + case euCentral1 + case apSouth1 + case apSoutheast1 + case apSoutheast2 + case apNortheast1 + case apNortheast2 + case saEast1 + case custom(code: String) public var host: String { switch self { @@ -35,8 +36,29 @@ public enum Region: String { case .apNortheast1: return "s3-ap-northeast-1.amazonaws.com" case .apNortheast2: return "s3.ap-northeast-2.amazonaws.com" case .saEast1: return "s3-sa-east-1.amazonaws.com" + case .custom(let code): return "s3-\(code).amazonaws.com" } } + + var code: String { + switch self { + case .usEast1: return "us-east-1" + case .usEast2: return "us-east-2" + case .usWest1: return "us-west-1" + case .usWest2: return "us-west-2" + case .euWest1: return "eu-west-1" + case .euWest2: return "eu-west-2" + case .euWest3: return "eu-west-3" + case .euCentral1: return "eu-central-1" + case .apSouth1: return "ap-south-1" + case .apSoutheast1: return "ap-southeast-1" + case .apSoutheast2: return "ap-southeast-2" + case .apNortheast1: return "ap-northeast-1" + case .apNortheast2: return "ap-northeast-2" + case .saEast1: return "sa-east-1" + case .custom(let code): return code + } + } } public enum Payload { @@ -126,7 +148,7 @@ public struct AWSSignatureV4 { ) { self.service = service self.host = host - self.region = region.rawValue + self.region = region.code self.accessKey = accessKey self.secretKey = secretKey } From 87edbb459db02cee5e44269b938fc1b4c13156c3 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Thu, 3 Jan 2019 23:40:16 +0100 Subject: [PATCH 3/6] Fix indentation --- Sources/Storage/Utilities/S3.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index 5276eb3..4048023 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -57,8 +57,8 @@ public enum Region { case .apNortheast2: return "ap-northeast-2" case .saEast1: return "sa-east-1" case .custom(let code): return code + } } - } } public enum Payload { From 6b3472eb81da26e40a0bc3dba2064f0f6c07b928 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Thu, 3 Jan 2019 23:49:10 +0100 Subject: [PATCH 4/6] Muting codebeat info issues --- Sources/Storage/Utilities/S3.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index 4048023..34a11b3 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -40,6 +40,7 @@ public enum Region { } } + // codebeat:disable[CYCLO,ABC] var code: String { switch self { case .usEast1: return "us-east-1" @@ -59,6 +60,7 @@ public enum Region { case .custom(let code): return code } } + // codebeat:enable[CYCLO,ABC] } public enum Payload { From 9be1c23c31ed04dc30a5009c9092c10f95510717 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Fri, 8 Mar 2019 23:51:22 +0100 Subject: [PATCH 5/6] Refact Region using the struct approach --- Sources/Storage/Utilities/S3.swift | 79 ++++++++---------------------- 1 file changed, 21 insertions(+), 58 deletions(-) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index 34a11b3..4cbe78b 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -3,64 +3,27 @@ import Vapor import Crypto import Foundation -public enum Region { - case usEast1 - case usEast2 - case usWest1 - case usWest2 - case euWest1 - case euWest2 - case euWest3 - case euCentral1 - case apSouth1 - case apSoutheast1 - case apSoutheast2 - case apNortheast1 - case apNortheast2 - case saEast1 - case custom(code: String) - - public var host: String { - switch self { - case .usEast1: return "s3.amazonaws.com" - case .usEast2: return "s3.us-east-2.amazonaws.com" - case .usWest1: return "s3-us-west-1.amazonaws.com" - case .usWest2: return "s3-us-west-2.amazonaws.com" - case .euWest1: return "s3-eu-west-1.amazonaws.com" - case .euWest2: return "s3-eu-west-2.amazonaws.com" - case .euWest3: return "s3-eu-west-3.amazonaws.com" - case .euCentral1: return "s3.eu-central-1.amazonaws.com" - case .apSouth1: return "s3.ap-south-1.amazonaws.com" - case .apSoutheast1: return "s3-ap-southeast-1.amazonaws.com" - case .apSoutheast2: return "s3-ap-southeast-2.amazonaws.com" - case .apNortheast1: return "s3-ap-northeast-1.amazonaws.com" - case .apNortheast2: return "s3.ap-northeast-2.amazonaws.com" - case .saEast1: return "s3-sa-east-1.amazonaws.com" - case .custom(let code): return "s3-\(code).amazonaws.com" - } - } - - // codebeat:disable[CYCLO,ABC] - var code: String { - switch self { - case .usEast1: return "us-east-1" - case .usEast2: return "us-east-2" - case .usWest1: return "us-west-1" - case .usWest2: return "us-west-2" - case .euWest1: return "eu-west-1" - case .euWest2: return "eu-west-2" - case .euWest3: return "eu-west-3" - case .euCentral1: return "eu-central-1" - case .apSouth1: return "ap-south-1" - case .apSoutheast1: return "ap-southeast-1" - case .apSoutheast2: return "ap-southeast-2" - case .apNortheast1: return "ap-northeast-1" - case .apNortheast2: return "ap-northeast-2" - case .saEast1: return "sa-east-1" - case .custom(let code): return code - } - } - // codebeat:enable[CYCLO,ABC] +public struct Region { + let code: String + + public static var usEast1: Region = .init(code: "us-east-1") + public static var usEast2: Region = .init(code: "us-east-2") + public static var usWest1: Region = .init(code: "us-west-1") + public static var usWest2: Region = .init(code: "us-west-2") + public static var euWest1: Region = .init(code: "eu-west-1") + public static var euWest2: Region = .init(code: "eu-west-2") + public static var euWest3: Region = .init(code: "eu-west-3") + public static var euCentral1: Region = .init(code: "eu-central-1") + public static var apSouth1: Region = .init(code: "ap-south-1") + public static var apSoutheast1: Region = .init(code: "ap-southeast-1") + public static var apSoutheast2: Region = .init(code: "ap-southeast-2") + public static var apNortheast1: Region = .init(code: "ap-northeast-1") + public static var apNortheast2: Region = .init(code: "ap-northeast-2") + public static var saEast1: Region = .init(code: "sa-east-1") + + public var host: String { + return "s3-\(code).amazonaws.com" + } } public enum Payload { From 329bc6bf42ee15e26d5a89216fba3aafbae01724 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Mon, 11 Mar 2019 09:25:18 +0100 Subject: [PATCH 6/6] Permit custom region initialization --- Sources/Storage/Utilities/S3.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Storage/Utilities/S3.swift b/Sources/Storage/Utilities/S3.swift index 4cbe78b..5474e49 100644 --- a/Sources/Storage/Utilities/S3.swift +++ b/Sources/Storage/Utilities/S3.swift @@ -21,6 +21,10 @@ public struct Region { public static var apNortheast2: Region = .init(code: "ap-northeast-2") public static var saEast1: Region = .init(code: "sa-east-1") + public init(code: String) { + self.code = code + } + public var host: String { return "s3-\(code).amazonaws.com" }