-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathBuildSecrets.swift
More file actions
72 lines (60 loc) · 1.86 KB
/
Copy pathBuildSecrets.swift
File metadata and controls
72 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public struct BuildSecrets: Sendable {
public struct OAuth: Sendable {
public let client: String
public let secret: String
public init(client: String, secret: String) {
self.client = client
self.secret = secret
}
}
public struct Zendesk: Sendable {
public let appId: String
public let url: String
public let clientId: String
public init(appId: String, url: String, clientId: String) {
self.appId = appId
self.url = url
self.clientId = clientId
}
}
public let oauth: OAuth
public let zendesk: Zendesk
public let encryptedLogsKey: String
public let debuggingKey: String
public init(
oauth: OAuth,
zendesk: Zendesk,
encryptedLogsKey: String,
debuggingKey: String
) {
self.oauth = oauth
self.zendesk = zendesk
self.encryptedLogsKey = encryptedLogsKey
self.debuggingKey = debuggingKey
}
}
extension BuildSecrets {
public static let dummy = BuildSecrets(
oauth: .init(client: "", secret: ""),
zendesk: .init(appId: "", url: "", clientId: ""),
encryptedLogsKey: "",
debuggingKey: ""
)
}
extension BuildSecrets {
nonisolated(unsafe) static var configuredSecrets: BuildSecrets?
static var current: BuildSecrets {
switch BuildSettingsEnvironment.current {
case .preview:
return .dummy
case .test:
// TODO: Should we crash if a secret is accessed from the tests to prevent under-the-hood access and favor injection?
return .dummy
case .live:
guard let secrets = configuredSecrets else {
fatalError("Attempted to access BuildSettings before configuring secrets.")
}
return secrets
}
}
}