Skip to content

Commit

Permalink
Fix destination URL & add support for custom region in config
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpavlik authored Dec 23, 2016
1 parent ffb5e75 commit 8ca5c03
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/S3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ public class S3 {
throw Error.missingCredentials("secretKey")
}

self.init(accessKey: accessKey, secretKey: secretKey)
if let regionString: String = drop.config["s3", "region"]?.string {
guard let region = Region(rawValue: regionString) else {
throw Error.missingCredentials("region")
}
self.init(accessKey: accessKey, secretKey: secretKey, region: region)
} else {
self.init(accessKey: accessKey, secretKey: secretKey)
}

if let bucket: String = drop.config["s3", "bucket"]?.string {
self.bucketName = bucket
Expand Down Expand Up @@ -273,8 +280,7 @@ internal extension S3 {
throw Error.missingBucketName
}

var url: URL = URL(string: "https://s3.amazonaws.com")!
url.appendPathComponent(bucket!)
var url: URL = URL(string: "https://\(bucket!).s3.amazonaws.com")!
url.appendPathComponent(fileName)
return url
}
Expand Down

0 comments on commit 8ca5c03

Please sign in to comment.