import Foundation import SnapshotKit /// The stored secrets can't be read unattended, and what would fix that. /// /// Both faults come back from the Keychain as one status and are found the same /// way — a read that refuses to raise a dialog — but the dialog that fixes them /// asks different things: Always Allow for a build that isn't on the access /// list, the login password for a locked keychain. The remedy says which, so /// the button offering it can too. public struct KeychainProblem: Equatable, Sendable { public enum Remedy: Equatable, Sendable { /// The Always Allow prompt, which adds this build to the item's access /// list for good. case authorise /// The unlock prompt for the login keychain. case unlock } public var message: String public var remedy: Remedy init(_ error: any Error) { switch error as? KeychainError { case .needsAuthorisation(_, interactionAllowed: false): // The error's own words are for a run that has just failed; here // nothing has run, and the fix is the button beside this. message = "This build of Snapshot isn't on the repository password's access list — " + "a rebuilt app never is. Scheduled backups will fail until it's authorised." remedy = .authorise case .keychainLocked: message = "\(error)" remedy = .unlock default: message = "\(error)" remedy = .authorise } } }