diff --git a/Passepartout/Sources/Model/ConnectionProfile.swift b/Passepartout/Sources/Model/ConnectionProfile.swift index c4978ea8..313390ef 100644 --- a/Passepartout/Sources/Model/ConnectionProfile.swift +++ b/Passepartout/Sources/Model/ConnectionProfile.swift @@ -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 { diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 2f209b53..dde29016 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -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] = [] diff --git a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift index 591cdebe..154d014f 100644 --- a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift @@ -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 { diff --git a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift index 7343571d..fa577cc7 100644 --- a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift @@ -139,6 +139,10 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { } return builder.build() } + + func with(newId: String) -> ConnectionProfile { + fatalError("Cannot rename a ProviderConnectionProfile") + } } extension ProviderConnectionProfile {