Skip to content

Commit 6857603

Browse files
brennanMKEroyjit
authored andcommitted
chore(storage): renames type to AWSS3SigningOperation and adds uploadPart case (#100)
1 parent 58f6e36 commit 6857603

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

AmplifyPlugins/Storage/AWSS3StoragePlugin/Dependency/AWSS3PreSignedURLBuilderAdapter.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
3232

3333
/// Gets pre-signed URL.
3434
/// - Returns: Pre-Signed URL
35-
func getPreSignedURL(key: String, method: AWSS3HttpMethod, expires: Int64? = nil) -> URL? {
35+
func getPreSignedURL(key: String, signingOperation: AWSS3SigningOperation, expires: Int64? = nil) -> URL? {
3636
let expiresDate = Date(timeIntervalSinceNow: Double(expires ?? defaultExpiration))
3737
let expiration = Int64(expiresDate.timeIntervalSinceNow)
3838
let preSignedUrl: URL?
39-
switch method {
40-
case .get:
39+
switch signingOperation {
40+
case .getObject:
4141
let input = GetObjectInput(bucket: bucket, key: key)
4242
preSignedUrl = input.presignURL(config: config, expiration: expiration)
43-
case .put:
43+
case .putObject:
4444
let input = PutObjectInput(bucket: bucket, key: key)
4545
preSignedUrl = input.presignURL(config: config, expiration: expiration)
46+
case .uploadPart(let partNumber, let uploadId):
47+
let input = UploadPartInput(bucket: bucket, key: key, partNumber: partNumber, uploadId: uploadId)
48+
preSignedUrl = input.presignURL(config: config, expiration: expiration)
4649
}
4750
return urlWithEscapedToken(preSignedUrl)
4851
}

AmplifyPlugins/Storage/AWSS3StoragePlugin/Dependency/AWSS3PreSignedURLBuilderBehavior.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import AWSS3
1212
import ClientRuntime
1313
import AWSClientRuntime
1414

15-
public enum AWSS3HttpMethod {
16-
case get
17-
case put
18-
}
1915

2016
enum AWSS3PreSignedURLBuilderError: Error {
2117
case failed(reason: String, error: Error?)
@@ -26,18 +22,18 @@ protocol AWSS3PreSignedURLBuilderBehavior {
2622

2723
/// Gets a pre-signed URL.
2824
/// - Returns: Pre-Signed URL
29-
func getPreSignedURL(key: String, method: AWSS3HttpMethod, expires: Int64?) -> URL?
25+
func getPreSignedURL(key: String, signingOperation: AWSS3SigningOperation, expires: Int64?) -> URL?
3026

3127
}
3228

3329
extension AWSS3PreSignedURLBuilderBehavior {
3430

35-
func getPreSignedURL(key: String, method: AWSS3HttpMethod) -> URL? {
36-
getPreSignedURL(key: key, method: method, expires: nil)
31+
func getPreSignedURL(key: String, signingOperation: AWSS3SigningOperation) -> URL? {
32+
getPreSignedURL(key: key, signingOperation: signingOperation, expires: nil)
3733
}
3834

3935
func getPreSignedURL(key: String) -> URL? {
40-
getPreSignedURL(key: key, method: .get, expires: nil)
36+
getPreSignedURL(key: key, signingOperation: .getObject, expires: nil)
4137
}
4238

4339
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import Foundation
9+
10+
public enum AWSS3SigningOperation {
11+
case getObject
12+
case putObject
13+
case uploadPart(partNumber: Int, uploadId: String)
14+
}

AmplifyPlugins/Storage/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService+GetPreSignedURLBehavior.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Amplify
1111
extension AWSS3StorageService {
1212

1313
func getPreSignedURL(serviceKey: String,
14-
method: AWSS3HttpMethod = .get,
14+
signingOperation: AWSS3SigningOperation = .getObject,
1515
expires: Int,
1616
onEvent: @escaping StorageServiceGetPreSignedURLEventHandler) {
1717
guard let preSignedURL = preSignedURLBuilder.getPreSignedURL(key: serviceKey) else {

AmplifyPlugins/Storage/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService+UploadBehavior.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension AWSS3StorageService {
3131

3232
let contentType = contentType ?? "application/octet-stream"
3333

34-
guard let preSignedURL = preSignedURLBuilder.getPreSignedURL(key: serviceKey, method: .put) else {
34+
guard let preSignedURL = preSignedURLBuilder.getPreSignedURL(key: serviceKey, signingOperation: .putObject) else {
3535
onEvent(.failed(StorageError.unknown("Failed to get pre-signed URL", nil)))
3636
return
3737
}

AmplifyPlugins/Storage/AWSS3StoragePlugin/Service/Storage/AWSS3StorageServiceBehaviour.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protocol AWSS3StorageServiceBehaviour {
4242
onEvent: @escaping StorageServiceDownloadEventHandler)
4343

4444
func getPreSignedURL(serviceKey: String,
45-
method: AWSS3HttpMethod,
45+
signingOperation: AWSS3SigningOperation,
4646
expires: Int,
4747
onEvent: @escaping StorageServiceGetPreSignedURLEventHandler)
4848

@@ -70,6 +70,6 @@ extension AWSS3StorageServiceBehaviour {
7070
func getPreSignedURL(serviceKey: String,
7171
expires: Int,
7272
onEvent: @escaping StorageServiceGetPreSignedURLEventHandler) {
73-
getPreSignedURL(serviceKey: serviceKey, method: .get, expires: expires, onEvent: onEvent)
73+
getPreSignedURL(serviceKey: serviceKey, signingOperation: .getObject, expires: expires, onEvent: onEvent)
7474
}
7575
}

AmplifyPlugins/Storage/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadClient.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
8686
func uploadPart(partNumber: PartNumber, multipartUpload: StorageMultipartUpload, subTask: StorageTransferTask) throws {
8787
guard let serviceProxy = serviceProxy else { fatalError("Service Proxy is required") }
8888

89-
guard let uploadFile = multipartUpload.uploadFile,
89+
guard let uploadId = multipartUpload.uploadId,
90+
let uploadFile = multipartUpload.uploadFile,
9091
let partSize = multipartUpload.partSize,
9192
let part = multipartUpload.part(for: partNumber) else {
9293
fatalError("Part number is required")
@@ -121,7 +122,8 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
121122
do {
122123
let partialFileURL = try result.get()
123124

124-
guard let preSignedURL = serviceProxy.preSignedURLBuilder.getPreSignedURL(key: self.key, method: .put) else {
125+
let operation = AWSS3SigningOperation.uploadPart(partNumber: partNumber, uploadId: uploadId)
126+
guard let preSignedURL = serviceProxy.preSignedURLBuilder.getPreSignedURL(key: self.key, signingOperation: operation) else {
125127
self.session?.fail(error: StorageError.unknown("Failed to get pre-signed URL", nil))
126128
return
127129
}

AmplifyPlugins/Storage/AWSS3StoragePluginTests/Mocks/MockAWSS3StorageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class MockAWSS3StorageService: AWSS3StorageServiceBehaviour {
8080
}
8181

8282
public func getPreSignedURL(serviceKey: String,
83-
method: AWSS3HttpMethod = .get,
83+
signingOperation: AWSS3SigningOperation = .getObject,
8484
expires: Int,
8585
onEvent: @escaping StorageServiceGetPreSignedURLEventHandler) {
8686
getPreSignedURLCalled += 1

0 commit comments

Comments
 (0)