-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathProblemReportInteractor.swift
62 lines (52 loc) · 1.79 KB
/
ProblemReportInteractor.swift
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
//
// ProblemReportInteractor.swift
// MullvadVPN
//
// Created by pronebird on 25/10/2022.
// Copyright © 2022 Mullvad VPN AB. All rights reserved.
//
import Foundation
import MullvadREST
import MullvadTypes
import Operations
final class ProblemReportInteractor {
private let apiProxy: APIQuerying
private let tunnelManager: TunnelManager
private lazy var consolidatedLog: ConsolidatedApplicationLog = {
let securityGroupIdentifier = ApplicationConfiguration.securityGroupIdentifier
let redactStrings = [tunnelManager.deviceState.accountData?.number].compactMap { $0 }
let report = ConsolidatedApplicationLog(
redactCustomStrings: redactStrings,
redactContainerPathsForSecurityGroupIdentifiers: [securityGroupIdentifier]
)
let logFileURLs = ApplicationTarget.allCases.flatMap { ApplicationConfiguration.logFileURLs(for: $0) }
report.addLogFiles(fileURLs: logFileURLs)
return report
}()
init(apiProxy: APIQuerying, tunnelManager: TunnelManager) {
self.apiProxy = apiProxy
self.tunnelManager = tunnelManager
}
func sendReport(
email: String,
message: String,
completion: @escaping (Result<Void, Error>) -> Void
) -> Cancellable {
let request = REST.ProblemReportRequest(
address: email,
message: message,
log: consolidatedLog.string,
metadata: consolidatedLog.metadata.reduce(into: [:]) { output, entry in
output[entry.key.rawValue] = entry.value
}
)
return apiProxy.sendProblemReport(
request,
retryStrategy: .default,
completionHandler: completion
)
}
var reportString: String {
consolidatedLog.string
}
}