Skip to content

Commit

Permalink
chore: Revert "feat(storage) AWS SDK S3 accelerate via useAccelerateE…
Browse files Browse the repository at this point in the history
…ndpoint pluginOptions. (#3087)" (#3096)

This reverts commit 54e1100.
  • Loading branch information
harsh62 authored Jul 18, 2023
1 parent 54e1100 commit d6c71c8
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ extension AWSS3StoragePlugin {
if let pluginOptions = options.pluginOptions as? AWSStorageGetURLOptions, pluginOptions.validateObjectExistence {
try await storageService.validateObjectExistence(serviceKey: serviceKey)
}
let accelerate = try AWSS3PluginOptions.accelerateValue(
pluginOptions: options.pluginOptions)
let result = try await storageService.getPreSignedURL(
serviceKey: serviceKey,
signingOperation: .getObject,
accelerate: accelerate,
expires: options.expires)
let result = try await storageService.getPreSignedURL(serviceKey: serviceKey,
signingOperation: .getObject,
expires: options.expires)

let channel = HubChannel(from: categoryType)
let payload = HubPayload(eventName: HubPayload.EventName.Storage.getURL, context: options, data: result)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
/// - Returns: Pre-Signed URL
func getPreSignedURL(key: String,
signingOperation: AWSS3SigningOperation,
accelerate: Bool? = nil,
expires: Int64? = nil) async throws -> URL {
let expiresDate = Date(timeIntervalSinceNow: Double(expires ?? defaultExpiration))
let expiration = expiresDate.timeIntervalSinceNow
let config = (accelerate == nil) ? self.config : S3ClientConfigurationProxy(
target: self.config,
accelerateOverride: accelerate)
let preSignedUrl: URL?
switch signingOperation {
case .getObject:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,14 @@ import AWSS3
import ClientRuntime
import AWSClientRuntime

/// - Tag: AWSS3PreSignedURLBuilderError
enum AWSS3PreSignedURLBuilderError: Error {

/// Returned by an implementation of a
/// [AWSS3PreSignedURLBuilderBehavior](x-source-tag://AWSS3PreSignedURLBuilderBehavior)
///
/// - Tag: AWSS3PreSignedURLBuilderError.failed
case failed(reason: String, error: Error?)
}

/// Behavior that the implemenation class for AWSS3PreSignedURLBuilder will use.
///
/// - Tag: AWSS3PreSignedURLBuilderBehavior
// Behavior that the implemenation class for AWSS3PreSignedURLBuilder will use.
protocol AWSS3PreSignedURLBuilderBehavior {

/// Attempts to generate a pre-signed URL.
///
/// - Parameters:
/// - key: String represnting the key of an S3 object.
/// - signingOperation: [AWSS3SigningOperation](x-source-tag://AWSS3SigningOperation)
/// (get, put, upload part) for which the URL will be generated.
/// - accelerate: Optional boolean indicating wether or not to enable S3 bucket
/// [transfer acceleration](https://docs.amplify.aws/lib/storage/transfer-acceleration/q/platform/js/)
/// - expires: Int64 indicating the expiration as the number of milliseconds since the 1970 epoc.
/// Gets a pre-signed URL.
/// - Returns: Pre-Signed URL
///
/// - Tag: AWSS3PreSignedURLBuilderBehavior.getPreSignedURL
func getPreSignedURL(key: String,
signingOperation: AWSS3SigningOperation,
accelerate: Bool?,
expires: Int64?) async throws -> URL

func getPreSignedURL(key: String, signingOperation: AWSS3SigningOperation, expires: Int64?) async throws -> URL
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class AWSS3StorageDownloadDataOperation: AmplifyInProcessReportingOperation<
do {
let prefix = try await prefixResolver.resolvePrefix(for: request.options.accessLevel, targetIdentityId: request.options.targetIdentityId)
let serviceKey = prefix + request.key
let accelerate = try AWSS3PluginOptions.accelerateValue(pluginOptions: request.options.pluginOptions)
storageService.download(serviceKey: serviceKey, fileURL: nil, accelerate: accelerate) { [weak self] event in
storageService.download(serviceKey: serviceKey, fileURL: nil) { [weak self] event in
self?.onServiceEvent(event: event)
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class AWSS3StorageDownloadFileOperation: AmplifyInProcessReportingOperation<
do {
let prefix = try await prefixResolver.resolvePrefix(for: request.options.accessLevel, targetIdentityId: request.options.targetIdentityId)
let serviceKey = prefix + request.key
let accelerate = try AWSS3PluginOptions.accelerateValue(pluginOptions: request.options.pluginOptions)
storageService.download(serviceKey: serviceKey, fileURL: self.request.local, accelerate: accelerate) { [weak self] event in
storageService.download(serviceKey: serviceKey, fileURL: self.request.local) { [weak self] event in
self?.onServiceEvent(event: event)
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,18 @@ class AWSS3StorageUploadDataOperation: AmplifyInProcessReportingOperation<
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
metadata: serviceMetadata) { [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
metadata: serviceMetadata) { [weak self] event in
self?.onServiceEvent(event: event)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,18 @@ class AWSS3StorageUploadFileOperation: AmplifyInProcessReportingOperation<
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
metadata: serviceMetadata) { [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
metadata: serviceMetadata) { [weak self] event in
self?.onServiceEvent(event: event)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ extension AWSS3StorageService {

func download(serviceKey: String,
fileURL: URL?,
accelerate: Bool?,
onEvent: @escaping StorageServiceDownloadEventHandler) {
onEvent: @escaping StorageServiceDownloadEventHandler) {
let fail: (Error) -> Void = { error in
let storageError = StorageError(error: error)
onEvent(.failed(storageError))
Expand All @@ -28,10 +27,7 @@ extension AWSS3StorageService {

Task {
do {
let preSignedURL = try await preSignedURLBuilder.getPreSignedURL(key: serviceKey,
signingOperation: .getObject,
accelerate: accelerate,
expires: nil)
let preSignedURL = try await preSignedURLBuilder.getPreSignedURL(key: serviceKey, signingOperation: .getObject, expires: nil)
startDownload(preSignedURL: preSignedURL, transferTask: transferTask)
} catch {
onEvent(.failed(StorageError.unknown("Failed to get pre-signed URL", nil)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ extension AWSS3StorageService {

func getPreSignedURL(serviceKey: String,
signingOperation: AWSS3SigningOperation,
accelerate: Bool?,
expires: Int) async throws -> URL {
return try await preSignedURLBuilder.getPreSignedURL(
key: serviceKey,
signingOperation: signingOperation,
accelerate: accelerate,
expires: Int64(expires))
return try await preSignedURLBuilder.getPreSignedURL(key: serviceKey, signingOperation: signingOperation, expires: Int64(expires))
}

func validateObjectExistence(serviceKey: String) async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension AWSS3StorageService {
uploadSource: UploadSource,
contentType: String?,
metadata: [String: String]?,
accelerate: Bool?,
onEvent: @escaping StorageServiceMultiPartUploadEventHandler) {
let fail: (Error) -> Void = { error in
let storageError = StorageError(error: error)
Expand Down
Loading

0 comments on commit d6c71c8

Please sign in to comment.