-
Notifications
You must be signed in to change notification settings - Fork 229
feat: add definitions for foundational apis #4135
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
Merged
+369
−17
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| import Foundation | ||
|
|
||
| public protocol FoundationAWSCredentials { | ||
| var accessKeyId: String { get } | ||
| var secretAccessKey: String { get } | ||
| } | ||
|
|
||
| public protocol FoundationAWSTemporaryCredentials: FoundationAWSCredentials { | ||
| var sessionToken: String { get } | ||
| var expiration: Date { get } | ||
| } | ||
|
|
||
| public protocol FoundationAWSCredentialsProvider { | ||
| func resolve() async throws -> FoundationAWSCredentials | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| import Foundation | ||
|
|
||
| public typealias FoundationErrorDescription = String | ||
| public typealias FoundationRecoverySuggestion = String | ||
|
|
||
| public struct FoundationAmplifyException: Error { | ||
| var errorDescription: FoundationErrorDescription | ||
| var recoverySuggestion: FoundationRecoverySuggestion | ||
| var underlyingError: Error? | ||
|
|
||
| init( | ||
| errorDescription: FoundationErrorDescription, | ||
| recoverySuggestion: FoundationRecoverySuggestion, | ||
| error: Error | ||
| ) { | ||
| self.errorDescription = errorDescription | ||
| self.recoverySuggestion = recoverySuggestion | ||
| self.underlyingError = error | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| import os | ||
| import Foundation | ||
|
|
||
| public final class FoundationAmplifyLogger: FoundationLogger { | ||
| static let lock: NSLocking = NSLock() | ||
| static var _logLevel = FoundationLogLevel.error | ||
|
|
||
| private let osLog: OSLog | ||
| private let subsystem: String | ||
|
|
||
| public init(namespace: String) { | ||
| self.subsystem = Bundle.main.bundleIdentifier ?? "com.amazonaws.amplify.logger" | ||
| self.namespace = namespace | ||
| self.osLog = OSLog(subsystem: subsystem, category: namespace) | ||
| } | ||
|
|
||
| public var namespace: String | ||
|
|
||
| public var logLevel: FoundationLogLevel { | ||
| get { | ||
| FoundationAmplifyLogger.lock.lock() | ||
| defer { | ||
| FoundationAmplifyLogger.lock.unlock() | ||
| } | ||
|
|
||
| return FoundationAmplifyLogger._logLevel | ||
| } | ||
| set { | ||
| FoundationAmplifyLogger.lock.lock() | ||
| defer { | ||
| FoundationAmplifyLogger.lock.unlock() | ||
| } | ||
|
|
||
| FoundationAmplifyLogger._logLevel = newValue | ||
| } | ||
| } | ||
|
|
||
| public func error(_ message: @autoclosure () -> String) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.error.rawValue else { return } | ||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.error, | ||
| message() | ||
| ) | ||
| } | ||
|
|
||
| public func error(_ error: @autoclosure () -> Error) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.error.rawValue else { return } | ||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.error, | ||
| error().localizedDescription | ||
| ) | ||
| } | ||
|
|
||
| public func warn(_ message: @autoclosure () -> String) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.warn.rawValue else { return } | ||
|
|
||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.info, | ||
| message() | ||
| ) | ||
| } | ||
|
|
||
| public func info(_ message: @autoclosure () -> String) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.info.rawValue else { return } | ||
|
|
||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.info, | ||
| message() | ||
| ) | ||
| } | ||
|
|
||
| public func debug(_ message: @autoclosure () -> String) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.debug.rawValue else { return } | ||
|
|
||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.debug, | ||
| message() | ||
| ) | ||
| } | ||
|
|
||
| public func verbose(_ message: @autoclosure () -> String) { | ||
| guard logLevel.rawValue >= FoundationLogLevel.verbose.rawValue else { return } | ||
|
|
||
| os_log( | ||
| "%@", | ||
| log: osLog, | ||
| type: OSLogType.debug, | ||
| message() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| public final class FoundationAmplifyLoggerProvider: FoundationLoggerProvider { | ||
| public func resolve(forNamespace namespace: String) -> any FoundationLogger { | ||
| FoundationAmplifyLogger(namespace: namespace) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| public protocol FoundationLogger { | ||
| /// namespace | ||
| var namespace: String {get set} | ||
|
|
||
| /// The log level of the logger. | ||
| var logLevel: FoundationLogLevel { get set } | ||
|
|
||
| /// Logs a message at `error` level | ||
| func error(_ message: @autoclosure () -> String) | ||
|
|
||
| /// Logs the error at `error` level | ||
| func error(_ error: @autoclosure () -> Error) | ||
|
|
||
| /// Logs a message at `warn` level | ||
| func warn(_ message: @autoclosure () -> String) | ||
|
|
||
| /// Logs a message at `info` level | ||
| func info(_ message: @autoclosure () -> String) | ||
|
|
||
| /// Logs a message at `debug` level | ||
| func debug(_ message: @autoclosure () -> String) | ||
|
|
||
| /// Logs a message at `verbose` level | ||
| func verbose(_ message: @autoclosure () -> String) | ||
| } | ||
|
|
||
| public protocol FoundationLoggerProvider { | ||
| func resolve(forNamespace namespace: String) -> FoundationLogger | ||
| } | ||
|
|
||
| /// An enumeration of the different levels of logging. | ||
| /// The levels are progressive, with lower-value items being lower priority | ||
| /// than higher-value items. For example, `info` is lower priority than `warn` | ||
| /// or `error`. | ||
| public enum FoundationLogLevel: Int { | ||
| case error | ||
| case warn | ||
| case info | ||
| case debug | ||
| case verbose | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.