-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
936 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.0 | ||
4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Container+S3.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 19/04/2018. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
|
||
extension Container { | ||
|
||
public func makeS3Client() throws -> S3Client { | ||
return try make() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Region+Tools.swift | ||
// S3Signer | ||
// | ||
// Created by Ondrej Rafaj on 19/04/2018. | ||
// | ||
|
||
import Foundation | ||
@_exported import S3Signer | ||
|
||
|
||
extension Region { | ||
|
||
public func urlString(bucket: String) -> String { | ||
return host + bucket | ||
} | ||
|
||
public func url(bucket: String) -> URL? { | ||
return URL(string: urlString(bucket: bucket)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// S3+Private.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 19/04/2018. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
import HTTP | ||
|
||
|
||
extension S3 { | ||
|
||
func make(request url: URL, method: HTTPMethod, headers: HTTPHeaders, data: Data? = nil, on req: Request) throws -> Future<Response> { | ||
let client = try req.make(Client.self) | ||
let request = Request(using: req.privateContainer) | ||
request.http.method = method | ||
request.http.headers = headers | ||
if let data = data { | ||
request.http.body = HTTPBody(data: data) | ||
} | ||
request.http.url = url | ||
return try client.respond(to: request) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Service+S3.swift | ||
// S3Signer | ||
// | ||
// Created by Ondrej Rafaj on 19/04/2018. | ||
// | ||
|
||
import Foundation | ||
import Service | ||
@_exported import S3Signer | ||
|
||
|
||
extension Services { | ||
|
||
/// Convenience method to register both S3Signer and S3Client | ||
public mutating func register(s3 config: S3Signer.Config, defaultBucket: String) throws { | ||
try S3.init(defaultBucket: defaultBucket, config: config, services: &self) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// FileInfo.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 19/04/2018. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public protocol FileInfo { | ||
/// Override target bucket | ||
var bucket: String? { get } | ||
|
||
/// S3 file path | ||
var path: String { get } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// S3Signer.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 18/04/2018. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
|
||
public protocol S3Client: Service { | ||
func put(file: S3.File.Upload, headers: [String: String], on req: Request) throws -> EventLoopFuture<S3.File.Response> | ||
func put(file url: URL, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response> | ||
func put(file path: String, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response> | ||
func put(string: String, mime: MediaType, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response> | ||
func get(file: S3.File.Location, headers: [String: String], on req: Request) throws -> Future<S3.File.Response> | ||
func delete(file: S3.File.Location, headers: [String: String], on req: Request) throws -> Future<Void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// S3+Files.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 01/12/2016. | ||
// Copyright © 2016 manGoweb UK Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
|
||
// Helper S3 extension for uploading files by their URL/path | ||
public extension S3 { | ||
|
||
/// Upload file by it's URL to S3, full set | ||
public func put(file url: URL, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> { | ||
let data: Data = try Data(contentsOf: url) | ||
let file = File.Upload(data: data, bucket: bucket, destination: destination, access: access, mime: mimeType(forFileAtUrl: url)) | ||
return try put(file: file, on: req) | ||
} | ||
|
||
/// Upload file by it's path to S3, full set | ||
public func put(file path: String, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> { | ||
let url: URL = URL(fileURLWithPath: path) | ||
return try put(file: url, destination: destination, bucket: bucket, access: access, on: req) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// S3+Strings.swift | ||
// S3 | ||
// | ||
// Created by Ondrej Rafaj on 01/12/2016. | ||
// Copyright © 2016 manGoweb UK Ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
|
||
public extension S3 { | ||
|
||
/// Upload file content to S3, full set | ||
public func put(string: String, mime: MediaType = .plainText, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> { | ||
guard let data: Data = string.data(using: String.Encoding.utf8) else { | ||
throw Error.badStringData | ||
} | ||
let file = File.Upload(data: data, bucket: bucket, destination: destination, access: access, mime: mime) | ||
return try put(file: file, on: req) | ||
} | ||
|
||
} |
Oops, something went wrong.