pmcf 1.17.0 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { join } from "node:path";
4
4
  import { createHmac } from "node:crypto";
5
- import { writeLines } from "../src/utils.mjs";
5
+ import { writeLines, isIPv4Address } from "../src/utils.mjs";
6
6
  import { prepare } from "../src/cmd.mjs";
7
7
 
8
8
  const { world, args, options } = prepare();
@@ -103,7 +103,7 @@ async function generateNamedDefs(location, targetDir) {
103
103
  const host = networkInterface.host;
104
104
  zone.records.add(
105
105
  `${host.hostName.padEnd(NAME_LEN, " ")} ${ttl} IN ${
106
- address.indexOf(".") >= 0 ? "A " : "AAAA"
106
+ isIPv4Address(address) ? "A " : "AAAA"
107
107
  } ${normalizeIPAddress(address)}`
108
108
  );
109
109
 
@@ -132,7 +132,7 @@ async function generateNamedDefs(location, targetDir) {
132
132
 
133
133
  const reverseZone = networkInterface.network.subnet?.reverseZone;
134
134
 
135
- if (reverseZone && address.indexOf(".") >= 0) {
135
+ if (reverseZone && isIPv4Address(address)) {
136
136
  reverseZone.records.add(
137
137
  `${(reverseArpaAddress(address) + ".").padEnd(
138
138
  NAME_LEN,
@@ -159,7 +159,9 @@ async function generateNamedDefs(location, targetDir) {
159
159
  zoneConfig.push(` file \"${zone.file}\";`);
160
160
 
161
161
  zoneConfig.push(
162
- ` allow-update { ${dns.allowedUpdates.length ? dns.allowedUpdates.join(";") : "none"}; };`
162
+ ` allow-update { ${
163
+ dns.allowedUpdates.length ? dns.allowedUpdates.join(";") : "none"
164
+ }; };`
163
165
  );
164
166
  zoneConfig.push(` notify yes;`);
165
167
  zoneConfig.push(`};`);
@@ -177,7 +179,7 @@ async function generateNamedDefs(location, targetDir) {
177
179
  }
178
180
 
179
181
  export function reverseAddress(address) {
180
- if (address.indexOf(".") >= 0) {
182
+ if (isIPv4Address(address)) {
181
183
  return address.split(".").reverse().join(".");
182
184
  }
183
185
 
@@ -191,12 +193,12 @@ export function reverseAddress(address) {
191
193
  export function reverseArpaAddress(address) {
192
194
  return (
193
195
  reverseAddress(address) +
194
- (address.indexOf(".") >= 0 ? ".in-addr.arpa" : ".ip6.arpa")
196
+ (isIPv4Address(address) ? ".in-addr.arpa" : ".ip6.arpa")
195
197
  );
196
198
  }
197
199
 
198
200
  export function normalizeIPAddress(address) {
199
- if (address.indexOf(".") >= 0) {
201
+ if (isIPv4Address(address)) {
200
202
  return address;
201
203
  }
202
204
  address = address.replace(/\/\d+$/, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -668,14 +668,14 @@ export class Host extends Base {
668
668
  }
669
669
  }
670
670
 
671
- Object.assign(this, { networkInterfaces: {} }, data);
672
-
673
- owner.addHost(this);
671
+ Object.assign(this, data);
674
672
 
675
673
  for (const [name, iface] of Object.entries(this.networkInterfaces)) {
676
674
  iface.name = name;
677
- this.networkInterfaces[name] = new NetworkInterface(this, iface);
675
+ new NetworkInterface(this, iface);
678
676
  }
677
+
678
+ owner.addHost(this);
679
679
  }
680
680
 
681
681
  get deployment() {
@@ -774,10 +774,12 @@ export class Host extends Base {
774
774
  }
775
775
  }
776
776
 
777
+ addNetworkInterface(networkInterface) {
778
+ this.networkInterfaces[networkInterface.name] = networkInterface;
779
+ }
780
+
777
781
  *networkAddresses() {
778
- for (const [name, networkInterface] of Object.entries(
779
- this.networkInterfaces
780
- )) {
782
+ for (const networkInterface of Object.values(this.networkInterfaces)) {
781
783
  for (const attribute of ["ipv4", "ipv6", "link-local-ipv6"]) {
782
784
  if (networkInterface[attribute]) {
783
785
  yield { address: networkInterface[attribute], networkInterface };
@@ -846,6 +848,8 @@ export class NetworkInterface extends Base {
846
848
  }
847
849
 
848
850
  Object.assign(this, data);
851
+
852
+ owner.addNetworkInterface(this);
849
853
  }
850
854
 
851
855
  get host() {
package/src/utils.mjs CHANGED
@@ -31,3 +31,11 @@ export function bridgeToJSON(bridge) {
31
31
  export function asArray(value) {
32
32
  return Array.isArray(value) ? value : value === undefined ? [] : [value];
33
33
  }
34
+
35
+ export function isIPv4Address(address) {
36
+ return address.indexOf(".") >= 0;
37
+ }
38
+
39
+ export function isIPv6Address(address) {
40
+ return address.indexOf(":") >= 0;
41
+ }
package/types/model.d.mts CHANGED
@@ -109,6 +109,7 @@ export class Host extends Base {
109
109
  get domainName(): string;
110
110
  addService(service: any): void;
111
111
  services(filter: any): Generator<any, void, unknown>;
112
+ addNetworkInterface(networkInterface: any): void;
112
113
  networkAddresses(): Generator<{
113
114
  address: any;
114
115
  networkInterface: any;
package/types/utils.d.mts CHANGED
@@ -2,3 +2,5 @@ export function writeLines(dir: any, name: any, lines: any): Promise<void>;
2
2
  export function sectionLines(sectionName: any, values: any): string[];
3
3
  export function bridgeToJSON(bridge: any): any[];
4
4
  export function asArray(value: any): any[];
5
+ export function isIPv4Address(address: any): boolean;
6
+ export function isIPv6Address(address: any): boolean;