Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
noppoMan committed Jul 4, 2017
0 parents commit 5b89106
Show file tree
Hide file tree
Showing 9 changed files with 7,405 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Yuki Takei(noppoMan)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Package.pins
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoPin": true,
"pins": [

],
"version": 1
}
10 changes: 10 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-tools-version:3.1

import PackageDescription

let package = Package(
name: "SwiftAWSS3",
dependencies: [
.Package(url: "https://github.com/noppoMan/aws-sdk-swift-core.git", majorVersion: 0, minor: 2)
]
)
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# s3

An AWS s3 type safe client for Swift (This is part of [aws-sdk-swift](https://github.com/noppoMan/aws-sdk-swift))

## Documentation

Visit the aws-sdk-swift [documentation](http://htmlpreview.github.io/?https://github.com/noppoMan/aws-sdk-swift-doc/blob/master/docs/index.html) for instructions and browsing api references.

## Installation

### Package.swift

```swift
import PackageDescription

let package = Package(
name: "MyAWSApp",
dependencies: [
.Package(url: "https://github.com/swift-aws/s3.git", majorVersion: 0, minor: 3)
]
)
```
49 changes: 49 additions & 0 deletions Sources/S3RequestMiddleware.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Foundation
import AWSSDKSwiftCore

struct S3RequestMiddleware: AWSRequestMiddleware {
func chain(request: AWSRequest) throws -> AWSRequest {
var request = request

var paths = request.url.path.components(separatedBy: "/").filter({ $0 != "" })
if paths.count == 0 {
return request
}

switch request.httpMethod.lowercased() {
case "get":
let query = request.url.query != nil ? "?\(request.url.query!)" : ""
let domain: String
if let host = request.url.host, host.contains("amazonaws.com") {
domain = "s3-\(request.region.rawValue).amazonaws.com"
} else {
let port = request.url.port == nil ? "" : ":\(request.url.port!)"
domain = request.url.host!+port
}
request.url = URL(string: "\(request.url.scheme ?? "https")://\(paths.removeFirst()).\(domain)/\(paths.joined(separator: "/"))\(query)")!
default:
break
}

switch request.operation {
case "CreateBucket":
var xml = ""
xml += "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
xml += "<LocationConstraint>"
xml += request.region.rawValue
xml += "</LocationConstraint>"
xml += "</CreateBucketConfiguration>"
request.body = .text(xml)

case "PutObject":
if let data = try request.body.asData() {
let encoded = Data(bytes: md5(data)).base64EncodedString()
request.addValue(encoded, forHTTPHeaderField: "Content-MD5")
}
default:
break
}

return request
}
}
424 changes: 424 additions & 0 deletions Sources/S3_API.swift

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions Sources/S3_Error.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
/**
The MIT License (MIT)

Copyright (c) 2017 Yuki Takei(noppoMan)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

import AWSSDKSwiftCore

/// Error enum for S3
public enum S3Error: AWSErrorType {
case noSuchUpload(message: String?)
case objectAlreadyInActiveTierError(message: String?)
case noSuchKey(message: String?)
case noSuchBucket(message: String?)
case bucketAlreadyExists(message: String?)
case bucketAlreadyOwnedByYou(message: String?)
case objectNotInActiveTierError(message: String?)
}

extension S3Error {
public init?(errorCode: String, message: String?){
var errorCode = errorCode
if let index = errorCode.index(of: "#") {
errorCode = errorCode.substring(from: errorCode.index(index, offsetBy: 1))
}
switch errorCode {
case "NoSuchUpload":
self = .noSuchUpload(message: message)
case "ObjectAlreadyInActiveTierError":
self = .objectAlreadyInActiveTierError(message: message)
case "NoSuchKey":
self = .noSuchKey(message: message)
case "NoSuchBucket":
self = .noSuchBucket(message: message)
case "BucketAlreadyExists":
self = .bucketAlreadyExists(message: message)
case "BucketAlreadyOwnedByYou":
self = .bucketAlreadyOwnedByYou(message: message)
case "ObjectNotInActiveTierError":
self = .objectNotInActiveTierError(message: message)
default:
return nil
}
}
}
Loading

0 comments on commit 5b89106

Please sign in to comment.