Refactor with provider customizations (#976)
Update library with new API.
This commit is contained in:
parent
2d93fa64c6
commit
0aaef04a25
|
@ -41,7 +41,7 @@
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "ff9a47ee0aad9a2a2947f5ce23346ced93d3d3d2"
|
"revision" : "f4786bf573ce30f85107b422590d7633d17fb87a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "ff9a47ee0aad9a2a2947f5ce23346ced93d3d3d2"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "f4786bf573ce30f85107b422590d7633d17fb87a"),
|
||||||
// .package(path: "../../passepartoutkit-source"),
|
// .package(path: "../../passepartoutkit-source"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
||||||
|
|
|
@ -35,6 +35,6 @@ final class CDProviderV3: NSManagedObject {
|
||||||
@NSManaged var providerId: String?
|
@NSManaged var providerId: String?
|
||||||
@NSManaged var fullName: String?
|
@NSManaged var fullName: String?
|
||||||
@NSManaged var supportedConfigurationIds: String?
|
@NSManaged var supportedConfigurationIds: String?
|
||||||
@NSManaged var encodedConfigurations: Data? // [String: ProviderMetadata.Configuration]
|
@NSManaged var encodedCustomizations: Data? // [String: ProviderMetadata.Customization]
|
||||||
@NSManaged var lastUpdate: Date?
|
@NSManaged var lastUpdate: Date?
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ struct CoreDataMapper {
|
||||||
entity.providerId = metadata.id.rawValue
|
entity.providerId = metadata.id.rawValue
|
||||||
entity.fullName = metadata.description
|
entity.fullName = metadata.description
|
||||||
entity.lastUpdate = lastUpdate
|
entity.lastUpdate = lastUpdate
|
||||||
entity.supportedConfigurationIds = metadata.configurations.map(\.key).joined(separator: ",")
|
entity.supportedConfigurationIds = metadata.customizations.map(\.key).joined(separator: ",")
|
||||||
entity.encodedConfigurations = try JSONEncoder().encode(metadata.configurations)
|
entity.encodedCustomizations = try JSONEncoder().encode(metadata.customizations)
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,24 +32,24 @@ struct DomainMapper {
|
||||||
guard let id = entity.providerId, let fullName = entity.fullName else {
|
guard let id = entity.providerId, let fullName = entity.fullName else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let configurations: [String: ProviderMetadata.Configuration]
|
let customizations: [String: ProviderMetadata.Customization]
|
||||||
if let encodedConfigurations = entity.encodedConfigurations {
|
if let encodedCustomizations = entity.encodedCustomizations {
|
||||||
do {
|
do {
|
||||||
configurations = try JSONDecoder().decode([String: ProviderMetadata.Configuration].self, from: encodedConfigurations)
|
customizations = try JSONDecoder().decode([String: ProviderMetadata.Customization].self, from: encodedCustomizations)
|
||||||
} catch {
|
} catch {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else if let supportedConfigurationIds = entity.supportedConfigurationIds?.components(separatedBy: ",") {
|
} else if let supportedConfigurationIds = entity.supportedConfigurationIds?.components(separatedBy: ",") {
|
||||||
configurations = supportedConfigurationIds.reduce(into: [:]) {
|
customizations = supportedConfigurationIds.reduce(into: [:]) {
|
||||||
$0[$1] = .init()
|
$0[$1] = .init()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configurations = [:]
|
customizations = [:]
|
||||||
}
|
}
|
||||||
return ProviderMetadata(
|
return ProviderMetadata(
|
||||||
id,
|
id,
|
||||||
description: fullName,
|
description: fullName,
|
||||||
configurations: configurations
|
customizations: customizations
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="23H222" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="23H222" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
|
||||||
<entity name="CDProviderV3" representedClassName="CDProviderV3" syncable="YES">
|
<entity name="CDProviderV3" representedClassName="CDProviderV3" syncable="YES">
|
||||||
<attribute name="encodedConfigurations" optional="YES" attributeType="Binary"/>
|
<attribute name="encodedCustomizations" optional="YES" attributeType="Binary"/>
|
||||||
<attribute name="fullName" optional="YES" attributeType="String"/>
|
<attribute name="fullName" optional="YES" attributeType="String"/>
|
||||||
<attribute name="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
<attribute name="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||||
<attribute name="providerId" optional="YES" attributeType="String"/>
|
<attribute name="providerId" optional="YES" attributeType="String"/>
|
||||||
|
|
|
@ -66,9 +66,9 @@ extension ProfileAttributes: CustomDebugStringConvertible {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UserInfoTransformable
|
// MARK: - UserInfoCodable
|
||||||
|
|
||||||
extension ProfileAttributes: UserInfoTransformable {
|
extension ProfileAttributes: UserInfoCodable {
|
||||||
public var userInfo: [String: AnyHashable]? {
|
public var userInfo: [String: AnyHashable]? {
|
||||||
do {
|
do {
|
||||||
let data = try JSONEncoder().encode(self)
|
let data = try JSONEncoder().encode(self)
|
||||||
|
|
|
@ -59,7 +59,7 @@ public struct OpenVPNCredentialsView: View {
|
||||||
private var builder = OpenVPN.Credentials.Builder()
|
private var builder = OpenVPN.Credentials.Builder()
|
||||||
|
|
||||||
@State
|
@State
|
||||||
private var providerConfiguration: OpenVPN.Credentials.ProviderConfiguration?
|
private var providerCustomization: OpenVPN.ProviderCustomization?
|
||||||
|
|
||||||
@State
|
@State
|
||||||
private var paywallReason: PaywallReason?
|
private var paywallReason: PaywallReason?
|
||||||
|
@ -148,7 +148,7 @@ private extension OpenVPNCredentialsView {
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var guidanceSection: some View {
|
var guidanceSection: some View {
|
||||||
if let url = providerConfiguration?.url {
|
if let url = providerCustomization?.credentials.url {
|
||||||
Link(Strings.Modules.Openvpn.Credentials.Guidance.link, destination: url)
|
Link(Strings.Modules.Openvpn.Credentials.Guidance.link, destination: url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,12 +157,12 @@ private extension OpenVPNCredentialsView {
|
||||||
if isAuthenticating {
|
if isAuthenticating {
|
||||||
return builder.otpMethod.localizedDescription(style: .approachDescription)
|
return builder.otpMethod.localizedDescription(style: .approachDescription)
|
||||||
.nilIfEmpty
|
.nilIfEmpty
|
||||||
} else if let providerConfiguration {
|
} else if providerId != nil {
|
||||||
switch providerConfiguration.purpose {
|
switch providerCustomization?.credentials.purpose {
|
||||||
case .web:
|
|
||||||
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
|
||||||
case .specific:
|
case .specific:
|
||||||
return Strings.Modules.Openvpn.Credentials.Guidance.specific
|
return Strings.Modules.Openvpn.Credentials.Guidance.specific
|
||||||
|
default:
|
||||||
|
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -215,12 +215,12 @@ private extension OpenVPNCredentialsView {
|
||||||
}
|
}
|
||||||
|
|
||||||
var ignoresPassword: Bool {
|
var ignoresPassword: Bool {
|
||||||
providerConfiguration?.options?.contains(.noPassword) ?? false
|
providerCustomization?.credentials.options?.contains(.noPassword) ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
func onLoad() {
|
func onLoad() {
|
||||||
if let providerId, let metadata = providerManager.provider(withId: providerId) {
|
if let providerId, let metadata = providerManager.provider(withId: providerId) {
|
||||||
providerConfiguration = OpenVPN.Credentials.configuration(forProvider: metadata)
|
providerCustomization = metadata.customization(for: OpenVPN.Configuration.self)
|
||||||
}
|
}
|
||||||
builder = credentials?.builder() ?? OpenVPN.Credentials.Builder()
|
builder = credentials?.builder() ?? OpenVPN.Credentials.Builder()
|
||||||
if ignoresPassword {
|
if ignoresPassword {
|
||||||
|
|
Loading…
Reference in New Issue