// // Networks. // const { Element } = require("./Element"); const ROLE_LABEL = "com.apple.container.resource.role"; class NetworkModel extends Element { constructor(json) { let configuration = (json && json.configuration) || {}; let status = (json && json.status) || {}; super(`network:${configuration.name || json.id}`); this.name = configuration.name || json.id; this.mode = configuration.mode || ""; this.plugin = configuration.plugin || ""; this.created = configuration.creationDate || null; this.labels = configuration.labels || {}; this.subnet = status.ipv4Subnet || ""; this.gateway = status.ipv4Gateway || ""; this.subnet6 = status.ipv6Subnet || ""; } get revision() { return `${this.subnet}:${this.gateway}:${this.mode}`; } get builtin() { return this.labels[ROLE_LABEL] === "builtin"; } get tooltip() { let lines = [`Network:\t${this.name}`]; if (this.mode) { lines.push(`Mode:\t${this.mode}`); } if (this.subnet) { lines.push(`Subnet:\t${this.subnet}`); } if (this.gateway) { lines.push(`Gateway:\t${this.gateway}`); } if (this.plugin) { lines.push(`Plugin:\t${this.plugin}`); } return lines.join("\n"); } } function build(list) { return (list || []) .map((entry) => new NetworkModel(entry)) .sort((left, right) => left.name.localeCompare(right.name)); } module.exports = { NetworkModel, build };