Continue documenting public surface (#25)

Signed-off-by: Danny Canter <danny_canter@apple.com>
This commit is contained in:
Danny Canter
2025-06-06 10:34:19 -04:00
committed by GitHub
parent 46260fd6a6
commit fc4a124173
32 changed files with 215 additions and 33 deletions
@@ -34,6 +34,8 @@ public struct BasicAuthentication: Authentication {
self.password = password
}
/// Get a token using the provided username and password. This will be a
/// base64 encoded string of the username and password delimited by a colon.
public func token() async throws -> String {
let credentials = "\(username):\(password)"
if let authenticationData = credentials.data(using: .utf8)?.base64EncodedString() {
@@ -42,6 +44,7 @@ public struct BasicAuthentication: Authentication {
throw Error.invalidCredentials
}
/// `BasicAuthentication` errors.
public enum Error: Swift.Error {
case invalidCredentials
}
@@ -90,6 +90,7 @@ public struct KeychainHelper: Sendable {
}
extension KeychainHelper {
/// `KeychainHelper` errors.
public enum Error: Swift.Error {
case keyNotFound
case invalidInput
@@ -18,9 +18,11 @@
import NIOHTTP1
extension RegistryClient {
/// `RegistryClient` errors.
public enum Error: Swift.Error, CustomStringConvertible {
case invalidStatus(url: String, HTTPResponseStatus)
/// Description of the errors.
public var description: String {
switch self {
case .invalidStatus(let u, let response):
@@ -27,10 +27,15 @@ import NIOHTTP1
import Network
#endif
/// Data used to control retry behavior for `RegistryClient`.
public struct RetryOptions: Sendable {
let maxRetries: Int
let retryInterval: UInt64
let shouldRetry: (@Sendable (HTTPClientResponse) -> Bool)?
/// The maximum number of retries to attempt before failing.
public var maxRetries: Int
/// The retry interval in nanoseconds.
public var retryInterval: UInt64
/// A provided closure to handle if a given HTTP response should be
/// retried.
public var shouldRetry: (@Sendable (HTTPClientResponse) -> Bool)?
public init(maxRetries: Int, retryInterval: UInt64, shouldRetry: (@Sendable (HTTPClientResponse) -> Bool)? = nil) {
self.maxRetries = maxRetries
@@ -39,6 +44,7 @@ public struct RetryOptions: Sendable {
}
}
/// A client for interacting with OCI compliant container registries.
public final class RegistryClient: ContentClient {
private static let defaultRetryOptions = RetryOptions(
maxRetries: 3,