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(Auth): Add logging to non throwing tasks #3791

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -33,7 +33,6 @@ class AWSAuthChangePasswordTask: AuthChangePasswordTask, DefaultLogger {
}

func execute() async throws {
log.verbose("Starting execution")
do {
await taskHelper.didStateMachineConfigured()
let accessToken = try await taskHelper.getAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class AWSAuthClearFederationToIdentityPoolTask: AuthClearFederationToIden
}

public func execute() async throws {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()
try await clearFederationHelper.clearFederation(authStateMachine)
log.verbose("Cleared federation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg
}

func execute() async throws {
log.verbose("Starting execution")
if let validationError = request.hasError() {
throw validationError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask, DefaultLogger {
}

func execute() async throws -> AuthSignInResult {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()

// Check if we have a user pool configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger {
}

func execute() async throws -> AuthSignUpResult {
log.verbose("Starting execution")
try request.hasError()
let userPoolEnvironment = authEnvironment.userPoolEnvironment
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AWSAuthDeleteUserTask: AuthDeleteUserTask, DefaultLogger {
}

func execute() async throws {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()
let accessToken = try await taskHelper.getAccessToken()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class AWSAuthFederateToIdentityPoolTask: AuthFederateToIdentityPoolTask,
}

public func execute() async throws -> FederateToIdentityPoolResult {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()
let state = await authStateMachine.currentState
guard case .configured(let authNState, let authZState) = state else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AWSAuthFetchSessionTask: AuthFetchSessionTask, DefaultLogger {
}

func execute() async throws -> AuthSession {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()
let doesNeedForceRefresh = request.options.forceRefresh
return try await fetchAuthSessionHelper.fetch(authStateMachine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AWSAuthResendSignUpCodeTask: AuthResendSignUpCodeTask, DefaultLogger {
}

func execute() async throws -> AuthCodeDeliveryDetails {
log.verbose("Starting execution")
if let validationError = request.hasError() {
throw validationError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AWSAuthResetPasswordTask: AuthResetPasswordTask, DefaultLogger {
}

func execute() async throws -> AuthResetPasswordResult {
log.verbose("Starting execution")
if let validationError = request.hasError() {
throw validationError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AWSAuthSignInTask: AuthSignInTask, DefaultLogger {
}

func execute() async throws -> AuthSignInResult {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()
// Check if we have a user pool configuration
guard let userPoolConfiguration = authConfiguration.getUserPoolConfiguration() else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AWSAuthSignOutTask: AuthSignOutTask, DefaultLogger {
}

func execute() async -> AuthSignOutResult {
log.verbose("Starting execution")
await taskHelper.didStateMachineConfigured()

guard case .configured(let authNState, _) = await authStateMachine.currentState else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AWSAuthSignUpTask: AuthSignUpTask, DefaultLogger {
}

func execute() async throws -> AuthSignUpResult {
log.verbose("Starting execution")
let userPoolEnvironment = authEnvironment.userPoolEnvironment
try request.hasError()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class AWSAuthWebUISignInTask: AuthWebUISignInTask, DefaultLogger {
}

func execute() async throws -> AuthSignInResult {
log.verbose("Starting execution")
do {
await taskHelper.didStateMachineConfigured()
let result = try await helper.initiateSignIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ protocol AmplifyAuthTaskNonThrowing {

}

extension AmplifyAuthTaskNonThrowing {
extension AmplifyAuthTaskNonThrowing where Self: DefaultLogger {
var value: Success {
get async {
log.info("Starting execution for \(eventName)")
let valueReturned = await execute()
log.info("Successfully completed execution for \(eventName) with result:\n\(valueReturned)")
dispatch(result: valueReturned)
return valueReturned
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,42 @@ public protocol AWSCredentialsProvider {
func fetchAWSCredentials() async throws -> AWSCredentials
}

public protocol AWSTemporaryCredentials: AWSCredentials {

var sessionToken: String { get }
/**
Represents AWS credentials.

var expiration: Date { get }
}
Typically refers to long-term credentials that do not expire unless manually rotated or deactivated.
These credentials are generally associated with an IAM (Identity and Access Management) user and are used to authenticate API requests to AWS services.

- Properties:
- accessKeyId: A unique identifier.
- secretAccessKey: A secret key used to sign requests cryptographically.
*/
public protocol AWSCredentials {

/// A unique identifier.
var accessKeyId: String { get }

/// A secret key used to sign requests cryptographically.
var secretAccessKey: String { get }
}

/**
Represents temporary AWS credentials.

Refers to short-term credentials generated by AWS STS (Security Token Service).
These credentials are used for temporary access, often for applications, temporary roles, federated users, or scenarios requiring limited-time access.

- Inherits: AWSCredentials

- Properties:
- sessionToken: A token that is required when using temporary security credentials to sign requests.
- expiration: The expiration date and time of the temporary credentials.
*/
public protocol AWSTemporaryCredentials: AWSCredentials {

/// A token that is required when using temporary security credentials to sign requests.
var sessionToken: String { get }

/// The expiration date and time of the temporary credentials.
var expiration: Date { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public struct KeychainStore: KeychainStoreBehavior {
log.error("[KeychainStore] Unable to create String from Data retrieved")
throw KeychainStoreError.conversionError("Unable to create String from Data retrieved")
}
log.verbose("[KeychainStore] Successfully retrieved string from the store")
log.verbose("[KeychainStore] Successfully retrieved `String` from the store")
return string

}
Expand Down Expand Up @@ -175,7 +175,7 @@ public struct KeychainStore: KeychainStoreBehavior {
log.error("[KeychainStore] Error updating item to keychain with status=\(updateStatus)")
throw KeychainStoreError.securityError(updateStatus)
}
log.verbose("[KeychainStore] Successfully updated `String` in keychain for key=\(key)")
log.verbose("[KeychainStore] Successfully updated `Data` in keychain for key=\(key)")
#endif
case errSecItemNotFound:
log.verbose("[KeychainStore] Unable to find an existing item, creating new item")
Expand All @@ -188,7 +188,7 @@ public struct KeychainStore: KeychainStoreBehavior {
log.error("[KeychainStore] Error adding item to keychain with status=\(addStatus)")
throw KeychainStoreError.securityError(addStatus)
}
log.verbose("[KeychainStore] Successfully added `String` in keychain for key=\(key)")
log.verbose("[KeychainStore] Successfully added `Data` in keychain for key=\(key)")
default:
log.error("[KeychainStore] Error occurred while retrieving data from keychain when deciding to update or add with status=\(fetchStatus)")
throw KeychainStoreError.securityError(fetchStatus)
Expand All @@ -206,7 +206,7 @@ public struct KeychainStore: KeychainStoreBehavior {

let status = SecItemDelete(query as CFDictionary)
if status != errSecSuccess && status != errSecItemNotFound {
log.error("[KeychainStore] Error removing itms from keychain with status=\(status)")
log.error("[KeychainStore] Error removing items from keychain with status=\(status)")
throw KeychainStoreError.securityError(status)
}
log.verbose("[KeychainStore] Successfully removed item from keychain")
Expand Down
Loading