mirror of
https://github.com/apple/container.git
synced 2026-09-26 00:51:12 -04:00
Update to containerization 0.20.0. (#1027)
- Use MACAddress for Attachment and CZ interfaces. - Move data validation closer to API surface.
This commit is contained in:
@@ -27,9 +27,9 @@ public struct Attachment: Codable, Sendable {
|
||||
/// The IPv4 gateway address.
|
||||
public let ipv4Gateway: IPv4Address
|
||||
/// The MAC address associated with the attachment (optional).
|
||||
public let macAddress: String?
|
||||
public let macAddress: MACAddress?
|
||||
|
||||
public init(network: String, hostname: String, ipv4Address: CIDRv4, ipv4Gateway: IPv4Address, macAddress: String? = nil) {
|
||||
public init(network: String, hostname: String, ipv4Address: CIDRv4, ipv4Gateway: IPv4Address, macAddress: MACAddress? = nil) {
|
||||
self.network = network
|
||||
self.hostname = hostname
|
||||
self.ipv4Address = ipv4Address
|
||||
@@ -44,28 +44,4 @@ public struct Attachment: Codable, Sendable {
|
||||
case ipv4Gateway
|
||||
case macAddress
|
||||
}
|
||||
|
||||
/// Create an attachment from the supplied Decoder.
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
network = try container.decode(String.self, forKey: .network)
|
||||
hostname = try container.decode(String.self, forKey: .hostname)
|
||||
let addressText = try container.decode(String.self, forKey: .ipv4Address)
|
||||
ipv4Address = try CIDRv4(addressText)
|
||||
let gatewayText = try container.decode(String.self, forKey: .ipv4Gateway)
|
||||
ipv4Gateway = try IPv4Address(gatewayText)
|
||||
macAddress = try container.decodeIfPresent(String.self, forKey: .macAddress)
|
||||
}
|
||||
|
||||
/// Encode the attachment to the supplied Encoder.
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encode(network, forKey: .network)
|
||||
try container.encode(hostname, forKey: .hostname)
|
||||
try container.encode(ipv4Address.description, forKey: .ipv4Address)
|
||||
try container.encode(ipv4Gateway.description, forKey: .ipv4Gateway)
|
||||
try container.encodeIfPresent(macAddress, forKey: .macAddress)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ public actor NetworkService: Sendable {
|
||||
}
|
||||
|
||||
let hostname = try message.hostname()
|
||||
let macAddress = message.string(key: NetworkKeys.macAddress.rawValue)
|
||||
let macAddress = try message.string(key: NetworkKeys.macAddress.rawValue)
|
||||
.map { try MACAddress($0) }
|
||||
let index = try await allocator.allocate(hostname: hostname)
|
||||
let subnet = status.ipv4Subnet
|
||||
let ip = IPv4Address(index)
|
||||
@@ -78,7 +79,7 @@ public actor NetworkService: Sendable {
|
||||
"hostname": "\(hostname)",
|
||||
"ipv4Address": "\(attachment.ipv4Address)",
|
||||
"ipv4Gateway": "\(attachment.ipv4Gateway)",
|
||||
"macAddress": "\(macAddress ?? "auto")",
|
||||
"macAddress": "\(macAddress?.description ?? "unspecified")",
|
||||
])
|
||||
let reply = message.reply()
|
||||
try reply.setAttachment(attachment)
|
||||
|
||||
Reference in New Issue
Block a user