Move Context to ConnectionProfile
Fix an id conflict in credentials.
This commit is contained in:
parent
18c7de140e
commit
b5347e04b2
|
@ -409,7 +409,7 @@ extension OrganizerViewController {
|
|||
private func profile(at indexPath: IndexPath) -> ConnectionProfile {
|
||||
let id = sectionProfiles(at: indexPath)[indexPath.row]
|
||||
let section = model.section(for: indexPath.section)
|
||||
let context: ConnectionService.ProfileKey.Context
|
||||
let context: Context
|
||||
switch section {
|
||||
case .providers:
|
||||
context = .provider
|
||||
|
|
|
@ -27,7 +27,15 @@ import Foundation
|
|||
import TunnelKit
|
||||
import NetworkExtension
|
||||
|
||||
enum Context: String, Codable {
|
||||
case provider
|
||||
|
||||
case host
|
||||
}
|
||||
|
||||
protocol ConnectionProfile: class, EndpointDataSource {
|
||||
var context: Context { get }
|
||||
|
||||
var id: String { get }
|
||||
|
||||
var username: String? { get set }
|
||||
|
@ -42,7 +50,7 @@ extension ConnectionProfile {
|
|||
guard let username = username else {
|
||||
return nil
|
||||
}
|
||||
return "\(Bundle.main.bundleIdentifier!).\(id).\(username)"
|
||||
return "\(Bundle.main.bundleIdentifier!).\(context.rawValue).\(id).\(username)"
|
||||
}
|
||||
|
||||
func password(in keychain: Keychain) -> String? {
|
||||
|
|
|
@ -50,12 +50,6 @@ class ConnectionService: Codable {
|
|||
}
|
||||
|
||||
struct ProfileKey: RawRepresentable, Hashable, Codable {
|
||||
enum Context: String {
|
||||
case provider
|
||||
|
||||
case host
|
||||
}
|
||||
|
||||
let context: Context
|
||||
|
||||
let id: String
|
||||
|
@ -66,15 +60,7 @@ class ConnectionService: Codable {
|
|||
}
|
||||
|
||||
init(_ profile: ConnectionProfile) {
|
||||
if let _ = profile as? ProviderConnectionProfile {
|
||||
context = .provider
|
||||
} else if let _ = profile as? HostConnectionProfile {
|
||||
context = .host
|
||||
} else if let placeholder = profile as? PlaceholderConnectionProfile {
|
||||
context = placeholder.context
|
||||
} else {
|
||||
fatalError("Unexpected profile type: \(type(of: profile))")
|
||||
}
|
||||
context = profile.context
|
||||
id = profile.id
|
||||
}
|
||||
|
||||
|
@ -288,7 +274,7 @@ class ConnectionService: Codable {
|
|||
}
|
||||
}
|
||||
|
||||
func profile(withContext context: ProfileKey.Context, id: String) -> ConnectionProfile? {
|
||||
func profile(withContext context: Context, id: String) -> ConnectionProfile? {
|
||||
let key = ProfileKey(context, id)
|
||||
var profile = cache[key]
|
||||
if let _ = profile as? PlaceholderConnectionProfile {
|
||||
|
@ -311,7 +297,7 @@ class ConnectionService: Codable {
|
|||
return profile
|
||||
}
|
||||
|
||||
func ids(forContext context: ProfileKey.Context) -> [String] {
|
||||
func ids(forContext context: Context) -> [String] {
|
||||
return cache.keys.filter { $0.context == context }.map { $0.id }
|
||||
}
|
||||
|
||||
|
@ -485,6 +471,8 @@ class ConnectionService: Codable {
|
|||
}
|
||||
|
||||
private class PlaceholderConnectionProfile: ConnectionProfile {
|
||||
let context: Context
|
||||
|
||||
let id: String
|
||||
|
||||
var username: String?
|
||||
|
@ -507,8 +495,6 @@ private class PlaceholderConnectionProfile: ConnectionProfile {
|
|||
|
||||
var customProtocol: TunnelKitProvider.EndpointProtocol?
|
||||
|
||||
let context: ConnectionService.ProfileKey.Context
|
||||
|
||||
init(_ key: ConnectionService.ProfileKey) {
|
||||
self.context = key.context
|
||||
self.id = key.id
|
||||
|
|
|
@ -42,6 +42,8 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
|
||||
// MARK: ConnectionProfile
|
||||
|
||||
let context: Context = .host
|
||||
|
||||
var id: String {
|
||||
return title
|
||||
}
|
||||
|
|
|
@ -92,6 +92,8 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
|
||||
// MARK: ConnectionProfile
|
||||
|
||||
let context: Context = .provider
|
||||
|
||||
var id: String {
|
||||
return name.rawValue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue