Skip to content

Commit

Permalink
chore(core): 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 c993076
Show file tree
Hide file tree
Showing 92 changed files with 484 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

/// Plugin specific options type
///
Expand All @@ -21,7 +21,8 @@ public struct AWSAPIPluginDataStoreOptions {
public let modelName: String

public init(authType: AWSAuthorizationType?,
modelName: String) {
modelName: String)
{

Check failure on line 25 in AmplifyPlugins/Core/AWSPluginsCore/AWSAPIPluginDataStoreOptions.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.authType = authType
self.modelName = modelName
}
Expand Down
5 changes: 3 additions & 2 deletions AmplifyPlugins/Core/AWSPluginsCore/AWSPluginOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

/// Plugin specific options type
///
Expand Down Expand Up @@ -38,7 +38,8 @@ public struct AWSPluginOptions {
public let modelName: String?

public init(authType: AWSAuthorizationType?,
modelName: String) {
modelName: String)
{
self.authType = authType
self.modelName = modelName
}
Expand Down
35 changes: 20 additions & 15 deletions AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.swift
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 Combine
import Amplify
import Combine
import Foundation

/// Represents different auth strategies supported by a client
/// interfacing with an AppSync backend
Expand Down Expand Up @@ -56,7 +56,7 @@ public protocol AuthorizationTypeIterator {

/// Total number of values
var count: Int { get }

/// Whether iterator has next available `AuthorizationType` to return or not
var hasNext: Bool { get }

Expand Down Expand Up @@ -85,7 +85,7 @@ public struct AWSAuthorizationTypeIterator: AuthorizationTypeIterator, Sequence,
public var count: Int {
_count
}

public var hasNext: Bool {
_position < _count
}
Expand All @@ -95,7 +95,7 @@ public struct AWSAuthorizationTypeIterator: AuthorizationTypeIterator, Sequence,
_position += 1
return value
}

return nil
}
}
Expand All @@ -108,15 +108,17 @@ public struct AWSAuthorizationTypeIterator: AuthorizationTypeIterator, Sequence,
/// registered as interceptor for the API
public class AWSDefaultAuthModeStrategy: AuthModeStrategy {
public weak var authDelegate: AuthModeStrategyDelegate?
required public init() {}
public required init() {}

public func authTypesFor(schema: ModelSchema,
operation: ModelOperation) -> AWSAuthorizationTypeIterator {
operation: ModelOperation) -> AWSAuthorizationTypeIterator
{

Check failure on line 115 in AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.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)
return AWSAuthorizationTypeIterator(withValues: [.inferred])
}

public func authTypesFor(schema: ModelSchema,
operations: [ModelOperation]) -> AWSAuthorizationTypeIterator {
operations: [ModelOperation]) -> AWSAuthorizationTypeIterator
{

Check failure on line 121 in AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.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)
return AWSAuthorizationTypeIterator(withValues: [.inferred])
}
}
Expand All @@ -129,7 +131,7 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy {

private typealias AuthPriority = Int

required public init() {}
public required init() {}

private static func defaultAuthTypeFor(authStrategy: AuthStrategy) -> AWSAuthorizationType {
switch authStrategy {
Expand Down Expand Up @@ -199,7 +201,8 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy {
/// Use provider priority to sort if rules have the same strategy
private static let comparator = { (rule1: AuthRule, rule2: AuthRule) -> Bool in
if let providerRule1 = rule1.provider,
let providerRule2 = rule2.provider, rule1.allow == rule2.allow {
let providerRule2 = rule2.provider, rule1.allow == rule2.allow
{

Check failure on line 205 in AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.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)
return priorityOf(authRuleProvider: providerRule1) < priorityOf(authRuleProvider: providerRule2)
}
return priorityOf(authStrategy: rule1.allow) < priorityOf(authStrategy: rule2.allow)
Expand All @@ -211,7 +214,8 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy {
/// - operation: model operation
/// - Returns: an iterator for the applicable auth rules
public func authTypesFor(schema: ModelSchema,
operation: ModelOperation) async -> AWSAuthorizationTypeIterator {
operation: ModelOperation) async -> AWSAuthorizationTypeIterator
{

Check failure on line 218 in AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.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)
return await authTypesFor(schema: schema, operations: [operation])
}

Expand All @@ -221,18 +225,19 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy {
/// - operations: model operations
/// - Returns: an iterator for the applicable auth rules
public func authTypesFor(schema: ModelSchema,
operations: [ModelOperation]) async -> AWSAuthorizationTypeIterator {
operations: [ModelOperation]) async -> AWSAuthorizationTypeIterator
{

Check failure on line 229 in AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.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)
var sortedRules = operations
.flatMap { schema.authRules.filter(modelOperation: $0) }
.reduce(into: [AuthRule](), { array, rule in
.reduce(into: [AuthRule]()) { array, rule in
if !array.contains(rule) {
array.append(rule)
}
})
}
.sorted(by: AWSMultiAuthModeStrategy.comparator)

// if there isn't a user signed in, returns only public or custom rules
if let authDelegate = authDelegate, await !authDelegate.isUserLoggedIn() {
if let authDelegate, await !authDelegate.isUserLoggedIn() {
sortedRules = sortedRules.filter { rule in
return rule.allow == .public || rule.allow == .custom
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

public class AWSAuthService: AWSAuthServiceBehavior {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

public protocol AWSAuthServiceBehavior: AnyObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

/// Defines the contract for an AuthSession that can vend AWS credentials and store a user ID
/// (`sub`) for the underlying OIDC-compliant authentication provider such as Cognito user pools.
Expand All @@ -19,13 +19,13 @@ import Amplify
/// successfully completed a `signIn` flow, and has not subsequently signed out.
public protocol AWSAuthSessionBehavior<Tokens>: AuthSession {

/// The concrete type holding the OIDC tokens from the authentication provider.
/// The concrete type holding the OIDC tokens from the authentication provider.
/// Generally, this type will have at least methods for retrieving an identity token and an access token.
associatedtype Tokens

/// The result of the most recent attempt to get AWS Credentials. There is no guarantee that the credentials
/// are not expired, but conforming types may have logic in place to automatically refresh the credentials.
/// The credentials may be fore either the unauthenticated or authenticated role, depending on the
/// The credentials may be fore either the unauthenticated or authenticated role, depending on the
/// configuration of the identity pool and the tokens used to retrieve the identity ID from Cognito.
///
/// If the most recent attempt caused an error, the result will contain the details of the error.
Expand All @@ -34,7 +34,7 @@ public protocol AWSAuthSessionBehavior<Tokens>: AuthSession {
// swiftlint:disable line_length
/// The result of the most recent attempt to get a
/// [Cognito identity pool identity ID](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html#CognitoIdentity-GetId-response-IdentityId).
/// The identityID may represent either an unauthenticated or authenticated identity,
/// The identityID may represent either an unauthenticated or authenticated identity,
/// depending on the configuration of the identity pool and the tokens used to
/// retrieve the identity ID from Cognito.
///
Expand All @@ -49,7 +49,7 @@ public protocol AWSAuthSessionBehavior<Tokens>: AuthSession {
/// If the most recent attempt caused an error, the result will contain the details of the error.
var userSubResult: Result<String, AuthError> { get }

/// The result of the most recent attempt to get the current user's `sub` (unique User ID).
/// The result of the most recent attempt to get the current user's `sub` (unique User ID).
/// Depending on the underlying implementation,
/// the details of the tokens may vary, but it is expected that the type will have at least methods for
/// retrieving an identity token and an access token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

// swiftlint:disable line_length

Expand Down Expand Up @@ -49,8 +49,8 @@ extension AWSAuthorizationType: CaseIterable { }
extension AWSAuthorizationType: Codable { }

/// Indicates whether the authotization type requires the auth plugin to operate.
extension AWSAuthorizationType {
public var requiresAuthPlugin: Bool {
public extension AWSAuthorizationType {
var requiresAuthPlugin: Bool {
switch self {
case .none, .apiKey, .openIDConnect, .function:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0
//


import Foundation

/// - Warning: Although this has `public` access, it is intended for internal use and should not be used directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ public extension AuthAWSCredentialsProvider where Self: AWSAuthSessionBehavior {
/// Return the most recent Result of fetching the AWS Credentials. If the temporary credentials are expired, returns
/// a `AuthError.sessionExpired` failure.
func getAWSCredentials() -> Result<AWSCredentials, AuthError> {
let result: Result<AWSCredentials, AuthError>
switch awsCredentialsResult {
case .failure(let error): result = .failure(error)
let result: Result<AWSCredentials, AuthError> = switch awsCredentialsResult {
case .failure(let error): .failure(error)
case .success(let tempCreds):
if tempCreds.expiration > Date() {
result = .success(tempCreds)
.success(tempCreds)
} else {
result = .failure(AuthError.sessionExpired("AWS Credentials are expired", ""))
.failure(AuthError.sessionExpired("AWS Credentials are expired", ""))
}
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

public enum AWSAuthorizationConfiguration {
case none
Expand All @@ -20,18 +20,20 @@ public enum AWSAuthorizationConfiguration {
// MARK: - AWSAuthorizationConfiguration factory
extension AWSAuthorizationConfiguration {
private static func awsIAMAuthorizationConfiguration(region: String?)
throws -> AWSAuthorizationConfiguration {
guard let region = region else {
throws -> AWSAuthorizationConfiguration
{

Check failure on line 24 in AmplifyPlugins/Core/AWSPluginsCore/Auth/Configuration/AWSAuthorizationConfiguration.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)
guard let region else {
throw PluginError.pluginConfigurationError("Region is not set for IAM",
"Set the region")
}
return .awsIAM(AWSIAMConfiguration(region: region))
}

private static func apiKeyAuthorizationConfiguration(apiKey: String?)
throws -> AWSAuthorizationConfiguration {
throws -> AWSAuthorizationConfiguration
{

Check failure on line 34 in AmplifyPlugins/Core/AWSPluginsCore/Auth/Configuration/AWSAuthorizationConfiguration.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)

guard let apiKey = apiKey else {
guard let apiKey else {
throw PluginError.pluginConfigurationError(
"Could not get `ApiKey` from plugin configuration",
"""
Expand All @@ -55,7 +57,8 @@ extension AWSAuthorizationConfiguration {
/// - Returns: an `AWSAuthorizationConfiguration` according to the provided `authType`
public static func makeConfiguration(authType: AWSAuthorizationType,
region: String?,
apiKey: String?) throws -> AWSAuthorizationConfiguration {
apiKey: String?) throws -> AWSAuthorizationConfiguration
{

Check failure on line 61 in AmplifyPlugins/Core/AWSPluginsCore/Auth/Configuration/AWSAuthorizationConfiguration.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)
switch authType {
case .none:
return .none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ extension KeychainStatus: CustomStringConvertible {
self = .success
case -128:
self = .userCanceled
case -25299:
case -25_299:
self = .duplicateItem
case -25300:
case -25_300:
self = .itemNotFound
case -34018:
case -34_018:
self = .missingEntitlement
default:
self = .unexpectedError(status)
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 Amplify
import Foundation
import Security
import Amplify

// swiftlint:disable identifier_name
public protocol KeychainStoreBehavior {
Expand Down Expand Up @@ -233,7 +233,7 @@ public struct KeychainStore: KeychainStoreBehavior {
}

extension KeychainStore {
struct Constants {
enum Constants {
/** Class Key Constant */
static let Class = String(kSecClass)
static let ClassGenericPassword = String(kSecClassGenericPassword)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension KeychainStoreAttributes {
KeychainStore.Constants.UseDataProtectionKeyChain: kCFBooleanTrue
]

if let accessGroup = accessGroup {
if let accessGroup {
query[KeychainStore.Constants.AttributeAccessGroup] = accessGroup
}
return query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

/// Custom implementation of Codable for AnyModel stores the instance as its JSON string representation and uses the
/// ModelRegistry utilities to deserialize it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
/// ```swift
/// let id = model["id"]
/// ```
extension AnyModel {
public extension AnyModel {

public subscript(_ key: String) -> Any? {
subscript(_ key: String) -> Any? {
let mirror = Mirror(reflecting: instance)
let property = mirror.children.first { $0.label == key }
return property?.value
}

public subscript(_ key: CodingKey) -> Any? {
subscript(_ key: CodingKey) -> Any? {
return self[key.stringValue]
}

Expand Down
Loading

0 comments on commit c993076

Please sign in to comment.