pmcf 2.25.0 → 2.26.0

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.
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  ## Poor mans configuration management
16
16
 
17
+
17
18
  # API
18
19
 
19
20
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.25.0",
3
+ "version": "2.26.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -1,14 +1,51 @@
1
1
  import { decodeIPv4, decodeIPv6 } from "ip-utilties";
2
2
  import { asIterator } from "./utils.mjs";
3
3
 
4
+ const typeOrder = {
5
+ SOA: 0,
6
+ NS: 1,
7
+ MX: 2,
8
+ A: 3,
9
+ AAAA: 3,
10
+ CNAME: 4,
11
+ PTR: 5,
12
+ HTTPS: 6,
13
+ SRV: 7,
14
+ TXT: 8
15
+ };
16
+
17
+ export function sortZoneRecords(a, b) {
18
+ let order = typeOrder[a.type] - typeOrder[b.type];
19
+ if (order) {
20
+ return order;
21
+ }
22
+
23
+ if (a.type === "PTR") {
24
+ const toNum = a => {
25
+ const s = a.split(".");
26
+ s.pop();s.pop();s.pop();
27
+ return s.reverse().reduce((a, c) => BigInt(parseInt(c,16)) + 256n * 256n * a, 0n);
28
+ };
29
+ return Number(toNum(a.key) - toNum(b.key));
30
+ }
31
+ order = a.key.localeCompare(b.key);
32
+ if(order) {
33
+ return order;
34
+ }
35
+
36
+ return a.values[0] - b.values[0];
37
+ }
38
+
4
39
  export function dnsFullName(name) {
5
40
  return name.endsWith(".") ? name : name + ".";
6
41
  }
7
42
 
8
43
  export function dnsRecordTypeForAddressFamily(family) {
9
- switch(family) {
10
- case 'IPv4': return "A";
11
- case 'IPv6': return "AAAA";
44
+ switch (family) {
45
+ case "IPv4":
46
+ return "A";
47
+ case "IPv6":
48
+ return "AAAA";
12
49
  }
13
50
  }
14
51
 
@@ -33,7 +70,9 @@ export function DNSRecord(key, type, ...values) {
33
70
  );
34
71
 
35
72
  return {
73
+ type,
36
74
  key,
75
+ values,
37
76
  toString: (maxKeyLength = 0, ttl = "1W") =>
38
77
  `${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
39
78
  5,
@@ -19,7 +19,6 @@ const DHCPServiceTypeDefinition = {
19
19
  };
20
20
 
21
21
  const controlAgentEndpoint = {
22
- // extends: ["http"],
23
22
  type: "kea-control-agent",
24
23
  port: 8000,
25
24
  protocol: "tcp",
@@ -294,30 +293,29 @@ export class DHCPService extends Service {
294
293
  .join(",")
295
294
  }
296
295
  ],
297
- subnet6: [
298
- {
299
- id: 1,
300
- subnet: "2001:db8:1::/64",
301
- pools: [
302
- {
303
- pool: "2001:db8:1::/80"
304
- }
305
- ],
306
- "pd-pools": [
307
- {
308
- prefix: "2001:db8:8::",
309
- "prefix-len": 56,
310
- "delegated-len": 64
311
- }
312
- ],
313
- reservations: [
314
- {
315
- duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
316
- "ip-addresses": ["2001:db8:1::100"]
317
- }
318
- ]
319
- }
320
- ],
296
+ subnet6: [...subnets]
297
+ .filter(s => s.family === "IPv6")
298
+ .map((subnet, index) => {
299
+ return {
300
+ id: index + 1,
301
+ subnet: subnet.longAddress,
302
+ pools: [{ pool: subnet.addressRange.join(" - ") }],
303
+
304
+ "pd-pools": [
305
+ {
306
+ prefix: "2001:db8:8::",
307
+ "prefix-len": 56,
308
+ "delegated-len": 64
309
+ }
310
+ ],
311
+ reservations: [
312
+ {
313
+ duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
314
+ "ip-addresses": ["2001:db8:1::100"]
315
+ }
316
+ ]
317
+ };
318
+ }),
321
319
  "dhcp-ddns": dhcpServerDdns,
322
320
  loggers
323
321
  }
@@ -6,7 +6,8 @@ import { writeLines } from "../utils.mjs";
6
6
  import {
7
7
  DNSRecord,
8
8
  dnsFullName,
9
- dnsRecordTypeForAddressFamily
9
+ dnsRecordTypeForAddressFamily,
10
+ sortZoneRecords
10
11
  } from "../dns-utils.mjs";
11
12
  import { addType } from "../types.mjs";
12
13
  import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
@@ -481,7 +482,9 @@ async function generateZoneDefs(dns, location, packageData) {
481
482
  await writeLines(
482
483
  join(packageData.dir, "var/lib/named"),
483
484
  zone.file,
484
- [...zone.records].map(r => r.toString(maxKeyLength, ttl))
485
+ [...zone.records]
486
+ .sort(sortZoneRecords)
487
+ .map(r => r.toString(maxKeyLength, ttl))
485
488
  );
486
489
  }
487
490
 
@@ -1,7 +1,10 @@
1
+ export function sortZoneRecords(a: any, b: any): number;
1
2
  export function dnsFullName(name: any): any;
2
3
  export function dnsRecordTypeForAddressFamily(family: any): "A" | "AAAA";
3
4
  export function DNSRecord(key: any, type: any, ...values: any[]): {
5
+ type: any;
4
6
  key: any;
7
+ values: any[];
5
8
  toString: (maxKeyLength?: number, ttl?: string) => string;
6
9
  };
7
10
  export function dnsFormatParameters(parameters: any): string;
@@ -325,7 +325,9 @@ export class Service extends Base {
325
325
  get type(): any;
326
326
  get systemdServices(): any;
327
327
  dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
328
+ type: any;
328
329
  key: any;
330
+ values: any[];
329
331
  toString: (maxKeyLength?: number, ttl?: string) => string;
330
332
  }[];
331
333
  }