Skip to content

Commit

Permalink
fix(storage): add metadata support to multipart upload
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Oct 13, 2023
1 parent c7d0435 commit 6a23710
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
let contentType: String?
let requestHeaders: RequestHeaders?
weak var session: StorageMultipartUploadSession?

let metadata: [String: String]?

init(serviceProxy: StorageServiceProxy,
fileSystem: FileSystem = .default,
bucket: String,
key: String,
uploadFile: UploadFile,
contentType: String? = nil,
requestHeaders: RequestHeaders? = nil) {
requestHeaders: RequestHeaders? = nil,
metadata: [String: String]? = nil
) {
self.serviceProxy = serviceProxy
self.fileSystem = fileSystem
self.bucket = bucket
self.key = key
self.uploadFile = uploadFile
self.contentType = contentType
self.requestHeaders = requestHeaders
self.metadata = metadata
}

func integrate(session: StorageMultipartUploadSession) {
Expand Down Expand Up @@ -135,7 +139,7 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
let preSignedURL = try await serviceProxy.preSignedURLBuilder.getPreSignedURL(
key: self.key,
signingOperation: operation,
metadata: nil,
metadata: self.metadata,
accelerate: nil,
expires: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ extension MockAWSS3PreSignedURLBuilder: AWSS3PreSignedURLBuilderBehavior {
metadata: [String : String]?,
accelerate: Bool?,
expires: Int64?) async throws -> URL {
if let metadata = metadata {
interactions.append("\(#function) \(key) \(signingOperation) \(metadata) \(String(describing: expires))")
} else {
interactions.append("\(#function) \(key) \(signingOperation) \(String(describing: expires))")
}

interactions.append("\(#function) \(key) \(signingOperation) \(String(describing: metadata)) \(String(describing: expires))")
return try await getPreSignedURLHandler(key, signingOperation, expires)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.getObject) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.getObject) nil \(String(describing: expires))"
])
}

Expand All @@ -88,23 +88,23 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.putObject) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.putObject) nil \(String(describing: expires))"
])
}

/// - Given: A storage service configured to use a AWSS3PreSignedURLBuilder
/// - When: A presigned URL is requested for a **AWSS3SigningOperation.putObject** operation with metadata
/// - Then: A valid URL is returned
func testForPutObjectWithMetadata() async throws {
let metadata = ["test": "value"]
let metadata: [String: String]? = ["test": "value"]
let url = try await systemUnderTest.getPreSignedURL(serviceKey: serviceKey,
signingOperation: .putObject,
metadata: metadata,
accelerate: nil,
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.putObject) \(metadata) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.putObject) \(String(describing: metadata)) \(String(describing: expires))"
])
}

Expand All @@ -120,7 +120,7 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(operation) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(operation) nil \(String(describing: expires))"
])
}

Expand Down

0 comments on commit 6a23710

Please sign in to comment.