Branchwell

Graphley / app · graphley.ai / Sources / AnalyticsKit / Credentials.swift

Raw 763 B on d69ca9c4c8ff088be085e80dbb7478e9463bddf8
1import Foundation
2
3/// Helpers the apps use to show and save Google keys without seeing the key material.
4public 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}