Skip to content

Commit

Permalink
Merge pull request #1 from petrpavlik/master
Browse files Browse the repository at this point in the history
Add support for custom regions
  • Loading branch information
rafiki270 authored Feb 2, 2017
2 parents ffb5e75 + 8ca5c03 commit a0845f5
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 a0845f5

Please sign in to comment.