pmcf 1.67.2 → 1.69.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.67.2",
3
+ "version": "1.69.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns.mjs CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  } from "./utils.mjs";
10
10
  import { Base } from "./base.mjs";
11
11
  import { addType } from "./types.mjs";
12
+ import { sortByPriority } from "./service.mjs";
13
+ import { subnets } from "./subnet.mjs";
12
14
 
13
15
  const DNSServiceTypeDefinition = {
14
16
  name: "dns",
@@ -29,6 +31,7 @@ const DNSServiceTypeDefinition = {
29
31
  expire: { type: "string", collection: false, writeable: true },
30
32
  minimum: { type: "string", collection: false, writeable: true },
31
33
  forwardsTo: { type: "network", collection: true, writeable: true },
34
+ trusts: { type: "network", collection: true, writeable: true },
32
35
  allowedUpdates: { type: "string", collection: true, writeable: true }
33
36
  }
34
37
  };
@@ -43,6 +46,7 @@ export class DNSService extends Base {
43
46
  hasLinkLocalAdresses = true;
44
47
  notify = true;
45
48
  #forwardsTo = [];
49
+ #trusts = [];
46
50
 
47
51
  refresh = 36000;
48
52
  retry = 72000;
@@ -71,6 +75,14 @@ export class DNSService extends Base {
71
75
  return [this.refresh, this.retry, this.expire, this.minimum];
72
76
  }
73
77
 
78
+ set trusts(value) {
79
+ this.#trusts.push(value);
80
+ }
81
+
82
+ get trusts() {
83
+ return this.#trusts;
84
+ }
85
+
74
86
  set forwardsTo(value) {
75
87
  this.#forwardsTo.push(value);
76
88
  }
@@ -79,6 +91,15 @@ export class DNSService extends Base {
79
91
  return this.#forwardsTo;
80
92
  }
81
93
 
94
+ get forwardsToAdresses() {
95
+ return this.forwardsTo
96
+ .map(ft => Array.from(ft.findServices(DNS_SERVICE_FILTER)))
97
+ .flat()
98
+ .sort(sortByPriority)
99
+ .map(s => s.rawAddresses)
100
+ .flat();
101
+ }
102
+
82
103
  *findServices(filter) {
83
104
  yield* this.owner.findServices(filter);
84
105
 
@@ -93,7 +114,7 @@ export class DNSService extends Base {
93
114
 
94
115
  async resolvedConfig() {
95
116
  const dnsServices = Array.from(this.findServices(DNS_SERVICE_FILTER)).sort(
96
- (a, b) => a.priority - b.priority
117
+ sortByPriority
97
118
  );
98
119
 
99
120
  const master = dnsServices
@@ -129,27 +150,18 @@ export class DNSService extends Base {
129
150
  }
130
151
  };
131
152
 
132
- const options = ["forwarders {"];
133
- for (const s of this.forwardsTo) {
134
- for (const dns of s.findServices(DNS_SERVICE_FILTER)) {
135
- options.push(...(dns.rawAddresses.map(a=>` ${a};`)));
136
- }
137
- }
138
- options.push("};");
153
+ const options = [
154
+ "forwarders {",
155
+ ...this.forwardsToAdresses.map(a => ` ${a};`),
156
+ "};"
157
+ ];
139
158
  await writeLines(join(p1, "etc/named.d/options"), `${name}.conf`, options);
140
159
 
141
- const category = [];
142
-
143
- /*
144
- const category = ["acl trusted {"];
145
-
146
- const network = this.owner.named("LOCAL");
147
- for (const subnet of network.subnets()) {
148
- category.push(`${subnet.name};`);
149
- }
150
-
151
- category.push("}");
152
- */
160
+ const category = [
161
+ "acl trusted {",
162
+ ...Array.from(subnets(this.trusts)).map(subnet => ` ${subnet.name};`),
163
+ "};"
164
+ ];
153
165
 
154
166
  await writeLines(
155
167
  join(p1, "etc/named.d/categories"),
@@ -157,7 +169,7 @@ export class DNSService extends Base {
157
169
  category
158
170
  );
159
171
 
160
- if(options.length > 2 || category.length > 2) {
172
+ if (options.length > 2 || category.length > 2) {
161
173
  yield result;
162
174
  }
163
175
 
package/src/host.mjs CHANGED
@@ -266,10 +266,54 @@ export class Host extends Base {
266
266
  if (filter) {
267
267
  for (const service of this.#services) {
268
268
  if (
269
- filter.type === "*" ||
270
- filter.type === service.type ||
271
- filter.name === service.name
269
+ (filter.type === undefined || filter.type === service.type) &&
270
+ (filter.name === undefined || filter.name === service.name)
272
271
  ) {
272
+ switch (typeof filter.priority) {
273
+ case "number":
274
+ if (filter.priority !== service.priority) {
275
+ continue;
276
+ }
277
+ break;
278
+ case "string":
279
+ const m = filter.priority.match(/^([=><!]+)(\d+)/);
280
+ if (m) {
281
+ const priority = parseInt(m[2]);
282
+ switch (m[1]) {
283
+ case "=":
284
+ if (service.priority != priority) {
285
+ continue;
286
+ }
287
+ break;
288
+ case "!=":
289
+ if (service.priority == priority) {
290
+ continue;
291
+ }
292
+ break;
293
+ case "<":
294
+ if (service.priority >= priority) {
295
+ continue;
296
+ }
297
+ break;
298
+ case "<=":
299
+ if (service.priority > priority) {
300
+ continue;
301
+ }
302
+ break;
303
+ case ">":
304
+ if (service.priority <= priority) {
305
+ continue;
306
+ }
307
+ break;
308
+ case ">=":
309
+ if (service.priority < priority) {
310
+ continue;
311
+ }
312
+ break;
313
+ }
314
+ }
315
+ }
316
+
273
317
  yield service;
274
318
  }
275
319
  }
package/src/service.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Base } from "./base.mjs";
2
2
  import { addType } from "./types.mjs";
3
3
 
4
+
5
+ export const sortByPriority = (a, b) => a.priority - b.priority;
6
+
4
7
  const ServiceTypes = {
5
8
  dns: { protocol: "udp", port: 53 },
6
9
  ldap: { protocol: "tcp", port: 389 },
package/src/subnet.mjs CHANGED
@@ -75,3 +75,17 @@ export class Subnet extends Base {
75
75
  return false;
76
76
  }
77
77
  }
78
+
79
+
80
+ export function subnets(sources) {
81
+ const all = new Set();
82
+
83
+ for (const owner of sources) {
84
+ for (const subnet of owner.subnets()) {
85
+ all.add(subnet);
86
+ }
87
+ }
88
+
89
+ return all;
90
+ }
91
+
@@ -142,6 +142,11 @@ export class Cluster extends Host {
142
142
  collection: boolean;
143
143
  writeable: boolean;
144
144
  };
145
+ trusts: {
146
+ type: string;
147
+ collection: boolean;
148
+ writeable: boolean;
149
+ };
145
150
  allowedUpdates: {
146
151
  type: string;
147
152
  collection: boolean;
@@ -326,6 +331,11 @@ export class Cluster extends Host {
326
331
  collection: boolean;
327
332
  writeable: boolean;
328
333
  };
334
+ trusts: {
335
+ type: string;
336
+ collection: boolean;
337
+ writeable: boolean;
338
+ };
329
339
  allowedUpdates: {
330
340
  type: string;
331
341
  collection: boolean;
package/types/dns.d.mts CHANGED
@@ -56,6 +56,11 @@ export class DNSService extends Base {
56
56
  collection: boolean;
57
57
  writeable: boolean;
58
58
  };
59
+ trusts: {
60
+ type: string;
61
+ collection: boolean;
62
+ writeable: boolean;
63
+ };
59
64
  allowedUpdates: {
60
65
  type: string;
61
66
  collection: boolean;
@@ -74,8 +79,11 @@ export class DNSService extends Base {
74
79
  expire: number;
75
80
  minimum: number;
76
81
  get soaUpdates(): number[];
82
+ set trusts(value: any[]);
83
+ get trusts(): any[];
77
84
  set forwardsTo(value: any[]);
78
85
  get forwardsTo(): any[];
86
+ get forwardsToAdresses(): any[];
79
87
  get domains(): any[];
80
88
  resolvedConfig(): Promise<{
81
89
  DNS: string;
@@ -142,6 +142,11 @@ export class Location extends Owner {
142
142
  collection: boolean;
143
143
  writeable: boolean;
144
144
  };
145
+ trusts: {
146
+ type: string;
147
+ collection: boolean;
148
+ writeable: boolean;
149
+ };
145
150
  allowedUpdates: {
146
151
  type: string;
147
152
  collection: boolean;
@@ -326,6 +331,11 @@ export class Location extends Owner {
326
331
  collection: boolean;
327
332
  writeable: boolean;
328
333
  };
334
+ trusts: {
335
+ type: string;
336
+ collection: boolean;
337
+ writeable: boolean;
338
+ };
329
339
  allowedUpdates: {
330
340
  type: string;
331
341
  collection: boolean;
@@ -144,6 +144,11 @@ export class Network extends Owner {
144
144
  collection: boolean;
145
145
  writeable: boolean;
146
146
  };
147
+ trusts: {
148
+ type: string;
149
+ collection: boolean;
150
+ writeable: boolean;
151
+ };
147
152
  allowedUpdates: {
148
153
  type: string;
149
154
  collection: boolean;
package/types/owner.d.mts CHANGED
@@ -140,6 +140,11 @@ export class Owner extends Base {
140
140
  collection: boolean;
141
141
  writeable: boolean;
142
142
  };
143
+ trusts: {
144
+ type: string;
145
+ collection: boolean;
146
+ writeable: boolean;
147
+ };
143
148
  allowedUpdates: {
144
149
  type: string;
145
150
  collection: boolean;
package/types/root.d.mts CHANGED
@@ -146,6 +146,11 @@ export class Root extends Location {
146
146
  collection: boolean;
147
147
  writeable: boolean;
148
148
  };
149
+ trusts: {
150
+ type: string;
151
+ collection: boolean;
152
+ writeable: boolean;
153
+ };
149
154
  allowedUpdates: {
150
155
  type: string;
151
156
  collection: boolean;
@@ -330,6 +335,11 @@ export class Root extends Location {
330
335
  collection: boolean;
331
336
  writeable: boolean;
332
337
  };
338
+ trusts: {
339
+ type: string;
340
+ collection: boolean;
341
+ writeable: boolean;
342
+ };
333
343
  allowedUpdates: {
334
344
  type: string;
335
345
  collection: boolean;
@@ -1,3 +1,4 @@
1
+ export function sortByPriority(a: any, b: any): number;
1
2
  export class Service extends Base {
2
3
  static get typeDefinition(): {
3
4
  name: string;
@@ -1,3 +1,4 @@
1
+ export function subnets(sources: any): Set<any>;
1
2
  export class Subnet extends Base {
2
3
  static get typeDefinition(): {
3
4
  name: string;