Add method to rename immutable profile

This commit is contained in:
Davide De Rosa 2018-11-02 14:44:29 +01:00
parent 3f1e98f8ac
commit aa2b6bafaf
4 changed files with 18 additions and 1 deletions

View File

@ -43,6 +43,8 @@ protocol ConnectionProfile: class, EndpointDataSource {
var requiresCredentials: Bool { get }
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration
func with(newId: String) -> ConnectionProfile
}
extension ConnectionProfile {

View File

@ -489,7 +489,7 @@ private class PlaceholderConnectionProfile: ConnectionProfile {
let id: String
var username: String?
var username: String? = nil
var requiresCredentials: Bool = false
@ -497,6 +497,10 @@ private class PlaceholderConnectionProfile: ConnectionProfile {
fatalError("Generating configuration from a PlaceholderConnectionProfile")
}
func with(newId: String) -> ConnectionProfile {
return PlaceholderConnectionProfile(ConnectionService.ProfileKey(context, newId))
}
var mainAddress: String = ""
var addresses: [String] = []

View File

@ -65,6 +65,13 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
return builder.build()
}
func with(newId: String) -> ConnectionProfile {
let profile = HostConnectionProfile(title: newId, hostname: hostname)
profile.username = username
profile.parameters = parameters
return profile
}
}
extension HostConnectionProfile {

View File

@ -139,6 +139,10 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
}
return builder.build()
}
func with(newId: String) -> ConnectionProfile {
fatalError("Cannot rename a ProviderConnectionProfile")
}
}
extension ProviderConnectionProfile {