pmcf 2.34.0 → 2.35.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.34.0",
3
+ "version": "2.35.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/endpoint.mjs CHANGED
@@ -17,6 +17,10 @@ export class Endpoint {
17
17
  return this.networkAddress.networkInterface.hostName;
18
18
  }
19
19
 
20
+ get domainName() {
21
+ return this.networkAddress.networkInterface.domainName;
22
+ }
23
+
20
24
  get address() {
21
25
  return this.networkAddress.address;
22
26
  }
@@ -29,3 +33,23 @@ export class Endpoint {
29
33
  return this.networkAddress.networkInterface;
30
34
  }
31
35
  }
36
+
37
+ export class DomainNameEndpoint {
38
+ constructor(service, domainName, data) {
39
+ this.service = service;
40
+ this.domainName = domainName;
41
+ Object.assign(this, data);
42
+ }
43
+
44
+ get networkInterface() {
45
+ return {};
46
+ }
47
+
48
+ get address() {
49
+ return this.domainName;
50
+ }
51
+
52
+ toString() {
53
+ return `${this.address}[${this.port}]`;
54
+ }
55
+ }
@@ -42,6 +42,10 @@ export class SkeletonNetworkInterface extends ServiceOwner {
42
42
  return this;
43
43
  }
44
44
 
45
+ get domainName() {
46
+ return this.host?.domainName;
47
+ }
48
+
45
49
  get domainNames() {
46
50
  return new Set();
47
51
  }
package/src/service.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { isLocalhost } from "ip-utilties";
2
- import { Base, Host, Endpoint } from "pmcf";
1
+ import { Base, Host, Endpoint, DomainNameEndpoint } from "pmcf";
3
2
  import { addType } from "./types.mjs";
4
3
  import { asArray } from "./utils.mjs";
5
4
  import { networkAddressProperties } from "./network-support.mjs";
@@ -11,11 +10,6 @@ import {
11
10
  } from "./dns-utils.mjs";
12
11
 
13
12
  const ServiceTypes = {
14
- "systemd-resolved": { endpoints: [] },
15
- "systemd-timesyncd": { endpoints: [] },
16
- "systemd-journal": { endpoints: [] },
17
- "systemd-journal-remote": { endpoints: [] },
18
- "systemd-journal-upload": { endpoints: [] },
19
13
  ntp: { endpoints: [{ protocol: "udp", port: 123, tls: false }] },
20
14
  dns: { endpoints: [{ protocol: "udp", port: 53, tls: false }] },
21
15
  ldap: { endpoints: [{ protocol: "tcp", port: 389, tls: false }] },
@@ -199,7 +193,7 @@ export class Service extends Base {
199
193
  }
200
194
  ];
201
195
 
202
- const result = [...this.host.networkAddresses()]
196
+ let result = [...this.host.networkAddresses()]
203
197
  .map(na =>
204
198
  data.map(
205
199
  d =>
@@ -211,6 +205,12 @@ export class Service extends Base {
211
205
  )
212
206
  .flat();
213
207
 
208
+ if (result.length === 0) {
209
+ result = data.map(
210
+ d => new DomainNameEndpoint(this, this.domainName, { ...d, ...local })
211
+ );
212
+ }
213
+
214
214
  return filter ? result.filter(filter) : result;
215
215
  }
216
216
 
@@ -322,26 +322,15 @@ export class Service extends Base {
322
322
 
323
323
  export const sortByPriority = (a, b) => a.priority - b.priority;
324
324
 
325
- export function serviceAddresses(
326
- sources,
327
- filter,
328
- addressType = "addresses",
329
- addressFilter = a => !isLocalhost(a)
330
- ) {
331
- return asArray(sources)
332
- .map(ft => Array.from(ft.findServices(filter)))
325
+ export function serviceEndpoints(sources, options = {}) {
326
+ const all = asArray(sources)
327
+ .map(ft => Array.from(ft.findServices(options.services)))
333
328
  .flat()
334
329
  .sort(sortByPriority)
335
- .map(s => s[addressType])
336
- .flat()
337
- .filter(addressFilter);
338
- }
339
-
340
- export function serviceEndpoints(sources, filter, endpointFilter) {
341
- return asArray(sources)
342
- .map(ft => Array.from(ft.findServices(filter)))
343
- .flat()
344
- .sort(sortByPriority)
345
- .map(service => service.endpoints(endpointFilter))
330
+ .map(service => service.endpoints(options.endpoints))
346
331
  .flat();
332
+
333
+ const res = new Set(options.select ? all.map(options.select) : all);
334
+
335
+ return options.join ? [...res].join(options.join) : res;
347
336
  }
@@ -70,14 +70,13 @@ export class DHCPService extends Service {
70
70
 
71
71
  console.log("kea", host.name, network.name);
72
72
 
73
- const dnsServerEndpoints = serviceEndpoints(
74
- network,
75
- {
73
+ const dnsServerEndpoints = serviceEndpoints(network, {
74
+ services: {
76
75
  type: "dns",
77
76
  priority: "<10"
78
77
  },
79
- endpoint => endpoint.networkInterface.kind !== "loopback"
80
- );
78
+ endpoints: endpoint => endpoint.networkInterface.kind !== "loopback"
79
+ });
81
80
 
82
81
  const packageData = {
83
82
  dir,
@@ -87,8 +87,6 @@ const statisticsEndpoint = {
87
87
  tls: false
88
88
  };
89
89
 
90
- const DNS_SERVICE_FILTER = { type: DNSServiceTypeDefinition.name };
91
-
92
90
  function addressList(objects) {
93
91
  return Array.from(objects).map(object => {
94
92
  switch (typeof object) {
@@ -222,9 +220,10 @@ export class DNSService extends ExtraSourceService {
222
220
  }
223
221
  };
224
222
 
225
- const forwarders = new Set(
226
- serviceEndpoints(this.source, DNS_SERVICE_FILTER).map(e => e.address)
227
- );
223
+ const forwarders = serviceEndpoints(this.source, {
224
+ services: { type: "dns", priority: ">=20" },
225
+ select: e => e.address
226
+ });
228
227
 
229
228
  if (forwarders.size) {
230
229
  await writeLines(
@@ -283,7 +282,7 @@ export class DNSService extends ExtraSourceService {
283
282
 
284
283
  async function generateZoneDefs(dns, location, packageData) {
285
284
  const ttl = dns.recordTTL;
286
- const nameService = dns.findService(DNS_SERVICE_FILTER);
285
+ const nameService = dns.findService({ type: "dns", priority: "<10" });
287
286
  const rname = dns.administratorEmail.replace(/@/, ".");
288
287
 
289
288
  const SOARecord = DNSRecord(
@@ -24,8 +24,6 @@ const NTPServiceTypeDefinition = {
24
24
  }
25
25
  };
26
26
 
27
- const NTP_SERVICE_FILTER = { type: NTPServiceTypeDefinition.name };
28
-
29
27
  export class NTPService extends ExtraSourceService {
30
28
  static {
31
29
  addType(this);
@@ -64,19 +62,19 @@ export class NTPService extends ExtraSourceService {
64
62
  };
65
63
 
66
64
  const lines = [
67
- ...serviceEndpoints(
68
- this,
69
- {
70
- ...NTP_SERVICE_FILTER,
71
- priority: ">=10"
65
+ ...serviceEndpoints(this, {
66
+ services: {
67
+ type: "ntp",
68
+ priority: ">=20"
72
69
  },
73
- e => e.family === "IPv4" && e.networkInterface.kind !== "loopback"
74
- ).map(
75
- endpoint =>
70
+ endpoints: e =>
71
+ e.family === "IPv4" && e.networkInterface.kind !== "loopback",
72
+
73
+ select: endpoint =>
76
74
  `${endpoint.service.isPool ? "pool" : "server"} ${
77
75
  endpoint.address
78
76
  } iburst`
79
- ),
77
+ }),
80
78
  `mailonchange ${this.administratorEmail} 0.5`,
81
79
  "local stratum 10",
82
80
  "leapsectz right/UTC",
@@ -1,5 +1,8 @@
1
- import { ExtraSourceService, ServiceTypeDefinition } from "pmcf";
2
- import { serviceAddresses } from "../service.mjs";
1
+ import {
2
+ ExtraSourceService,
3
+ ServiceTypeDefinition,
4
+ serviceEndpoints
5
+ } from "pmcf";
3
6
  import { addType } from "../types.mjs";
4
7
 
5
8
  const SystemdResolvedServiceTypeDefinition = {
@@ -34,19 +37,22 @@ export class SystemdResolvedService extends ExtraSourceService {
34
37
  }
35
38
 
36
39
  systemdConfig(name) {
40
+ const options = priority => {
41
+ return {
42
+ services: { type: "dns", priority },
43
+ endpoints: e => e.networkInterface.kind !== "loopback",
44
+ select: endpoint => endpoint.address,
45
+ join: " "
46
+ };
47
+ };
48
+
37
49
  return {
38
50
  name: `etc/systemd/resolved.conf.d/${name}.conf`,
39
51
  content: [
40
52
  "Resolve",
41
53
  {
42
- DNS: serviceAddresses(this, {
43
- type: "dns",
44
- priority: "<10"
45
- }).join(" "),
46
- FallbackDNS: serviceAddresses(this, {
47
- type: "dns",
48
- priority: ">=10"
49
- }).join(" "),
54
+ DNS: serviceEndpoints(this, options("<10")),
55
+ FallbackDNS: serviceEndpoints(this, options(">=20")),
50
56
  Domains: [...this.localDomains].join(" "),
51
57
  DNSSEC: "no",
52
58
  MulticastDNS: this.network.multicastDNS ? "yes" : "no",
@@ -1,5 +1,8 @@
1
- import { ExtraSourceService, ServiceTypeDefinition } from "pmcf";
2
- import { serviceAddresses } from "../service.mjs";
1
+ import {
2
+ ExtraSourceService,
3
+ ServiceTypeDefinition,
4
+ serviceEndpoints
5
+ } from "pmcf";
3
6
  import { addType } from "../types.mjs";
4
7
 
5
8
  const SystemdTimesyncdServiceTypeDefinition = {
@@ -39,15 +42,16 @@ export class SystemdTimesyncdService extends ExtraSourceService {
39
42
  content: [
40
43
  "Time",
41
44
  {
42
- NTP: serviceAddresses(
43
- this,
44
- {
45
+ NTP: serviceEndpoints(this, {
46
+ services: {
45
47
  type: "ntp",
46
- priority: "<20"
48
+ priority: "<10"
47
49
  },
48
- "domainName",
49
- () => true
50
- ).join(" ")
50
+ endpoints: endpoint =>
51
+ endpoint.networkInterface.kind !== "loopback",
52
+ select: endpoint => endpoint.domainName,
53
+ join: " "
54
+ })
51
55
  }
52
56
  ]
53
57
  };
@@ -5,7 +5,16 @@ export class Endpoint {
5
5
  toString(): string;
6
6
  get socketAddress(): string;
7
7
  get hostName(): any;
8
+ get domainName(): any;
8
9
  get address(): any;
9
10
  get family(): any;
10
11
  get networkInterface(): any;
11
12
  }
13
+ export class DomainNameEndpoint {
14
+ constructor(service: any, domainName: any, data: any);
15
+ service: any;
16
+ domainName: any;
17
+ get networkInterface(): {};
18
+ get address(): any;
19
+ toString(): string;
20
+ }
@@ -7,6 +7,7 @@ export class SkeletonNetworkInterface extends ServiceOwner {
7
7
  get host(): Host;
8
8
  hosts(): Generator<any, void, any>;
9
9
  get network_interface(): this;
10
+ get domainName(): any;
10
11
  get domainNames(): Set<any>;
11
12
  matches(other: any): boolean;
12
13
  set network(network: any);
@@ -1,5 +1,4 @@
1
- export function serviceAddresses(sources: any, filter: any, addressType?: string, addressFilter?: (a: any) => boolean): any[];
2
- export function serviceEndpoints(sources: any, filter: any, endpointFilter: any): any[];
1
+ export function serviceEndpoints(sources: any, options?: {}): string | Set<any>;
3
2
  export namespace endpointProperties {
4
3
  export namespace port {
5
4
  let type: string;
@@ -257,8 +257,8 @@ export class SystemdResolvedService extends ExtraSourceService {
257
257
  systemdConfig(name: any): {
258
258
  name: string;
259
259
  content: (string | {
260
- DNS: string;
261
- FallbackDNS: string;
260
+ DNS: string | Set<any>;
261
+ FallbackDNS: string | Set<any>;
262
262
  Domains: string;
263
263
  DNSSEC: string;
264
264
  MulticastDNS: string;
@@ -257,7 +257,7 @@ export class SystemdTimesyncdService extends ExtraSourceService {
257
257
  systemdConfig(name: any): {
258
258
  name: string;
259
259
  content: (string | {
260
- NTP: string;
260
+ NTP: string | Set<any>;
261
261
  })[];
262
262
  };
263
263
  }