Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage): add metadata support to uploads #3295

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extension AWSS3StoragePlugin {
let result = try await storageService.getPreSignedURL(
serviceKey: serviceKey,
signingOperation: .getObject,
metadata: nil,
accelerate: accelerate,
expires: options.expires)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
/// - Returns: Pre-Signed URL
func getPreSignedURL(key: String,
signingOperation: AWSS3SigningOperation,
metadata: [String: String]? = nil,
accelerate: Bool? = nil,
expires: Int64? = nil) async throws -> URL {
let expiresDate = Date(timeIntervalSinceNow: Double(expires ?? defaultExpiration))
Expand All @@ -47,7 +48,7 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
config: config,
expiration: expiration)
case .putObject:
let input = PutObjectInput(bucket: bucket, key: key)
let input = PutObjectInput(bucket: bucket, key: key, metadata: metadata)
preSignedUrl = try await input.presignURL(
config: config,
expiration: expiration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protocol AWSS3PreSignedURLBuilderBehavior {
/// - Tag: AWSS3PreSignedURLBuilderBehavior.getPreSignedURL
func getPreSignedURL(key: String,
signingOperation: AWSS3SigningOperation,
metadata: [String: String]?,
accelerate: Bool?,
expires: Int64?) async throws -> URL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension AWSS3StorageService {
do {
let preSignedURL = try await preSignedURLBuilder.getPreSignedURL(key: serviceKey,
signingOperation: .getObject,
metadata: nil,
accelerate: accelerate,
expires: nil)
startDownload(preSignedURL: preSignedURL, transferTask: transferTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ extension AWSS3StorageService {

func getPreSignedURL(serviceKey: String,
signingOperation: AWSS3SigningOperation,
metadata: [String: String]?,
accelerate: Bool?,
expires: Int) async throws -> URL {
return try await preSignedURLBuilder.getPreSignedURL(
key: serviceKey,
signingOperation: signingOperation,
metadata: metadata,
accelerate: nil,
expires: Int64(expires)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ extension AWSS3StorageService {
let client = DefaultStorageMultipartUploadClient(serviceProxy: self,
bucket: bucket,
key: serviceKey,
uploadFile: uploadFile)
uploadFile: uploadFile,
metadata: metadata)
let multipartUploadSession = StorageMultipartUploadSession(client: client,
bucket: bucket,
key: serviceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extension AWSS3StorageService {
do {
let preSignedURL = try await preSignedURLBuilder.getPreSignedURL(key: serviceKey,
signingOperation: .putObject,
metadata: metadata,
accelerate: accelerate,
expires: nil)
startUpload(preSignedURL: preSignedURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protocol AWSS3StorageServiceBehavior {

func getPreSignedURL(serviceKey: String,
signingOperation: AWSS3SigningOperation,
metadata: [String: String]?,
accelerate: Bool?,
expires: Int) async throws -> URL

Expand Down
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,6 +139,7 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
let preSignedURL = try await serviceProxy.preSignedURLBuilder.getPreSignedURL(
key: self.key,
signingOperation: operation,
metadata: self.metadata,
accelerate: nil,
expires: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class AWSS3StoragePluginGetPresignedUrlTests: XCTestCase {
])
let expectedServiceKey = "public/" + testKey
XCTAssertEqual(storageService.interactions, [
"getPreSignedURL(serviceKey:signingOperation:accelerate:expires:) \(expectedServiceKey) getObject 18000"
"getPreSignedURL(serviceKey:signingOperation:metadata:accelerate:expires:) \(expectedServiceKey) getObject nil 18000"
])
}

Expand Down Expand Up @@ -120,7 +120,7 @@ final class AWSS3StoragePluginGetPresignedUrlTests: XCTestCase {

let expectedServiceKey = StorageAccessLevel.protected.rawValue + "/" + testIdentityId + "/" + testKey
XCTAssertEqual(storageService.interactions, [
"getPreSignedURL(serviceKey:signingOperation:accelerate:expires:) \(expectedServiceKey) getObject \(expectedExpires)"
"getPreSignedURL(serviceKey:signingOperation:metadata:accelerate:expires:) \(expectedServiceKey) getObject nil \(expectedExpires)"
])
}

Expand Down Expand Up @@ -152,7 +152,7 @@ final class AWSS3StoragePluginGetPresignedUrlTests: XCTestCase {

let expectedServiceKey = StorageAccessLevel.protected.rawValue + "/" + testIdentityId + "/" + testKey
XCTAssertEqual(storageService.interactions, [
"getPreSignedURL(serviceKey:signingOperation:accelerate:expires:) \(expectedServiceKey) getObject \(expectedExpires)"
"getPreSignedURL(serviceKey:signingOperation:metadata:accelerate:expires:) \(expectedServiceKey) getObject nil \(expectedExpires)"
])
}

Expand All @@ -173,7 +173,7 @@ final class AWSS3StoragePluginGetPresignedUrlTests: XCTestCase {
let expectedExpires = 18000
let expectedServiceKey = StorageAccessLevel.protected.rawValue + "/" + testIdentityId + "/" + testKey
XCTAssertEqual(storageService.interactions, [
"getPreSignedURL(serviceKey:signingOperation:accelerate:expires:) \(expectedServiceKey) getObject \(expectedExpires)"
"getPreSignedURL(serviceKey:signingOperation:metadata:accelerate:expires:) \(expectedServiceKey) getObject nil \(expectedExpires)"
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ extension MockAWSS3PreSignedURLBuilder: AWSS3PreSignedURLBuilderBehavior {
func getPreSignedURL(
key: String,
signingOperation: AWSS3SigningOperation,
metadata: [String : String]?,
accelerate: Bool?,
expires: Int64?) async throws -> URL {
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 @@ -80,9 +80,10 @@ public class MockAWSS3StorageService: AWSS3StorageServiceBehavior {
public func getPreSignedURL(
serviceKey: String,
signingOperation: AWSS3SigningOperation,
metadata: [String: String]?,
accelerate: Bool?,
expires: Int) async throws -> URL {
interactions.append("\(#function) \(serviceKey) \(signingOperation) \(expires)")
interactions.append("\(#function) \(serviceKey) \(signingOperation) \(String(describing: metadata)) \(expires)")
return try await getPreSignedURLHandler(serviceKey, signingOperation, expires)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
func testForGetObject() async throws {
let url = try await systemUnderTest.getPreSignedURL(serviceKey: serviceKey,
signingOperation: .getObject,
metadata: nil,
accelerate: nil,
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.getObject) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(AWSS3SigningOperation.getObject) nil \(String(describing: expires))"
])
}

Expand All @@ -82,11 +83,28 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
func testForPutObject() async throws {
let url = try await systemUnderTest.getPreSignedURL(serviceKey: serviceKey,
signingOperation: .putObject,
metadata: nil,
accelerate: nil,
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation: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: [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) \(String(describing: metadata)) \(String(describing: expires))"
])
}

Expand All @@ -97,11 +115,12 @@ class AWSS3StorageServiceGetPreSignedURLBehaviorTests: XCTestCase {
let operation = AWSS3SigningOperation.uploadPart(partNumber: 0, uploadId: UUID().uuidString)
let url = try await systemUnderTest.getPreSignedURL(serviceKey: serviceKey,
signingOperation: operation,
metadata: nil,
accelerate: nil,
expires: expires)
XCTAssertEqual(url, presignedURL)
XCTAssertEqual(builder.interactions, [
"getPreSignedURL(key:signingOperation:accelerate:expires:) \(serviceKey ?? "") \(operation) \(String(describing: expires))"
"getPreSignedURL(key:signingOperation:metadata:accelerate:expires:) \(serviceKey ?? "") \(operation) nil \(String(describing: expires))"
])
}

Expand Down
Loading