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
73
74
75
76
77
78
79
80
81
82
83
84
|
//
// RESTProxyFactory.swift
// MullvadREST
//
// Created by pronebird on 19/04/2022.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
import MullvadRustRuntime
public protocol ProxyFactoryProtocol {
var configuration: REST.AuthProxyConfiguration { get }
func createAPIProxy() -> APIQuerying
func createAccountsProxy() -> RESTAccountHandling
func createDevicesProxy() -> DeviceHandling
static func makeProxyFactory(
transportProvider: RESTTransportProvider,
apiTransportProvider: APITransportProviderProtocol,
addressCache: REST.AddressCache
) -> ProxyFactoryProtocol
}
extension REST {
public final class ProxyFactory: ProxyFactoryProtocol {
public var configuration: AuthProxyConfiguration
public static func makeProxyFactory(
transportProvider: any RESTTransportProvider,
apiTransportProvider: any APITransportProviderProtocol,
addressCache: REST.AddressCache
) -> any ProxyFactoryProtocol {
let basicConfiguration = REST.ProxyConfiguration(
transportProvider: transportProvider,
apiTransportProvider: apiTransportProvider,
addressCacheStore: addressCache
)
let authenticationProxy = REST.AuthenticationProxy(
configuration: basicConfiguration
)
let accessTokenManager = REST.AccessTokenManager(
authenticationProxy: authenticationProxy
)
let authConfiguration = REST.AuthProxyConfiguration(
proxyConfiguration: basicConfiguration,
accessTokenManager: accessTokenManager
)
return ProxyFactory(configuration: authConfiguration)
}
public init(configuration: AuthProxyConfiguration) {
self.configuration = configuration
}
public func createAPIProxy() -> APIQuerying {
MullvadAPIProxy(
transportProvider: configuration.apiTransportProvider,
dispatchQueue: DispatchQueue(label: "MullvadAPIProxy.dispatchQueue"),
responseDecoder: Coding.makeJSONDecoder()
)
}
public func createAccountsProxy() -> RESTAccountHandling {
MullvadAccountProxy(
transportProvider: configuration.apiTransportProvider,
dispatchQueue: DispatchQueue(label: "MullvadAccountProxy.dispatchQueue"),
responseDecoder: Coding.makeJSONDecoder()
)
}
public func createDevicesProxy() -> DeviceHandling {
MullvadDeviceProxy(
transportProvider: configuration.apiTransportProvider,
dispatchQueue: DispatchQueue(label: "MullvadDeviceProxy.dispatchQueue"),
responseDecoder: Coding.makeJSONDecoder()
)
}
}
}
|