DnsUpdater/Sources/App/Model/DnsConfiguration.swift

67 lines
1.5 KiB
Swift
Raw Permalink Normal View History

2024-11-15 10:46:29 +01:00
import Foundation
struct DnsConfiguration: Codable, Equatable {
let domainConfigFilePath: String
let logFilePath: String
let lastUpdateFilePath: String
let logLevel: Log.Level
}
struct DomainConfiguration {
let domains: Set<String>
let password: String
var useIPv4: Bool = true
var useIPv6: Bool = true
}
extension DomainConfiguration: Equatable {
}
extension DomainConfiguration: Hashable {
}
extension DomainConfiguration: Encodable {
enum CodingKeys: String, CodingKey {
case domains
case password
case useIPv4
case useIPv6
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(domains, forKey: .domains)
try container.encode(password, forKey: .password)
if !useIPv4 {
try container.encode(false, forKey: .useIPv4)
}
if !useIPv6 {
try container.encode(false, forKey: .useIPv6)
}
}
}
extension DomainConfiguration: Decodable {
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.domains = try container.decode(Set<String>.self, forKey: .domains)
self.password = try container.decode(String.self, forKey: .password)
self.useIPv4 = try container.decodeIfPresent(Bool.self, forKey: .useIPv4) ?? true
self.useIPv6 = try container.decodeIfPresent(Bool.self, forKey: .useIPv6) ?? true
}
}