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",
|
||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||
"state" : {
|
||||
"revision" : "ff9a47ee0aad9a2a2947f5ce23346ced93d3d3d2"
|
||||
"revision" : "f4786bf573ce30f85107b422590d7633d17fb87a"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
// .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(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"),
|
||||
|
|
|
@ -35,6 +35,6 @@ final class CDProviderV3: NSManagedObject {
|
|||
@NSManaged var providerId: String?
|
||||
@NSManaged var fullName: String?
|
||||
@NSManaged var supportedConfigurationIds: String?
|
||||
@NSManaged var encodedConfigurations: Data? // [String: ProviderMetadata.Configuration]
|
||||
@NSManaged var encodedCustomizations: Data? // [String: ProviderMetadata.Customization]
|
||||
@NSManaged var lastUpdate: Date?
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ struct CoreDataMapper {
|
|||
entity.providerId = metadata.id.rawValue
|
||||
entity.fullName = metadata.description
|
||||
entity.lastUpdate = lastUpdate
|
||||
entity.supportedConfigurationIds = metadata.configurations.map(\.key).joined(separator: ",")
|
||||
entity.encodedConfigurations = try JSONEncoder().encode(metadata.configurations)
|
||||
entity.supportedConfigurationIds = metadata.customizations.map(\.key).joined(separator: ",")
|
||||
entity.encodedCustomizations = try JSONEncoder().encode(metadata.customizations)
|
||||
return entity
|
||||
}
|
||||
|
||||
|
|
|
@ -32,24 +32,24 @@ struct DomainMapper {
|
|||
guard let id = entity.providerId, let fullName = entity.fullName else {
|
||||
return nil
|
||||
}
|
||||
let configurations: [String: ProviderMetadata.Configuration]
|
||||
if let encodedConfigurations = entity.encodedConfigurations {
|
||||
let customizations: [String: ProviderMetadata.Customization]
|
||||
if let encodedCustomizations = entity.encodedCustomizations {
|
||||
do {
|
||||
configurations = try JSONDecoder().decode([String: ProviderMetadata.Configuration].self, from: encodedConfigurations)
|
||||
customizations = try JSONDecoder().decode([String: ProviderMetadata.Customization].self, from: encodedCustomizations)
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
} else if let supportedConfigurationIds = entity.supportedConfigurationIds?.components(separatedBy: ",") {
|
||||
configurations = supportedConfigurationIds.reduce(into: [:]) {
|
||||
customizations = supportedConfigurationIds.reduce(into: [:]) {
|
||||
$0[$1] = .init()
|
||||
}
|
||||
} else {
|
||||
configurations = [:]
|
||||
customizations = [:]
|
||||
}
|
||||
return ProviderMetadata(
|
||||
id,
|
||||
description: fullName,
|
||||
configurations: configurations
|
||||
customizations: customizations
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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="">
|
||||
<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="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<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]? {
|
||||
do {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
|
|
|
@ -59,7 +59,7 @@ public struct OpenVPNCredentialsView: View {
|
|||
private var builder = OpenVPN.Credentials.Builder()
|
||||
|
||||
@State
|
||||
private var providerConfiguration: OpenVPN.Credentials.ProviderConfiguration?
|
||||
private var providerCustomization: OpenVPN.ProviderCustomization?
|
||||
|
||||
@State
|
||||
private var paywallReason: PaywallReason?
|
||||
|
@ -148,7 +148,7 @@ private extension OpenVPNCredentialsView {
|
|||
|
||||
@ViewBuilder
|
||||
var guidanceSection: some View {
|
||||
if let url = providerConfiguration?.url {
|
||||
if let url = providerCustomization?.credentials.url {
|
||||
Link(Strings.Modules.Openvpn.Credentials.Guidance.link, destination: url)
|
||||
}
|
||||
}
|
||||
|
@ -157,12 +157,12 @@ private extension OpenVPNCredentialsView {
|
|||
if isAuthenticating {
|
||||
return builder.otpMethod.localizedDescription(style: .approachDescription)
|
||||
.nilIfEmpty
|
||||
} else if let providerConfiguration {
|
||||
switch providerConfiguration.purpose {
|
||||
case .web:
|
||||
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
||||
} else if providerId != nil {
|
||||
switch providerCustomization?.credentials.purpose {
|
||||
case .specific:
|
||||
return Strings.Modules.Openvpn.Credentials.Guidance.specific
|
||||
default:
|
||||
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -215,12 +215,12 @@ private extension OpenVPNCredentialsView {
|
|||
}
|
||||
|
||||
var ignoresPassword: Bool {
|
||||
providerConfiguration?.options?.contains(.noPassword) ?? false
|
||||
providerCustomization?.credentials.options?.contains(.noPassword) ?? false
|
||||
}
|
||||
|
||||
func onLoad() {
|
||||
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()
|
||||
if ignoresPassword {
|
||||
|
|
Loading…
Reference in New Issue