Skip to content

Commit

Permalink
chore(storage): resolve swiftformat errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 3, 2024
1 parent ca6c65a commit b69b17e
Show file tree
Hide file tree
Showing 149 changed files with 1,106 additions and 1,000 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import Foundation

import AWSS3
import Amplify
import AWSPluginsCore
import AWSS3

extension AWSS3StoragePlugin {
public extension AWSS3StoragePlugin {

@discardableResult
public func getURL(
func getURL(
key: String,
options: StorageGetURLOperation.Request.Options? = nil
) async throws -> URL {
Expand Down Expand Up @@ -45,7 +45,7 @@ extension AWSS3StoragePlugin {
return result
}

public func getURL(
func getURL(
path: any StoragePath,
options: StorageGetURLOperation.Request.Options? = nil
) async throws -> URL {
Expand All @@ -57,7 +57,7 @@ extension AWSS3StoragePlugin {
return try await task.value
}

public func downloadData(
func downloadData(
path: any StoragePath,
options: StorageDownloadDataOperation.Request.Options? = nil
) -> StorageDownloadDataTask {
Expand All @@ -74,7 +74,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func downloadData(
func downloadData(
key: String,
options: StorageDownloadDataOperation.Request.Options? = nil
) -> StorageDownloadDataTask {
Expand All @@ -91,7 +91,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func downloadFile(
func downloadFile(
key: String,
local: URL,
options: StorageDownloadFileOperation.Request.Options? = nil
Expand All @@ -109,7 +109,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func downloadFile(
func downloadFile(
path: any StoragePath,
local: URL,
options: StorageDownloadFileOperation.Request.Options? = nil
Expand All @@ -127,7 +127,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func uploadData(
func uploadData(
key: String,
data: Data,
options: StorageUploadDataOperation.Request.Options? = nil
Expand All @@ -145,7 +145,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func uploadData(
func uploadData(
path: any StoragePath,
data: Data,
options: StorageUploadDataOperation.Request.Options? = nil
Expand All @@ -163,7 +163,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func uploadFile(
func uploadFile(
key: String,
local: URL,
options: StorageUploadFileOperation.Request.Options? = nil
Expand All @@ -181,7 +181,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func uploadFile(
func uploadFile(
path: any StoragePath,
local: URL,
options: StorageUploadFileOperation.Request.Options? = nil
Expand All @@ -199,7 +199,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func remove(
func remove(
key: String,
options: StorageRemoveOperation.Request.Options? = nil
) async throws -> String {
Expand All @@ -216,7 +216,7 @@ extension AWSS3StoragePlugin {
}

@discardableResult
public func remove(
func remove(
path: any StoragePath,
options: StorageRemoveOperation.Request.Options? = nil
) async throws -> String {
Expand All @@ -229,7 +229,7 @@ extension AWSS3StoragePlugin {
return try await task.value
}

public func list(
func list(
options: StorageListRequest.Options? = nil
) async throws -> StorageListResult {
let options = options ?? StorageListRequest.Options()
Expand All @@ -244,7 +244,7 @@ extension AWSS3StoragePlugin {
return result
}

public func list(
func list(
path: any StoragePath,
options: StorageListRequest.Options? = nil
) async throws -> StorageListResult {
Expand All @@ -257,7 +257,7 @@ extension AWSS3StoragePlugin {
return try await task.value
}

public func handleBackgroundEvents(identifier: String) async -> Bool {
func handleBackgroundEvents(identifier: String) async -> Bool {
await withCheckedContinuation { (continuation: CheckedContinuation<Bool, Never>) in
StorageBackgroundEventsRegistry.handleBackgroundEvents(identifier: identifier, continuation: continuation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import Foundation

import AWSS3
import Amplify
import AWSPluginsCore
import AWSS3

extension AWSS3StoragePlugin {
public extension AWSS3StoragePlugin {

/// Retrieve the escape hatch to perform low level operations on S3.
///
/// - Returns: S3 client
///
/// - Tag: AWSS3StoragePlugin.getEscapeHatch
public func getEscapeHatch() -> S3Client {
func getEscapeHatch() -> S3Client {
return storageService.getEscapeHatch()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ extension AWSS3StoragePlugin {
let storageService = try AWSS3StorageService(authService: authService,
region: configClosures.retrieveRegion(),
bucket: configClosures.retrieveBucket(),
httpClientEngineProxy: self.httpClientEngineProxy)
storageService.urlRequestDelegate = self.urlRequestDelegate
httpClientEngineProxy: httpClientEngineProxy)
storageService.urlRequestDelegate = urlRequestDelegate

configure(storageService: storageService,
configure(storageService: storageService,
authService: authService,
defaultAccessLevel: defaultAccessLevel)
} catch let storageError as StorageError {
Expand Down Expand Up @@ -74,7 +74,8 @@ extension AWSS3StoragePlugin {
func configure(storageService: AWSS3StorageServiceBehavior,
authService: AWSAuthServiceBehavior,
defaultAccessLevel: StorageAccessLevel,
queue: OperationQueue = OperationQueue()) {
queue: OperationQueue = OperationQueue())
{
self.storageService = storageService
self.authService = authService
self.queue = queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AWSPluginsCore
import Foundation

extension AWSS3StoragePlugin {
public extension AWSS3StoragePlugin {

/// Resets the state of the plugin.
///
/// Calls the reset methods on the storage service and authentication service to clean up resources. Setting the
/// storage service, authentication service, and queue to nil to allow deallocation.
///
/// - Tag: AWSS3StoragePlugin.reset
public func reset() async {
func reset() async {
if storageService != nil {
storageService.reset()
storageService = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//

import Amplify
import Foundation
import AWSPluginsCore
import Foundation

/// The AWSS3StoragePlugin which conforms to the Amplify plugin protocols and implements the Storage
/// Plugin APIs for AWS S3.
///
/// - Tag: AWSS3StoragePlugin
final public class AWSS3StoragePlugin: StorageCategoryPlugin {
public final class AWSS3StoragePlugin: StorageCategoryPlugin {

/// An instance of the S3 storage service.
var storageService: AWSS3StorageServiceBehavior!
Expand All @@ -39,16 +39,17 @@ final public class AWSS3StoragePlugin: StorageCategoryPlugin {
let storageConfiguration: AWSS3StoragePluginConfiguration

/// See [HttpClientEngineProxy](x-source-tag://HttpClientEngineProxy)
internal var httpClientEngineProxy: HttpClientEngineProxy?
var httpClientEngineProxy: HttpClientEngineProxy?

/// See [URLRequestDelegate](x-source-tag://URLRequestDelegate)
internal weak var urlRequestDelegate: URLRequestDelegate?
weak var urlRequestDelegate: URLRequestDelegate?

/// Instantiates an instance of the AWSS3StoragePlugin.
///
/// - Tag: AWSS3StoragePlugin.init
public init(configuration
storageConfiguration: AWSS3StoragePluginConfiguration = AWSS3StoragePluginConfiguration()) {
storageConfiguration: AWSS3StoragePluginConfiguration = AWSS3StoragePluginConfiguration())
{
self.storageConfiguration = storageConfiguration
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Amplify
import Foundation

/// - Tag: AWSS3PluginOptions
struct AWSS3PluginOptions {
enum AWSS3PluginOptions {

/// - Tag: AWSS3PluginOptionsCodingKeys
enum CodingKeys: String, CodingKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AWSPluginsCore
import Foundation

/// Resolves the final prefix prepended to the S3 key for a given request.
///
Expand All @@ -25,7 +25,8 @@ public protocol AWSS3PluginPrefixResolver {
@available(*, deprecated)
public struct PassThroughPrefixResolver: AWSS3PluginPrefixResolver {
public func resolvePrefix(for accessLevel: StorageAccessLevel,
targetIdentityId: String?) async throws -> String {
targetIdentityId: String?) async throws -> String
{
""
}
}
Expand All @@ -45,7 +46,8 @@ struct StorageAccessLevelAwarePrefixResolver {

extension StorageAccessLevelAwarePrefixResolver: AWSS3PluginPrefixResolver {
func resolvePrefix(for accessLevel: StorageAccessLevel,
targetIdentityId: String?) async throws -> String {
targetIdentityId: String?) async throws -> String
{
do {
let identityId = try await authService.getIdentityID()
let prefix = StorageRequestUtils.getAccessLevelPrefix(accessLevel: accessLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public struct AWSS3StoragePluginConfiguration {
/// - Tag: AWSS3StoragePluginConfiguration.prefixResolverFunc
@available(*, deprecated, message: "Use `StoragePath` instead")
public static func prefixResolver(
_ prefixResolver: AWSS3PluginPrefixResolver) -> AWSS3StoragePluginConfiguration {
_ prefixResolver: AWSS3PluginPrefixResolver) -> AWSS3StoragePluginConfiguration
{
.init(prefixResolver: prefixResolver)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation

import Amplify

import AWSClientRuntime
import AWSS3
import ClientRuntime
import AWSClientRuntime

/// The class conforming to AWSS3Behavior which uses an instance of the AWSS3 to perform its methods.
/// This class acts as a wrapper to expose AWSS3 functionality through an instance over a singleton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation

import Amplify

import AWSClientRuntime
import AWSS3
import ClientRuntime
import AWSClientRuntime

// Behavior that the implemenation class for AWSS3 will use.
protocol AWSS3Behavior {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation

import Amplify

import AWSClientRuntime
import AWSS3
import ClientRuntime
import AWSClientRuntime

struct AWSS3ListObjectsV2Request {
let bucket: String
Expand All @@ -28,7 +28,8 @@ struct AWSS3ListObjectsV2Request {
continuationToken: String? = nil,
delimiter: String? = nil,
maxKeys: Int = 1_000,
startAfter: String? = nil) {
startAfter: String? = nil)
{

Check failure on line 32 in AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3ListObjectsV2Request.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.bucket = bucket
self.prefix = prefix
self.path = path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typealias AWSS3MultipartUploadRequestCompletedParts = [AWSS3MultipartUploadReque
extension AWSS3MultipartUploadRequestCompletedParts {

init(completedParts: StorageUploadParts) {
let eTags = completedParts.map { $0.eTag }
let eTags = completedParts.map(\.eTag)
let parts = eTags.indices.map { index in
AWSS3MultipartUploadRequestCompletedPart(partNumber: index + 1, eTag: eTags[index] ?? "")
}
Expand All @@ -29,7 +29,8 @@ extension AWSS3MultipartUploadRequestCompletedParts {
init(parts: [S3ClientTypes.Part]) {
self = parts.compactMap {
guard let eTag = $0.eTag,
let partNumber = $0.partNumber else {
let partNumber = $0.partNumber
else {
return nil
}
return AWSS3MultipartUploadRequestCompletedPart(partNumber: partNumber, eTag: eTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Foundation

import Amplify
import AWSS3
import AWSClientRuntime
import AWSPluginsCore
import AWSS3
import ClientRuntime
import AWSClientRuntime

/// The class confirming to AWSS3PreSignedURLBuilderBehavior which uses GetObjectInput to
/// create a pre-signed URL.
Expand All @@ -36,7 +36,8 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
signingOperation: AWSS3SigningOperation,
metadata: [String: String]? = nil,
accelerate: Bool? = nil,
expires: Int64? = nil) async throws -> URL {
expires: Int64? = nil) async throws -> URL
{

Check failure on line 40 in AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3PreSignedURLBuilderAdapter.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
let expiresDate = Date(timeIntervalSinceNow: Double(expires ?? defaultExpiration))
let expiration = expiresDate.timeIntervalSinceNow
let config = try config.withAccelerate(accelerate)
Expand Down Expand Up @@ -65,7 +66,7 @@ class AWSS3PreSignedURLBuilderAdapter: AWSS3PreSignedURLBuilderBehavior {
}

private func urlWithEscapedToken(_ url: URL?) -> URL? {
guard let url = url,
guard let url,
var components = URLComponents(string: url.absoluteString),
var token = components.queryItems?.first(where: { $0.name == "X-Amz-Security-Token" }) else {
return nil
Expand Down
Loading

0 comments on commit b69b17e

Please sign in to comment.