Skip to content

Commit

Permalink
chore: resolve swiftlint errors and warnings in Amplify Storage plugin (
Browse files Browse the repository at this point in the history
#3444)

* chore: resolve swiftlint errors

* chore: resolve swiftlint warnings

* chore: resolve swiftlint warnings

* chore: resolve swiftlint errors and warnings

* chore: resolve swiftlint errors and warnings

* chore: resolve swiftlint errors and warnings
  • Loading branch information
phantumcode authored Jan 3, 2024
1 parent f9bfdc4 commit c980aa7
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension AWSS3StoragePlugin {
authService: authService)
let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation)
queue.addOperation(operation)

return taskAdapter
}

Expand Down Expand Up @@ -94,7 +94,7 @@ extension AWSS3StoragePlugin {
authService: authService)
let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation)
queue.addOperation(operation)

return taskAdapter
}

Expand All @@ -112,7 +112,7 @@ extension AWSS3StoragePlugin {
authService: authService)
let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation)
queue.addOperation(operation)

return taskAdapter
}

Expand All @@ -129,7 +129,7 @@ extension AWSS3StoragePlugin {
authService: authService)
let taskAdapter = AmplifyOperationTaskAdapter(operation: operation)
queue.addOperation(operation)

return try await taskAdapter.value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct AWSS3PluginOptions {

/// - Tag: AWSS3PluginOptionsCodingKeys
enum CodingKeys: String, CodingKey {

/// See: https://docs.amplify.aws/lib/storage/transfer-acceleration/q/platform/js/
/// - Tag: AWSS3PluginOptionsCodingKeys.useAccelerateEndpoint
case useAccelerateEndpoint
Expand All @@ -30,7 +30,7 @@ struct AWSS3PluginOptions {
///
/// - Tag: AWSS3PluginOptions.accelerateValue
static func accelerateValue(pluginOptions: Any?) throws -> Bool? {
guard let pluginOptions = pluginOptions as? [String:Any] else {
guard let pluginOptions = pluginOptions as? [String: Any] else {
return nil
}
guard let value = pluginOptions[CodingKeys.useAccelerateEndpoint.rawValue] else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,4 @@ struct AWSS3AbortMultipartUploadRequest {
let bucket: String
let key: String
let uploadId: String

init(bucket: String,
key: String,
uploadId: String) {
self.bucket = bucket
self.key = key
self.uploadId = uploadId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ class AWSS3Adapter: AWSS3Behavior {
S3ClientTypes.CompletedPart(eTag: $0.eTag, partNumber: $0.partNumber)
}
let completedMultipartUpload = S3ClientTypes.CompletedMultipartUpload(parts: parts)
let input = CompleteMultipartUploadInput(bucket: request.bucket, key: request.key, multipartUpload: completedMultipartUpload, uploadId: request.uploadId)
let input = CompleteMultipartUploadInput(
bucket: request.bucket,
key: request.key,
multipartUpload: completedMultipartUpload,
uploadId: request.uploadId
)
do {
let response = try await awsS3.completeMultipartUpload(input: input)
guard let eTag = response.eTag else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,4 @@ struct AWSS3CompleteMultipartUploadRequest {
let key: String
let uploadId: String
let parts: [AWSS3MultipartUploadRequestCompletedPart]

init(bucket: String,
key: String,
uploadId: String,
parts: [AWSS3MultipartUploadRequestCompletedPart]) {
self.bucket = bucket
self.key = key
self.uploadId = uploadId
self.parts = parts
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ struct AWSS3CompleteMultipartUploadResponse {
let bucket: String
let key: String
let eTag: String

init(bucket: String, key: String, eTag: String) {
self.bucket = bucket
self.key = key
self.eTag = eTag
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ struct AWSS3CreateMultipartUploadResponse {
let bucket: String
let key: String
let uploadId: String

init(bucket: String, key: String, uploadId: String) {
self.bucket = bucket
self.key = key
self.uploadId = uploadId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ import Foundation
struct AWSS3DeleteObjectRequest {
let bucket: String
let key: String

init(bucket: String, key: String) {
self.bucket = bucket
self.key = key
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ struct AWSS3ListUploadPartResponse {
let key: String
let uploadId: String
let parts: AWSS3MultipartUploadRequestCompletedParts

init(bucket: String,
key: String,
uploadId: String,
parts: AWSS3MultipartUploadRequestCompletedParts) {
self.bucket = bucket
self.key = key
self.uploadId = uploadId
self.parts = parts
}
}

extension AWSS3ListUploadPartResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import AWSS3
struct AWSS3MultipartUploadRequestCompletedPart {
let partNumber: Int
let eTag: String

init(partNumber: Int, eTag: String) {
self.partNumber = partNumber
self.eTag = eTag
}
}

typealias AWSS3MultipartUploadRequestCompletedParts = [AWSS3MultipartUploadRequestCompletedPart]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ enum UploadPartOutputError: ClientRuntime.HttpResponseErrorBinding {
static func makeError(httpResponse: ClientRuntime.HttpResponse, decoder: ClientRuntime.ResponseDecoder? = nil) async throws -> Swift.Error {
let restXMLError = try await AWSClientRuntime.RestXMLError.makeError(from: httpResponse)
switch restXMLError.errorCode {
default: return try await AWSClientRuntime.UnknownAWSHTTPServiceError.makeError(httpResponse: httpResponse, message: restXMLError.message, requestID: restXMLError.requestId, requestID2: httpResponse.requestId2, typeName: restXMLError.errorCode)
default: return try await AWSClientRuntime.UnknownAWSHTTPServiceError.makeError(
httpResponse: httpResponse,
message: restXMLError.message,
requestID: restXMLError.requestId,
requestID2: httpResponse.requestId2,
typeName: restXMLError.errorCode
)
}
}
}
Expand Down Expand Up @@ -41,21 +47,40 @@ extension UploadPartInput {
.withSigningName(value: "s3")
.withSigningRegion(value: config.signingRegion)
var operation = ClientRuntime.OperationStack<UploadPartInput, UploadPartOutput, UploadPartOutputError>(id: "uploadPart")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<UploadPartInput, UploadPartOutput, UploadPartOutputError>())
operation.initializeStep.intercept(
position: .after,
middleware: ClientRuntime.URLPathMiddleware<UploadPartInput, UploadPartOutput, UploadPartOutputError>()
)
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<UploadPartInput, UploadPartOutput>())
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<UploadPartOutput, UploadPartOutputError>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: config.endpointParams(withBucket: input.bucket)))
operation.buildStep.intercept(
position: .before,
middleware: EndpointResolverMiddleware<UploadPartOutput, UploadPartOutputError>(
endpointResolver: config.serviceSpecific.endpointResolver,
endpointParams: config.endpointParams(withBucket: input.bucket)
)
)
operation.serializeStep.intercept(position: .after, middleware: UploadPartInputBodyMiddleware())
operation.serializeStep.intercept(position: .after, middleware: QueryItemMiddleware())
operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware<DefaultRetryStrategy, AWSRetryErrorInfoProvider, UploadPartOutput, UploadPartOutputError>(options: config.retryStrategyOptions))
operation.finalizeStep.intercept(
position: .after,
middleware: ClientRuntime.RetryMiddleware<DefaultRetryStrategy, AWSRetryErrorInfoProvider, UploadPartOutput, UploadPartOutputError>(
options: config.retryStrategyOptions
)
)
let sigv4Config = AWSClientRuntime.SigV4Config(
signatureType: .requestQueryParams,
useDoubleURIEncode: false,
expiration: expiration,
unsignedBody: true,
signingAlgorithm: .sigv4
)
operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware<UploadPartOutput, UploadPartOutputError>(config: sigv4Config))
operation.deserializeStep.intercept(position: .before, middleware: ClientRuntime.LoggerMiddleware<UploadPartOutput, UploadPartOutputError>(clientLogMode: config.clientLogMode))
operation.finalizeStep.intercept(
position: .before,
middleware: AWSClientRuntime.SigV4Middleware<UploadPartOutput, UploadPartOutputError>(config: sigv4Config)
)
operation.deserializeStep.intercept(
position: .before,
middleware: ClientRuntime.LoggerMiddleware<UploadPartOutput, UploadPartOutputError>(clientLogMode: config.clientLogMode))
operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware<UploadPartOutput, UploadPartOutputError>())
let presignedRequestBuilder = try await operation.presignedRequest(context: context.build(), input: input, next: ClientRuntime.NoopHandler())
guard let builtRequest = presignedRequestBuilder?.build(), let presignedURL = builtRequest.endpoint.url else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ class AWSS3StorageRemoveOperation: AmplifyOperation<
resultListener: resultListener)
}

/// Cancels operation.
override public func cancel() {
super.cancel()
}

/// Perform the task to remove item.
override public func main() {
if isCancelled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy {
let awsS3 = AWSS3Adapter(s3Client, config: clientConfig)
let preSignedURLBuilder = AWSS3PreSignedURLBuilderAdapter(config: clientConfig, bucket: bucket)

var _sessionConfiguration: URLSessionConfiguration
var sessionConfig: URLSessionConfiguration
if let sessionConfiguration = sessionConfiguration {
_sessionConfiguration = sessionConfiguration
sessionConfig = sessionConfiguration
} else {
#if os(macOS)
let sessionConfiguration = URLSessionConfiguration.default
Expand All @@ -90,16 +90,16 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy {
sessionConfiguration.urlCache = nil
sessionConfiguration.allowsCellularAccess = storageConfiguration.allowsCellularAccess
sessionConfiguration.timeoutIntervalForResource = TimeInterval(storageConfiguration.timeoutIntervalForResource)
_sessionConfiguration = sessionConfiguration
sessionConfig = sessionConfiguration
}

_sessionConfiguration.sharedContainerIdentifier = storageConfiguration.sharedContainerIdentifier
sessionConfig.sharedContainerIdentifier = storageConfiguration.sharedContainerIdentifier

self.init(authService: authService,
storageConfiguration: storageConfiguration,
storageTransferDatabase: storageTransferDatabase,
fileSystem: fileSystem,
sessionConfiguration: _sessionConfiguration,
sessionConfiguration: sessionConfig,
logger: logger,
s3Client: s3Client,
preSignedURLBuilder: preSignedURLBuilder,
Expand Down Expand Up @@ -185,7 +185,12 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy {
bucket: pair.transferTask.bucket,
key: pair.transferTask.key,
uploadFile: uploadFile)
guard let session = StorageMultipartUploadSession(client: client, transferTask: pair.transferTask, multipartUpload: multipartUpload, logger: logger) else {
guard let session = StorageMultipartUploadSession(
client: client,
transferTask: pair.transferTask,
multipartUpload: multipartUpload,
logger: logger
) else {
return
}
session.restart()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient {
let requestHeaders: RequestHeaders?
weak var session: StorageMultipartUploadSession?
let metadata: [String: String]?

init(serviceProxy: StorageServiceProxy,
fileSystem: FileSystem = .default,
bucket: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ class StorageMultipartUploadSession {
if case .failed = multipartUpload {
logger.debug("Multipart Upload is failed and event cannot be handled: \(uploadPartEvent)")
return
}
else if case .paused = multipartUpload {
} else if case .paused = multipartUpload {
logger.debug("Multipart Upload is paused and event cannot be handled: \(uploadPartEvent)")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate {
guard let eTag = task.eTag else {
let message = "Completed upload part does not include header value for ETAG: [\(partNumber), \(uploadId)]"
logURLSessionActivity(message, warning: true)
multipartUploadSession.handle(uploadPartEvent: .failed(partNumber: partNumber, error: StorageError.unknown("Upload for part number does not include value for eTag", nil)))
multipartUploadSession.handle(
uploadPartEvent: .failed(
partNumber: partNumber,
error: StorageError.unknown("Upload for part number does not include value for eTag", nil)
)
)
return
}

Expand All @@ -153,7 +158,11 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate {
}

func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
logURLSessionActivity("Session task update: [bytesSent: \(bytesSent)], [totalBytesSent: \(totalBytesSent)], [totalBytesExpectedToSend: \(totalBytesExpectedToSend)]")
logURLSessionActivity(
"""
Session task update: [bytesSent: \(bytesSent)], [totalBytesSent: \(totalBytesSent)], [totalBytesExpectedToSend: \(totalBytesExpectedToSend)]
"""
)

guard let storageService = storageService,
let transferTask = findTransferTask(for: task.taskIdentifier) else { return }
Expand All @@ -165,7 +174,13 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate {
return
}

multipartUploadSession.handle(uploadPartEvent: .progressUpdated(partNumber: partNumber, bytesTransferred: UInt64(bytesSent), taskIdentifier: task.taskIdentifier))
multipartUploadSession.handle(
uploadPartEvent: .progressUpdated(
partNumber: partNumber,
bytesTransferred: UInt64(bytesSent),
taskIdentifier: task.taskIdentifier
)
)
case .upload(let onEvent):
let progress = Progress(totalUnitCount: totalBytesExpectedToSend)
progress.completedUnitCount = totalBytesSent
Expand All @@ -183,7 +198,12 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate {
extension StorageServiceSessionDelegate: URLSessionDownloadDelegate {

func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
logURLSessionActivity("Session download task [\(downloadTask.taskIdentifier)] did write [\(bytesWritten)], [totalBytesWritten \(totalBytesWritten)], [totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)]")
logURLSessionActivity(
"""
Session download task [\(downloadTask.taskIdentifier)] did write [\(bytesWritten)],
[totalBytesWritten \(totalBytesWritten)], [totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)]
"""
)

guard let transferTask = findTransferTask(for: downloadTask.taskIdentifier) else { return }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ struct UploadFile {
let fileURL: URL
let temporaryFileCreated: Bool
let size: UInt64

init(fileURL: URL, temporaryFileCreated: Bool, size: UInt64) {
self.fileURL = fileURL
self.temporaryFileCreated = temporaryFileCreated
self.size = size
}
}

0 comments on commit c980aa7

Please sign in to comment.