Graphley / app · graphley.ai / Sources / AnalyticsKit / Credentials.swift
| 1 | import Foundation |
| 2 | |
| 3 | /// Helpers the apps use to show and save Google keys without seeing the key material. |
| 4 | public enum GoogleServiceAccountKey { |
| 5 | /// The service account's email (client_email) if a key is saved. |
| 6 | public static var savedEmail: String? { |
| 7 | Keychain.get(.googleServiceAccount).flatMap { try? ServiceAccount(json: $0).clientEmail } |
| 8 | } |
| 9 | /// Validates the JSON key file and saves it. Returns the service account's email. |
| 10 | @discardableResult |
| 11 | public static func save(json: String) throws -> String { |
| 12 | let account = try ServiceAccount(json: json) |
| 13 | try Keychain.set(json, for: .googleServiceAccount) |
| 14 | return account.clientEmail |
| 15 | } |
| 16 | public static func remove() { Keychain.remove(.googleServiceAccount) } |
| 17 | } |