Skip to content

Commit 638912c

Browse files
committed
network-creation: add createdAt field
1 parent 745cc18 commit 638912c

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Sources/ContainerCommands/Network/NetworkList.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ extension NetworkState {
9090

9191
public struct PrintableNetwork: Codable {
9292
let id: String
93+
let createdAt: Date
9394
let state: String
9495
let config: NetworkConfiguration
9596
let status: NetworkStatus?
9697

9798
public init(_ network: NetworkState) {
9899
self.id = network.id
100+
self.createdAt = network.createdAt
99101
self.state = network.state
100102
switch network {
101103
case .created(let config):

Sources/Services/ContainerNetworkService/NetworkConfiguration.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import ContainerizationError
1818
import ContainerizationExtras
19+
import Foundation
1920

2021
/// Configuration parameters for network creation.
2122
public struct NetworkConfiguration: Codable, Sendable, Identifiable {
@@ -24,6 +25,9 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
2425

2526
/// The network type
2627
public let mode: NetworkMode
28+
29+
/// When the network was created.
30+
public let createdAt: Date
2731

2832
/// The preferred CIDR address for the subnet, if specified
2933
public let subnet: String?
@@ -39,6 +43,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
3943
labels: [String: String] = [:]
4044
) throws {
4145
self.id = id
46+
self.createdAt = Date()
4247
self.mode = mode
4348
self.subnet = subnet
4449
self.labels = labels
@@ -47,6 +52,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
4752

4853
enum CodingKeys: String, CodingKey {
4954
case id
55+
case createdAt
5056
case mode
5157
case subnet
5258
case labels
@@ -58,6 +64,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
5864
let container = try decoder.container(keyedBy: CodingKeys.self)
5965

6066
id = try container.decode(String.self, forKey: .id)
67+
createdAt = try container.decode(Date.self, forKey: .createdAt)
6168
mode = try container.decode(NetworkMode.self, forKey: .mode)
6269
subnet = try container.decodeIfPresent(String.self, forKey: .subnet)
6370
labels = try container.decodeIfPresent([String: String].self, forKey: .labels) ?? [:]

Sources/Services/ContainerNetworkService/NetworkState.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,11 @@ public enum NetworkState: Codable, Sendable {
5353
case .running(let configuration, _): configuration.id
5454
}
5555
}
56+
57+
public var createdAt: Date {
58+
switch self {
59+
case .created(let configuration): configuration.createdAt
60+
case .running(let configuration, _): configuration.createdAt
61+
}
62+
}
5663
}

Tests/CLITests/Utilities/CLITest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CLITest {
4242

4343
struct NetworkInspectOutput: Codable {
4444
let id: String
45+
let createdAt: Date
4546
let state: String
4647
let config: NetworkConfiguration
4748
let status: NetworkStatus?

0 commit comments

Comments
 (0)