Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ContainerizationError
import ContainerizationExtras
import Foundation

/// Configuration parameters for network creation.
public struct NetworkConfiguration: Codable, Sendable, Identifiable {
Expand All @@ -25,6 +26,9 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
/// The network type
public let mode: NetworkMode

/// When the network was created.
public let creationDate: Date

/// The preferred CIDR address for the subnet, if specified
public let subnet: String?

Expand All @@ -39,6 +43,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
labels: [String: String] = [:]
) throws {
self.id = id
self.creationDate = Date()
self.mode = mode
self.subnet = subnet
self.labels = labels
Expand All @@ -47,6 +52,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {

enum CodingKeys: String, CodingKey {
case id
case creationDate
case mode
case subnet
case labels
Expand All @@ -58,6 +64,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable {
let container = try decoder.container(keyedBy: CodingKeys.self)

id = try container.decode(String.self, forKey: .id)
creationDate = try container.decodeIfPresent(Date.self, forKey: .creationDate) ?? Date(timeIntervalSince1970: 0)
mode = try container.decode(NetworkMode.self, forKey: .mode)
subnet = try container.decodeIfPresent(String.self, forKey: .subnet)
labels = try container.decodeIfPresent([String: String].self, forKey: .labels) ?? [:]
Expand Down
7 changes: 7 additions & 0 deletions Sources/Services/ContainerNetworkService/NetworkState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public enum NetworkState: Codable, Sendable {
case .running(let configuration, _): configuration.id
}
}

public var creationDate: Date {
switch self {
case .created(let configuration): configuration.creationDate
case .running(let configuration, _): configuration.creationDate
}
}
}