pmcf 2.39.7 → 2.39.9

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": "2.39.7",
3
+ "version": "2.39.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/endpoint.mjs CHANGED
@@ -3,12 +3,12 @@ class _Endpoint {
3
3
  #type;
4
4
  constructor(service, data) {
5
5
  this.service = service;
6
- if (data.port) {
6
+ if (data.port !== undefined) {
7
7
  this.#port = data.port;
8
8
  delete data.port;
9
9
  }
10
10
 
11
- if (data.type) {
11
+ if (data.type !== undefined) {
12
12
  this.#type = data.type;
13
13
  delete data.type;
14
14
  }
@@ -20,7 +20,7 @@ class _Endpoint {
20
20
  }
21
21
 
22
22
  get port() {
23
- return this.#port ?? this.service._port;
23
+ return this.#port ?? this.service.port;
24
24
  }
25
25
 
26
26
  toString() {
@@ -47,7 +47,7 @@ export class Endpoint extends _Endpoint {
47
47
  }
48
48
 
49
49
  get address() {
50
- return this.networkAddress.address;
50
+ return this.networkAddress?.address;
51
51
  }
52
52
 
53
53
  get family() {
@@ -28,13 +28,16 @@ export class SkeletonNetworkInterface extends ServiceOwner {
28
28
  }
29
29
 
30
30
  get host() {
31
- if(this.owner instanceof Host) {
31
+ if (this.owner instanceof Host) {
32
32
  return this.owner;
33
33
  }
34
34
  }
35
35
 
36
36
  *hosts() {
37
- yield* this.owner.hosts();
37
+ const host = this.host;
38
+ if (host) {
39
+ yield host;
40
+ }
38
41
  }
39
42
 
40
43
  get network_interface() {
@@ -12,7 +12,6 @@ export class ServiceOwner extends Base {
12
12
  set services(service) {
13
13
  const present = this._services.find(s => s.name === service.name);
14
14
 
15
- // console.log("SET SERVICE", service.name);
16
15
  if (!present) {
17
16
  this._services.push(service);
18
17
  }
package/src/service.mjs CHANGED
@@ -155,7 +155,7 @@ export class Service extends Base {
155
155
  }
156
156
 
157
157
  toString() {
158
- return `${this.type}`;
158
+ return `${super.toString()}[${this.type}]`;
159
159
  }
160
160
 
161
161
  set extends(value) {
@@ -222,7 +222,7 @@ export class Service extends Base {
222
222
  }
223
223
 
224
224
  get port() {
225
- return this._port ?? this.endpoints()[0].port;
225
+ return this._port ?? serviceTypeEndpoints(this.type)[0].port;
226
226
  }
227
227
 
228
228
  set weight(value) {
@@ -255,24 +255,16 @@ export class Service extends Base {
255
255
  for (const ep of this.endpoints(
256
256
  e => e.protocol && e.networkInterface.kind !== "loopback"
257
257
  )) {
258
- if (ep.port === undefined) {
259
- console.error(
260
- "Endpoint without port",
261
- ep.toString(),
262
- ep.networkInterface?.kind
263
- );
264
- } else {
265
- records.push(
266
- DNSRecord(
267
- dnsFullName(`_${this.type}._${ep.protocol}.${domainName}`),
268
- "SRV",
269
- this.priority ?? 10,
270
- this.weight,
271
- ep.port,
272
- dnsFullName(this.domainName)
273
- )
274
- );
275
- }
258
+ records.push(
259
+ DNSRecord(
260
+ dnsFullName(`_${this.type}._${ep.protocol}.${domainName}`),
261
+ "SRV",
262
+ this.priority ?? 10,
263
+ this.weight,
264
+ ep.port,
265
+ dnsFullName(this.domainName)
266
+ )
267
+ );
276
268
  }
277
269
  }
278
270
 
@@ -29,6 +29,12 @@ const BINDServiceTypeDefinition = {
29
29
  extends: ExtraSourceServiceTypeDefinition,
30
30
  priority: 0.1,
31
31
  properties: {
32
+ addresses: {
33
+ type: ["network", "host", "network_interface", "location", "owner"],
34
+ collection: true,
35
+ writeable: true
36
+ },
37
+
32
38
  trusted: {
33
39
  type: address_types,
34
40
  collection: true,
@@ -115,6 +121,7 @@ export class BINDService extends ExtraSourceService {
115
121
  hasLinkLocalAdresses = true;
116
122
  hasLocationRecord = true;
117
123
  notify = true;
124
+ _addresses = [];
118
125
  _trusted = [];
119
126
  _protected = [];
120
127
  _open = [];
@@ -161,6 +168,14 @@ export class BINDService extends ExtraSourceService {
161
168
  return [this.serial, this.refresh, this.retry, this.expire, this.minimum];
162
169
  }
163
170
 
171
+ set addresses(value) {
172
+ this._addresses.push(value);
173
+ }
174
+
175
+ get addresses() {
176
+ return this._addresses;
177
+ }
178
+
164
179
  set protected(value) {
165
180
  this._protected.push(value);
166
181
  }
@@ -202,8 +217,10 @@ export class BINDService extends ExtraSourceService {
202
217
  }
203
218
 
204
219
  async *preparePackages(dir) {
205
- const location = this.owner.owner;
206
- const name = location.name;
220
+ const sources = this.addresses.length ? this.addresses : [this.owner];
221
+ const names = sources.map(a => a.fullName).join(" ");
222
+
223
+ const name = this.owner.owner.name;
207
224
  const p1 = join(dir, "p1") + "/";
208
225
  const packageData = {
209
226
  dir: p1,
@@ -211,7 +228,7 @@ export class BINDService extends ExtraSourceService {
211
228
  outputs: this.outputs,
212
229
  properties: {
213
230
  name: `named-${name}`,
214
- description: `named definitions for ${location.fullName}`,
231
+ description: `named definitions for ${names}`,
215
232
  access: "private"
216
233
  }
217
234
  };
@@ -258,7 +275,7 @@ export class BINDService extends ExtraSourceService {
258
275
  packageData.dir = p2;
259
276
  packageData.properties = {
260
277
  name: `named-zones-${name}`,
261
- description: `zone definitions for ${location.fullName}`,
278
+ description: `zone definitions for ${names}`,
262
279
  dependencies: ["mf-named"],
263
280
  replaces: ["mf-named-zones"],
264
281
  access: "private",
@@ -281,13 +298,12 @@ export class BINDService extends ExtraSourceService {
281
298
  )
282
299
  ];
283
300
 
284
- await this.generateZoneDefs(location, packageData);
301
+ await this.generateZoneDefs(sources, packageData);
285
302
 
286
303
  yield packageData;
287
304
  }
288
305
 
289
- async generateZoneDefs(location, packageData) {
290
- const ttl = this.recordTTL;
306
+ async generateZoneDefs(sources, packageData) {
291
307
  const nameService = this.findService({ type: "dns", priority: "<10" });
292
308
  const rname = this.administratorEmail.replace(/@/, ".");
293
309
 
@@ -309,31 +325,9 @@ export class BINDService extends ExtraSourceService {
309
325
 
310
326
  const configs = [];
311
327
 
312
- for (const host of location.hosts()) {
313
- for (const domain of host.foreignDomainNames) {
314
- const zone = {
315
- id: domain,
316
- file: `FOREIGN/${domain}.zone`,
317
- records: new Set([SOARecord, NSRecord])
318
- };
319
-
320
- const config = {
321
- name: `${domain}.zone.conf`,
322
- zones: [zone]
323
- };
324
- configs.push(config);
325
-
326
- if (this.hasLocationRecord) {
327
- zone.records.add(DNSRecord("location", "TXT", host.location.name));
328
- }
329
-
330
- for (const na of host.networkAddresses(
331
- na => na.networkInterface.kind != "loopback"
332
- )) {
333
- zone.records.add(
334
- DNSRecord("@", dnsRecordTypeForAddressFamily(na.family), na.address)
335
- );
336
- }
328
+ for (const source of sources) {
329
+ for (const host of source.hosts()) {
330
+ configs.push(...this.foreignDomainZones(host, [SOARecord, NSRecord]));
337
331
  }
338
332
  }
339
333
 
@@ -343,139 +337,181 @@ export class BINDService extends ExtraSourceService {
343
337
  addHook(
344
338
  packageData.properties.hooks,
345
339
  "post_upgrade",
346
- `rm -f ${foreignZones.map(
340
+ /* `rm -f ${foreignZones.map(
347
341
  zone => `/var/lib/named/${zone.file}.jnl`
348
- )}\n` +
349
- `/usr/bin/named-hostname-info ${foreignZones
350
- .map(zone => zone.id)
351
- .join(" ")}|/usr/bin/named-hostname-update`
342
+ )}\n` + */
343
+ `/usr/bin/named-hostname-info ${foreignZones
344
+ .map(zone => zone.id)
345
+ .join(" ")}|/usr/bin/named-hostname-update`
352
346
  );
353
347
  }
354
348
 
355
- console.log(
356
- "LOCAL DOMAINS",
357
- location.localDomains,
358
- location.domain,
359
- location.toString()
360
- );
361
-
362
- for (const domain of location.localDomains) {
363
- const locationName = location.name;
364
- const reverseZones = new Map();
365
-
366
- const config = {
367
- name: `${domain}.zone.conf`,
368
- zones: []
369
- };
370
- configs.push(config);
371
-
372
- const locationRecord = DNSRecord("location", "TXT", locationName);
349
+ for (const source of sources) {
350
+ console.log(
351
+ "LOCAL DOMAINS",
352
+ source.localDomains,
353
+ source.domain,
354
+ source.toString()
355
+ );
373
356
 
374
- const zone = {
375
- id: domain,
376
- file: `${locationName}/${domain}.zone`,
377
- records: new Set([SOARecord, NSRecord, locationRecord])
378
- };
379
- config.zones.push(zone);
357
+ for (const domain of source.localDomains) {
358
+ const locationName = source.name;
359
+ const reverseZones = new Map();
380
360
 
381
- if (this.hasCatalog) {
382
- const catalogConfig = {
383
- name: `catalog.${domain}.zone.conf`,
361
+ const config = {
362
+ name: `${domain}.zone.conf`,
384
363
  zones: []
385
364
  };
386
- configs.push(catalogConfig);
387
-
388
- zone.catalogZone = {
389
- id: `catalog.${domain}`,
390
- file: `${locationName}/catalog.${domain}.zone`,
391
- records: new Set([
392
- SOARecord,
393
- NSRecord,
394
- DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
395
- ])
365
+ configs.push(config);
366
+
367
+ const locationRecord = DNSRecord("location", "TXT", locationName);
368
+
369
+ const zone = {
370
+ id: domain,
371
+ file: `${locationName}/${domain}.zone`,
372
+ records: new Set([SOARecord, NSRecord, locationRecord])
396
373
  };
397
- catalogConfig.zones.push(zone.catalogZone);
398
- }
374
+ config.zones.push(zone);
375
+
376
+ if (this.hasCatalog) {
377
+ const catalogConfig = {
378
+ name: `catalog.${domain}.zone.conf`,
379
+ zones: []
380
+ };
381
+ configs.push(catalogConfig);
382
+
383
+ zone.catalogZone = {
384
+ id: `catalog.${domain}`,
385
+ file: `${locationName}/catalog.${domain}.zone`,
386
+ records: new Set([
387
+ SOARecord,
388
+ NSRecord,
389
+ DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
390
+ ])
391
+ };
392
+ catalogConfig.zones.push(zone.catalogZone);
393
+ }
394
+
395
+ const hosts = new Set();
396
+ const addresses = new Set();
399
397
 
400
- const hosts = new Set();
401
- const addresses = new Set();
402
-
403
- for await (const {
404
- address,
405
- subnet,
406
- networkInterface,
407
- domainNames,
408
- family
409
- } of location.networkAddresses()) {
410
- if (
411
- !this.exclude.has(networkInterface.network) &&
412
- !this.excludeInterfaceKinds.has(networkInterface.kind)
413
- ) {
414
- const host = networkInterface.host;
398
+ for await (const {
399
+ address,
400
+ subnet,
401
+ networkInterface,
402
+ domainNames,
403
+ family
404
+ } of source.networkAddresses()) {
415
405
  if (
416
- !addresses.has(address) &&
417
- (this.hasLinkLocalAdresses || !isLinkLocal(address))
406
+ !this.exclude.has(networkInterface.network) &&
407
+ !this.excludeInterfaceKinds.has(networkInterface.kind)
418
408
  ) {
419
- addresses.add(address);
420
-
421
- for (const domainName of domainNames) {
422
- zone.records.add(
423
- DNSRecord(
424
- dnsFullName(domainName),
425
- dnsRecordTypeForAddressFamily(family),
426
- address
427
- )
428
- );
429
- }
430
- if (subnet && host.domain === domain) {
431
- let reverseZone = reverseZones.get(subnet.address);
432
-
433
- if (!reverseZone) {
434
- const id = reverseArpa(subnet.prefix);
435
- reverseZone = {
436
- id,
437
- type: "plain",
438
- file: `${locationName}/${id}.zone`,
439
- records: new Set([SOARecord, NSRecord])
440
- };
441
- config.zones.push(reverseZone);
442
- reverseZones.set(subnet.address, reverseZone);
409
+ const host = networkInterface.host;
410
+ if (host) {
411
+ if (
412
+ !addresses.has(address) &&
413
+ (this.hasLinkLocalAdresses || !isLinkLocal(address))
414
+ ) {
415
+ addresses.add(address);
416
+
417
+ for (const domainName of domainNames) {
418
+ zone.records.add(
419
+ DNSRecord(
420
+ dnsFullName(domainName),
421
+ dnsRecordTypeForAddressFamily(family),
422
+ address
423
+ )
424
+ );
425
+ }
426
+ if (subnet && host?.domain === domain) {
427
+ let reverseZone = reverseZones.get(subnet.address);
428
+
429
+ if (!reverseZone) {
430
+ const id = reverseArpa(subnet.prefix);
431
+ reverseZone = {
432
+ id,
433
+ type: "plain",
434
+ file: `${locationName}/${id}.zone`,
435
+ records: new Set([SOARecord, NSRecord])
436
+ };
437
+ config.zones.push(reverseZone);
438
+ reverseZones.set(subnet.address, reverseZone);
439
+ }
440
+
441
+ for (const domainName of host.domainNames) {
442
+ reverseZone.records.add(
443
+ DNSRecord(
444
+ dnsFullName(reverseArpa(address)),
445
+ "PTR",
446
+ dnsFullName(domainName)
447
+ )
448
+ );
449
+ }
450
+ }
443
451
  }
444
452
 
445
- for (const domainName of host.domainNames) {
446
- reverseZone.records.add(
447
- DNSRecord(
448
- dnsFullName(reverseArpa(address)),
449
- "PTR",
450
- dnsFullName(domainName)
451
- )
452
- );
453
+ if (!hosts.has(host)) {
454
+ hosts.add(host);
455
+
456
+ for (const foreignDomainName of host.foreignDomainNames) {
457
+ zone.records.add(
458
+ DNSRecord(
459
+ "outfacing",
460
+ "PTR",
461
+ dnsFullName(foreignDomainName)
462
+ )
463
+ );
464
+ }
465
+
466
+ // console.log(host._services.map(s=>s.name));
467
+ for (const service of host._services) {
468
+ for (const record of service.dnsRecordsForDomainName(
469
+ host.domainName,
470
+ this.hasSVRRecords
471
+ )) {
472
+ //console.log("SERVICE",service.toString(),record.toString())
473
+
474
+ zone.records.add(record);
475
+ }
476
+ }
453
477
  }
454
478
  }
455
479
  }
480
+ }
481
+ }
482
+ }
456
483
 
457
- if (!hosts.has(host)) {
458
- hosts.add(host);
484
+ await this.writeZones(packageData, configs);
485
+ }
459
486
 
460
- for (const foreignDomainName of host.foreignDomainNames) {
461
- zone.records.add(
462
- DNSRecord("outfacing", "PTR", dnsFullName(foreignDomainName))
463
- );
464
- }
487
+ foreignDomainZones(host, records) {
488
+ return host.foreignDomainNames.map(domain => {
489
+ const zone = {
490
+ id: domain,
491
+ file: `FOREIGN/${domain}.zone`,
492
+ records: new Set(records)
493
+ };
494
+ const config = {
495
+ name: `${domain}.zone.conf`,
496
+ zones: [zone]
497
+ };
465
498
 
466
- for (const service of host.findServices()) {
467
- for (const record of service.dnsRecordsForDomainName(
468
- host.domainName,
469
- this.hasSVRRecords
470
- )) {
471
- zone.records.add(record);
472
- }
473
- }
474
- }
475
- }
499
+ if (this.hasLocationRecord) {
500
+ zone.records.add(DNSRecord("location", "TXT", host.location.name));
476
501
  }
477
- }
502
+ for (const na of host.networkAddresses(
503
+ na => na.networkInterface.kind != "loopback"
504
+ )) {
505
+ zone.records.add(
506
+ DNSRecord("@", dnsRecordTypeForAddressFamily(na.family), na.address)
507
+ );
508
+ }
509
+
510
+ return config;
511
+ });
512
+ }
478
513
 
514
+ async writeZones(packageData, configs) {
479
515
  for (const config of configs) {
480
516
  console.log(`config: ${config.name}`);
481
517
 
@@ -519,7 +555,7 @@ export class BINDService extends ExtraSourceService {
519
555
  zone.file,
520
556
  [...zone.records]
521
557
  .sort(sortZoneRecords)
522
- .map(r => r.toString(maxKeyLength, ttl))
558
+ .map(r => r.toString(maxKeyLength, this.recordTTL))
523
559
  );
524
560
  }
525
561
 
@@ -5,7 +5,7 @@ export class SkeletonNetworkInterface extends ServiceOwner {
5
5
  set extends(value: any[]);
6
6
  get extends(): any[];
7
7
  get host(): Host;
8
- hosts(): Generator<any, void, any>;
8
+ hosts(): Generator<Host, void, unknown>;
9
9
  get network_interface(): this;
10
10
  get domainName(): any;
11
11
  get domainNames(): Set<any>;
@@ -254,6 +254,11 @@ export class BINDService extends ExtraSourceService {
254
254
  };
255
255
  priority: number;
256
256
  properties: {
257
+ addresses: {
258
+ type: string[];
259
+ collection: boolean;
260
+ writeable: boolean;
261
+ };
257
262
  trusted: {
258
263
  type: string[];
259
264
  collection: boolean;
@@ -353,6 +358,7 @@ export class BINDService extends ExtraSourceService {
353
358
  hasLinkLocalAdresses: boolean;
354
359
  hasLocationRecord: boolean;
355
360
  notify: boolean;
361
+ _addresses: any[];
356
362
  _trusted: any[];
357
363
  _protected: any[];
358
364
  _open: any[];
@@ -364,6 +370,8 @@ export class BINDService extends ExtraSourceService {
364
370
  expire: number;
365
371
  minimum: number;
366
372
  get soaUpdates(): number[];
373
+ set addresses(value: any[]);
374
+ get addresses(): any[];
367
375
  set protected(value: any[]);
368
376
  get protected(): any[];
369
377
  set trusted(value: any[]);
@@ -384,7 +392,9 @@ export class BINDService extends ExtraSourceService {
384
392
  access: string;
385
393
  };
386
394
  }, void, unknown>;
387
- generateZoneDefs(location: any, packageData: any): Promise<void>;
395
+ generateZoneDefs(sources: any, packageData: any): Promise<void>;
396
+ foreignDomainZones(host: any, records: any): any;
397
+ writeZones(packageData: any, configs: any): Promise<void>;
388
398
  }
389
399
  import { ExtraSourceService } from "pmcf";
390
400
  import { FileContentProvider } from "npm-pkgbuild";