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

chore: kickoff release #3320

Merged
merged 2 commits into from
Oct 23, 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 @@ -12,12 +12,17 @@ import AwsCommonRuntimeKit

extension CommonRunTimeError: PushNotificationsErrorConvertible {
var pushNotificationsError: PushNotificationsError {
if isConnectivityError {
return .network(
PushNotificationsPluginErrorConstants.deviceOffline.errorDescription,
PushNotificationsPluginErrorConstants.deviceOffline.recoverySuggestion,
self
)
}

switch self {
case .crtError(let crtError):
let errorDescription = isConnectivityError
? AWSPinpointErrorConstants.deviceOffline.errorDescription
: crtError.message
return .unknown(errorDescription, self)
return .unknown(crtError.message, self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,25 @@ class AWSS3StorageUploadDataOperation: AmplifyInProcessReportingOperation<
do {
let prefix = try await prefixResolver.resolvePrefix(for: request.options.accessLevel, targetIdentityId: request.options.targetIdentityId)
let serviceKey = prefix + request.key
let serviceMetadata = StorageRequestUtils.getServiceMetadata(request.options.metadata)
let accelerate = try AWSS3PluginOptions.accelerateValue(pluginOptions: request.options.pluginOptions)
if request.data.count > StorageUploadDataRequest.Options.multiPartUploadSizeThreshold {
storageService.multiPartUpload(serviceKey: serviceKey,
uploadSource: .data(request.data),
contentType: request.options.contentType,
metadata: serviceMetadata,
accelerate: accelerate) { [weak self] event in
storageService.multiPartUpload(
serviceKey: serviceKey,
uploadSource: .data(request.data),
contentType: request.options.contentType,
metadata: request.options.metadata,
accelerate: accelerate
) { [weak self] event in
self?.onServiceEvent(event: event)
}
} else {
storageService.upload(serviceKey: serviceKey,
uploadSource: .data(request.data),
contentType: request.options.contentType,
metadata: serviceMetadata,
accelerate: accelerate) { [weak self] event in
storageService.upload(
serviceKey: serviceKey,
uploadSource: .data(request.data),
contentType: request.options.contentType,
metadata: request.options.metadata,
accelerate: accelerate
) { [weak self] event in
self?.onServiceEvent(event: event)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,25 @@ class AWSS3StorageUploadFileOperation: AmplifyInProcessReportingOperation<
do {
let prefix = try await prefixResolver.resolvePrefix(for: request.options.accessLevel, targetIdentityId: request.options.targetIdentityId)
let serviceKey = prefix + request.key
let serviceMetadata = StorageRequestUtils.getServiceMetadata(request.options.metadata)
let accelerate = try AWSS3PluginOptions.accelerateValue(pluginOptions: request.options.pluginOptions)
if uploadSize > StorageUploadFileRequest.Options.multiPartUploadSizeThreshold {
storageService.multiPartUpload(serviceKey: serviceKey,
uploadSource: .local(request.local),
contentType: request.options.contentType,
metadata: serviceMetadata,
accelerate: accelerate) { [weak self] event in
storageService.multiPartUpload(
serviceKey: serviceKey,
uploadSource: .local(request.local),
contentType: request.options.contentType,
metadata: request.options.metadata,
accelerate: accelerate
) { [weak self] event in
self?.onServiceEvent(event: event)
}
} else {
storageService.upload(serviceKey: serviceKey,
uploadSource: .local(request.local),
contentType: request.options.contentType,
metadata: serviceMetadata,
accelerate: accelerate) { [weak self] event in
storageService.upload(
serviceKey: serviceKey,
uploadSource: .local(request.local),
contentType: request.options.contentType,
metadata: request.options.metadata,
accelerate: accelerate
) { [weak self] event in
self?.onServiceEvent(event: event)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
// The AWS S3 SDK handles the request so there will be not taskIdentifier
session.handle(multipartUploadEvent: .creating)

let request = CreateMultipartUploadRequest(bucket: bucket, key: key)
// User-defined metadata needs to provided
// when initiating the MPU.
// --
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html#mpu-process
// > Multipart upload initiation
// "If you want to provide any metadata describing the object
// being uploaded, you must provide it in the request to initiate
// multipart upload."
let request = CreateMultipartUploadRequest(
bucket: bucket,
key: key,
metadata: metadata
)
serviceProxy.awsS3.createMultipartUpload(request) { [weak self] result in
guard let self = self else { return }
switch result {
Expand Down Expand Up @@ -139,7 +151,9 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
let preSignedURL = try await serviceProxy.preSignedURLBuilder.getPreSignedURL(
key: self.key,
signingOperation: operation,
metadata: self.metadata,
// user-controlled metadata should *not* be provided
// with each upload part.
metadata: nil,
accelerate: nil,
expires: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ extension StorageRequestUtils {
return accessLevel.serviceAccessPrefix + "/"
}

static func getServiceMetadata(_ metadata: [String: String]?) -> [String: String]? {
guard let metadata = metadata else {
return nil
}
var serviceMetadata: [String: String] = [:]
for (key, value) in metadata {
let serviceKey = metadataKeyPrefix + key
serviceMetadata[serviceKey] = value
}

return serviceMetadata
}

static func getSize(_ file: URL) throws -> UInt64 {
if let error = validateFileExists(file) {
throw StorageError.localFileNotFound(error.errorDescription, error.recoverySuggestion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class AWSS3StorageUploadDataOperationTests: AWSS3StorageOperationTestBase {

let expectedUploadSource = UploadSource.data(testData)
let metadata = ["mykey": "Value"]
let expectedMetadata = ["x-amz-meta-mykey": "Value"]

let options = StorageUploadDataRequest.Options(accessLevel: .protected,
metadata: metadata,
Expand Down Expand Up @@ -119,7 +118,7 @@ class AWSS3StorageUploadDataOperationTests: AWSS3StorageOperationTestBase {
key: testKey,
uploadSource: expectedUploadSource,
contentType: testContentType,
metadata: expectedMetadata)
metadata: metadata)
}

func testUploadDataOperationUploadFail() {
Expand Down Expand Up @@ -183,7 +182,6 @@ class AWSS3StorageUploadDataOperationTests: AWSS3StorageOperationTestBase {
"Could not create data object greater than MultiPartUploadSizeThreshold")
let expectedUploadSource = UploadSource.data(testLargeData)
let metadata = ["mykey": "Value"]
let expectedMetadata = ["x-amz-meta-mykey": "Value"]

let options = StorageUploadDataRequest.Options(accessLevel: .protected,
metadata: metadata,
Expand Down Expand Up @@ -218,7 +216,7 @@ class AWSS3StorageUploadDataOperationTests: AWSS3StorageOperationTestBase {
key: testKey,
uploadSource: expectedUploadSource,
contentType: testContentType,
metadata: expectedMetadata)
metadata: metadata)
}

// TODO: test pause, resume, canel, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class AWSS3StorageUploadFileOperationTests: AWSS3StorageOperationTestBase {
FileManager.default.createFile(atPath: filePath, contents: testData, attributes: nil)
let expectedUploadSource = UploadSource.local(fileURL)
let metadata = ["mykey": "Value"]
let expectedMetadata = ["x-amz-meta-mykey": "Value"]

let options = StorageUploadFileRequest.Options(accessLevel: .protected,
metadata: metadata,
Expand Down Expand Up @@ -153,7 +152,7 @@ class AWSS3StorageUploadFileOperationTests: AWSS3StorageOperationTestBase {
key: testKey,
uploadSource: expectedUploadSource,
contentType: testContentType,
metadata: expectedMetadata)
metadata: metadata)
}

func testUploadFileOperationUploadFail() {
Expand Down Expand Up @@ -219,7 +218,6 @@ class AWSS3StorageUploadFileOperationTests: AWSS3StorageOperationTestBase {
"Could not create data object greater than MultiPartUploadSizeThreshold")
let expectedUploadSource = UploadSource.local(testURL)
let metadata = ["mykey": "Value"]
let expectedMetadata = ["x-amz-meta-mykey": "Value"]

let options = StorageUploadFileRequest.Options(accessLevel: .protected,
metadata: metadata,
Expand Down Expand Up @@ -254,7 +252,7 @@ class AWSS3StorageUploadFileOperationTests: AWSS3StorageOperationTestBase {
key: testKey,
uploadSource: expectedUploadSource,
contentType: testContentType,
metadata: expectedMetadata)
metadata: metadata)
}

// TODO: test pause, resume, canel, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ class StorageRequestUtilsGetterTests: XCTestCase {
XCTAssertEqual(result, expected)
}

// MARK: GetServiceMetadata tests

func testGetServiceMetadataConstructsMetadataKeysWithS3Prefix() {
let metadata = ["key1": "value1", "key2": "value2"]
let results = StorageRequestUtils.getServiceMetadata(metadata)
XCTAssertNotNil(results)

for (key, value) in results! {
XCTAssertNotNil(key)
XCTAssertNotNil(value)
XCTAssertTrue(key.contains(StorageRequestUtils.metadataKeyPrefix))
}
}

// MARK: GetSize tests

func testGetSizeForFileUploadSourceReturnsSize() throws {
Expand Down
Loading
Loading