From 1a1a89c8ec75960b116687a04abd7742717163f3 Mon Sep 17 00:00:00 2001 From: Robert Edwards Date: Thu, 25 May 2017 15:29:37 -0400 Subject: [PATCH 1/3] Update for Vapor 2.0 --- Package.pins | 114 +++++++++++++++++++++++++++++++++++++++++++++++ Package.swift | 9 ++-- Sources/S3.swift | 26 ++++++----- 3 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 Package.pins diff --git a/Package.pins b/Package.pins new file mode 100644 index 0000000..858b3c6 --- /dev/null +++ b/Package.pins @@ -0,0 +1,114 @@ +{ + "autoPin": true, + "pins": [ + { + "package": "BCrypt", + "reason": null, + "repositoryURL": "https://github.com/vapor/bcrypt.git", + "version": "1.0.0" + }, + { + "package": "Bits", + "reason": null, + "repositoryURL": "https://github.com/vapor/bits.git", + "version": "1.0.0" + }, + { + "package": "CTLS", + "reason": null, + "repositoryURL": "https://github.com/vapor/ctls.git", + "version": "1.0.0" + }, + { + "package": "Console", + "reason": null, + "repositoryURL": "https://github.com/vapor/console.git", + "version": "2.1.0" + }, + { + "package": "Core", + "reason": null, + "repositoryURL": "https://github.com/vapor/core.git", + "version": "2.0.2" + }, + { + "package": "Crypto", + "reason": null, + "repositoryURL": "https://github.com/vapor/crypto.git", + "version": "2.0.0" + }, + { + "package": "Debugging", + "reason": null, + "repositoryURL": "https://github.com/vapor/debugging.git", + "version": "1.0.0" + }, + { + "package": "Engine", + "reason": null, + "repositoryURL": "https://github.com/vapor/engine.git", + "version": "2.0.0" + }, + { + "package": "JSON", + "reason": null, + "repositoryURL": "https://github.com/vapor/json.git", + "version": "2.0.2" + }, + { + "package": "MimeLib", + "reason": null, + "repositoryURL": "https://github.com/manGoweb/MimeLib.git", + "version": "1.0.0" + }, + { + "package": "Multipart", + "reason": null, + "repositoryURL": "https://github.com/vapor/multipart.git", + "version": "2.0.0" + }, + { + "package": "Node", + "reason": null, + "repositoryURL": "https://github.com/vapor/node.git", + "version": "2.0.1" + }, + { + "package": "Random", + "reason": null, + "repositoryURL": "https://github.com/vapor/random.git", + "version": "1.0.0" + }, + { + "package": "Routing", + "reason": null, + "repositoryURL": "https://github.com/vapor/routing.git", + "version": "2.0.0" + }, + { + "package": "S3SignerAWS", + "reason": null, + "repositoryURL": "https://github.com/JustinM1/S3SignerAWS.git", + "version": "2.0.1" + }, + { + "package": "Sockets", + "reason": null, + "repositoryURL": "https://github.com/vapor/sockets.git", + "version": "2.0.1" + }, + { + "package": "TLS", + "reason": null, + "repositoryURL": "https://github.com/vapor/tls.git", + "version": "2.0.0" + }, + { + "package": "Vapor", + "reason": null, + "repositoryURL": "https://github.com/vapor/vapor.git", + "version": "2.0.2" + } + ], + "version": 1 +} \ No newline at end of file diff --git a/Package.swift b/Package.swift index 1839ac2..78a9e41 100644 --- a/Package.swift +++ b/Package.swift @@ -11,12 +11,9 @@ import PackageDescription let package = Package( name: "S3", dependencies: [ - .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1), - .Package(url: "https://github.com/JustinM1/S3SignerAWS.git", majorVersion: 1, minor: 1), + .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2), + .Package(url: "https://github.com/JustinM1/S3SignerAWS.git", majorVersion: 2), .Package(url: "https://github.com/manGoweb/MimeLib.git", majorVersion: 1) ], - exclude: [ - - ] + exclude: [] ) - diff --git a/Sources/S3.swift b/Sources/S3.swift index 9948a41..4b4a5b5 100644 --- a/Sources/S3.swift +++ b/Sources/S3.swift @@ -57,6 +57,8 @@ public class S3 { S3 Signer class (https://github.com/JustinM1/S3SignerAWS) */ let signer: S3SignerAWS + + let client: ClientFactoryProtocol // MARK: Initialization @@ -81,9 +83,9 @@ public class S3 { guard let region = Region(rawValue: regionString) else { throw Error.missingCredentials("region") } - self.init(accessKey: accessKey, secretKey: secretKey, region: region) + self.init(droplet: drop, accessKey: accessKey, secretKey: secretKey, region: region) } else { - self.init(accessKey: accessKey, secretKey: secretKey) + self.init(droplet: drop, accessKey: accessKey, secretKey: secretKey) } if let bucket: String = drop.config["s3", "bucket"]?.string { @@ -103,7 +105,8 @@ public class S3 { - bucketName: Name of the global bucket to be used for calls where bucket is not specified (optional) - region: AWS Region, default is .usEast1_Virginia */ - public init(accessKey: String, secretKey: String, bucketName: String?, region: Region = .usEast1_Virginia) { + public init(droplet drop: Droplet, accessKey: String, secretKey: String, bucketName: String?, region: Region = .usEast1_Virginia) { + self.client = drop.client self.bucketName = bucketName self.signer = S3SignerAWS(accessKey: accessKey, secretKey: secretKey, region: region) } @@ -116,8 +119,8 @@ public class S3 { - secretKey: AWS Secret key - region: AWS Region, default is .usEast1_Virginia */ - public convenience init(accessKey: String, secretKey: String, region: Region = .usEast1_Virginia) { - self.init(accessKey: accessKey, secretKey: secretKey, bucketName: nil, region: region) + public convenience init(droplet drop: Droplet, accessKey: String, secretKey: String, region: Region = .usEast1_Virginia) { + self.init(droplet: drop, accessKey: accessKey, secretKey: secretKey, bucketName: nil, region: region) } // MARK: Managing objects @@ -138,12 +141,13 @@ public class S3 { throw Error.invalidUrl } - let bytes: Bytes = try data.makeBytes() + let bytes = data.makeBytes() var awsHeaders: [String: String] = headers awsHeaders["x-amz-acl"] = accessControl.rawValue let signingHeaders: [String: String] = try signer.authHeaderV4(httpMethod: .put, urlString: url.absoluteString, headers: awsHeaders, payload: .bytes(bytes)) - let result: Response = try BasicClient.put(fileUrl!.absoluteString, headers: self.vaporHeaders(signingHeaders), query: [:], body: Body(bytes)) - + + let result = try client.put(url.absoluteString, query: [:], vaporHeaders(signingHeaders), Body(bytes), through: []) + guard result.status == .ok else { throw Error.badResponse(result) } @@ -208,7 +212,7 @@ public class S3 { } let headers: [String: String] = try signer.authHeaderV4(httpMethod: .get, urlString: url.absoluteString, headers: [:], payload: .none) - let result: Response = try BasicClient.get(fileUrl!.absoluteString, headers: self.vaporHeaders(headers)) + let result: Response = try client.get(url.absoluteString, query: [:], vaporHeaders(headers)) if result.status == .notFound { throw Error.notFound @@ -217,7 +221,7 @@ public class S3 { guard result.status == .ok else { throw Error.badResponse(result) } - + guard let bytes: Bytes = result.body.bytes else { throw Error.missingData } @@ -242,7 +246,7 @@ public class S3 { let headers: [String: String] = try signer.authHeaderV4(httpMethod: .delete, urlString: url.absoluteString, headers: [:], payload: .none) - let result: Response = try BasicClient.delete(fileUrl!.absoluteString, headers: self.vaporHeaders(headers), query: [:], body: Body("")) + let result = try client.delete(url.absoluteString, query: [:], vaporHeaders(headers), Body("")) guard result.status == .noContent || result.status == .ok else { throw Error.badResponse(result) From f6626c7df3c8e5d34b2c3e9b91edc9fd618b2a3f Mon Sep 17 00:00:00 2001 From: Robert Edwards Date: Thu, 25 May 2017 15:30:07 -0400 Subject: [PATCH 2/3] Add Xcode project to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8c160d2..1ac53db 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output .DS_Store +S3.xcodeproj From 76f9a257b80fce33dcebeec8ee003c33f4238940 Mon Sep 17 00:00:00 2001 From: Robert Edwards Date: Thu, 25 May 2017 15:33:28 -0400 Subject: [PATCH 3/3] Update version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd80bbb..4daffbe 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Basic S3 access library for Vapor written in Swift 1) Add following package to your ```Package.swift```: ``` Swift -.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 1) +.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 2) ``` 2) Run ```vapor clean```