import Foundation /// Helpers the apps use to show and save Google keys without seeing the key material. public enum GoogleServiceAccountKey { /// The service account's email (client_email) if a key is saved. public static var savedEmail: String? { Keychain.get(.googleServiceAccount).flatMap { try? ServiceAccount(json: $0).clientEmail } } /// Validates the JSON key file and saves it. Returns the service account's email. @discardableResult public static func save(json: String) throws -> String { let account = try ServiceAccount(json: json) try Keychain.set(json, for: .googleServiceAccount) return account.clientEmail } public static func remove() { Keychain.remove(.googleServiceAccount) } }