pmcf 1.98.1 → 1.99.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.98.1",
3
+ "version": "1.99.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -43,7 +43,7 @@
43
43
  "pkg-dir": "^8.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^22.13.13",
46
+ "@types/node": "^22.13.14",
47
47
  "ava": "^6.2.0",
48
48
  "c8": "^10.1.3",
49
49
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -179,9 +179,11 @@ export class Base {
179
179
  if (value instanceof property.type.clazz) {
180
180
  assign(property, value);
181
181
  } else {
182
+ const factory = property.type.factoryFor?.(value) || property.type.clazz;
183
+
182
184
  assign(
183
185
  property,
184
- new property.type.clazz(this.ownerFor(property, value), value)
186
+ new factory(this.ownerFor(property, value), value)
185
187
  );
186
188
  }
187
189
  break;
package/src/host.mjs CHANGED
@@ -103,22 +103,18 @@ export class Host extends Base {
103
103
  }
104
104
 
105
105
  _applyExtends(host) {
106
- /* this.depends = host.depends;
107
- this.provides = host.provides;
108
- this.replaces = host.replaces;
109
- */
110
106
  for (const service of host.services) {
111
107
  this.services = service.forOwner(this);
112
108
  }
113
109
 
114
110
  for (const [name, ni] of host.networkInterfaces) {
115
- const present = this.#networkInterfaces.get(name);
116
- if (present) {
117
- this.info("ALREADY THERE", name);
118
- } else {
119
- this.info("CLONE NI", name);
120
- this.#networkInterfaces.set(name, ni.forOwner(this));
111
+ let present = this.#networkInterfaces.get(name);
112
+ if (!present) {
113
+ present = ni.forOwner(this);
114
+ this.#networkInterfaces.set(name, present);
121
115
  }
116
+
117
+ present.extends.push(ni);
122
118
  }
123
119
  }
124
120
 
@@ -496,6 +492,7 @@ export class NetworkInterface extends Base {
496
492
  #network;
497
493
  #kind;
498
494
  #hostName;
495
+ extends = [];
499
496
  arpbridge;
500
497
  hwaddr;
501
498
 
package/src/location.mjs CHANGED
@@ -68,7 +68,7 @@ export class Location extends Owner {
68
68
  await writeLines(
69
69
  join(dir, "etc/systemd/resolved.conf.d"),
70
70
  `${this.name}.conf`,
71
- sectionLines(...this.dns.systemdConfig)
71
+ sectionLines(...this.findService({type: "dns"}).systemdConfig)
72
72
  );
73
73
 
74
74
  await writeLines(
@@ -84,7 +84,7 @@ export class Location extends Owner {
84
84
  await writeLines(
85
85
  join(dir, "etc/systemd/timesyncd.conf.d"),
86
86
  `${this.name}.conf`,
87
- sectionLines(...this.ntp.systemdConfig)
87
+ sectionLines(...this.findService({type: "ntp"}).systemdConfig)
88
88
  );
89
89
 
90
90
  const locationDir = join(dir, "etc", "location");
package/src/module.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from "./base.mjs";
2
2
  export * from "./service.mjs";
3
- export * from "./dns.mjs";
4
- export * from "./ntp.mjs";
5
- export * from "./dhcp.mjs";
3
+ export * from "./services/dns.mjs";
4
+ export * from "./services/ntp.mjs";
5
+ export * from "./services/dhcp.mjs";
6
6
  export * from "./cluster.mjs";
7
7
  export * from "./owner.mjs";
8
8
  export * from "./location.mjs";
package/src/owner.mjs CHANGED
@@ -2,9 +2,6 @@ import { asIterator, normalizeCIDR } from "./utils.mjs";
2
2
  import { Base } from "./base.mjs";
3
3
  import { Subnet } from "./subnet.mjs";
4
4
  import { addType, types } from "./types.mjs";
5
- import { DNSService } from "./dns.mjs";
6
- import { NTPService } from "./ntp.mjs";
7
- import { DHCPService } from "./dhcp.mjs";
8
5
 
9
6
  const OwnerTypeDefinition = {
10
7
  name: "owner",
@@ -16,21 +13,6 @@ const OwnerTypeDefinition = {
16
13
  hosts: { type: "host", collection: true, writeable: true },
17
14
  clusters: { type: "cluster", collection: true, writeable: true },
18
15
  subnets: { type: Subnet.typeDefinition, collection: true, writeable: true },
19
- dns: {
20
- type: DNSService.typeDefinition,
21
- collection: false,
22
- writeable: true
23
- },
24
- ntp: {
25
- type: NTPService.typeDefinition,
26
- collection: false,
27
- writeable: true
28
- },
29
- dhcp: {
30
- type: DHCPService.typeDefinition,
31
- collection: false,
32
- writeable: true
33
- },
34
16
 
35
17
  country: { type: "string", collection: false, writeable: true },
36
18
  domain: { type: "string", collection: false, writeable: true },
@@ -69,10 +51,6 @@ export class Owner extends Base {
69
51
  }
70
52
  }
71
53
 
72
- this.dns?._traverse(...args);
73
- this.ntp?._traverse(...args);
74
- this.dhcp?._traverse(...args);
75
-
76
54
  return true;
77
55
  }
78
56
 
package/src/service.mjs CHANGED
@@ -8,8 +8,10 @@ import {
8
8
  dnsFormatParameters,
9
9
  dnsMergeParameters
10
10
  } from "./dns-utils.mjs";
11
+ import { DHCPService, DNSService, NTPService } from "./module.mjs";
11
12
 
12
13
  const ServiceTypes = {
14
+ ntp: { protocol: "udp", port: 123, tls: false },
13
15
  dns: { protocol: "udp", port: 53, tls: false },
14
16
  ldap: { protocol: "tcp", port: 389, tls: false },
15
17
  ldaps: { protocol: "tcp", port: 636, tls: true },
@@ -46,18 +48,36 @@ const ServiceTypes = {
46
48
  parameters: {
47
49
  sys: "waMa=0",
48
50
  adVF: "0x100",
49
- dk0: "adVN=MF-TM-999",
50
- // adVF: "0x82"
51
+ dk0: "adVN=MF-TM-999"
52
+ // adVF: "0x82"
51
53
  }
52
54
  }
53
55
  }
54
56
  };
55
57
 
56
- const ServiceTypeDefinition = {
58
+ export const ServiceTypeDefinition = {
57
59
  name: "service",
58
60
  owners: ["host", "cluster"],
59
61
  priority: 0.4,
60
62
  extends: Base.typeDefinition,
63
+ factoryFor(value) {
64
+ const type = value.type || value.name;
65
+
66
+ if (type === "dns") {
67
+ delete value.type;
68
+ return DNSService;
69
+ }
70
+ if (type === "ntp") {
71
+ delete value.type;
72
+ return NTPService;
73
+ }
74
+ if (type === "dhcp") {
75
+ delete value.type;
76
+ return DHCPService;
77
+ }
78
+
79
+ return Service;
80
+ },
61
81
  properties: {
62
82
  ...networkAddressProperties,
63
83
  ipAddresses: { type: "string", collection: true, writeable: true },
@@ -126,6 +146,11 @@ export class Service extends Base {
126
146
  return this;
127
147
  }
128
148
 
149
+ get network()
150
+ {
151
+ return this.server.network;
152
+ }
153
+
129
154
  get server() {
130
155
  return this.owner;
131
156
  }
@@ -1,18 +1,21 @@
1
1
  import { join } from "node:path";
2
2
  import { FileContentProvider } from "npm-pkgbuild";
3
- import { Base } from "./base.mjs";
4
- import { addType } from "./types.mjs";
5
- import { writeLines } from "./utils.mjs";
6
- import { serviceAddresses } from "./service.mjs";
3
+ import {
4
+ Service,
5
+ ServiceTypeDefinition,
6
+ serviceAddresses
7
+ } from "../service.mjs";
8
+ import { addType } from "../types.mjs";
9
+ import { writeLines } from "../utils.mjs";
7
10
 
8
11
  const DHCPServiceTypeDefinition = {
9
12
  name: "dhcp",
10
- owners: ["location", "owner", "network", "cluster", "root"],
13
+ owners: ServiceTypeDefinition.owners,
11
14
  priority: 0.1,
12
15
  properties: {}
13
16
  };
14
17
 
15
- export class DHCPService extends Base {
18
+ export class DHCPService extends Service {
16
19
  static {
17
20
  addType(this);
18
21
  }
@@ -22,13 +25,12 @@ export class DHCPService extends Base {
22
25
  }
23
26
 
24
27
  constructor(owner, data) {
25
- if (!data.name) {
26
- data.name = DHCPServiceTypeDefinition.name; // TODO
27
- }
28
28
  super(owner, data);
29
29
  this.read(data, DHCPServiceTypeDefinition);
30
+ }
30
31
 
31
- owner.addObject(this);
32
+ get type() {
33
+ return DHCPServiceTypeDefinition.name;
32
34
  }
33
35
 
34
36
  async *preparePackages(dir) {
@@ -41,11 +43,15 @@ export class DHCPService extends Base {
41
43
  name: `kea-${name}`,
42
44
  description: `kea definitions for ${this.fullName}`,
43
45
  access: "private",
44
- dependencies: ["kea"]
46
+ dependencies: ["kea"],
47
+ replaces: ["kea-sw"] // TODO remove
45
48
  }
46
49
  };
47
50
 
48
51
  const commonConfig = {
52
+ "interfaces-config": {
53
+ interfaces: ["end0"]
54
+ },
49
55
  "lease-database": {
50
56
  type: "memfile",
51
57
  "lfc-interval": 3600
@@ -128,7 +134,7 @@ export class DHCPService extends Base {
128
134
  const hwmap = new Map();
129
135
  const hostNames = new Set();
130
136
 
131
- for await (const { networkInterface } of this.owner.networkAddresses()) {
137
+ for await (const { networkInterface } of this.network.networkAddresses()) {
132
138
  if (networkInterface.hwaddr) {
133
139
  if (!hostNames.has(networkInterface.hostName)) {
134
140
  hwmap.set(networkInterface.hwaddr, networkInterface);
@@ -148,9 +154,6 @@ export class DHCPService extends Base {
148
154
  const dhcp4 = {
149
155
  Dhcp4: {
150
156
  ...commonConfig,
151
- "interfaces-config": {
152
- interfaces: ["end0"]
153
- },
154
157
  "control-socket": {
155
158
  "socket-type": "unix",
156
159
  "socket-name": "/run/kea/4-ctrl-socket"
@@ -196,9 +199,6 @@ export class DHCPService extends Base {
196
199
  const dhcp6 = {
197
200
  Dhcp6: {
198
201
  ...commonConfig,
199
- "interfaces-config": {
200
- interfaces: []
201
- },
202
202
  "control-socket": {
203
203
  "socket-type": "unix",
204
204
  "socket-name": "/run/kea/6-ctrl-socket"
@@ -6,16 +6,19 @@ import {
6
6
  isIPv6Address,
7
7
  normalizeIPAddress,
8
8
  isLinkLocal
9
- } from "./utils.mjs";
10
- import { DNSRecord, dnsFullName } from "./dns-utils.mjs";
11
- import { Base } from "./base.mjs";
12
- import { addType } from "./types.mjs";
13
- import { serviceAddresses } from "./service.mjs";
14
- import { subnets } from "./subnet.mjs";
9
+ } from "../utils.mjs";
10
+ import { DNSRecord, dnsFullName } from "../dns-utils.mjs";
11
+ import { addType } from "../types.mjs";
12
+ import {
13
+ Service,
14
+ ServiceTypeDefinition,
15
+ serviceAddresses
16
+ } from "../service.mjs";
17
+ import { subnets } from "../subnet.mjs";
15
18
 
16
19
  const DNSServiceTypeDefinition = {
17
20
  name: "dns",
18
- owners: ["location", "owner", "network", "cluster", "root"],
21
+ owners: ServiceTypeDefinition.owners,
19
22
  priority: 0.1,
20
23
  properties: {
21
24
  source: { type: "network", collection: true, writeable: true },
@@ -58,7 +61,7 @@ function addressesStatement(prefix, objects, generateEmpty = false) {
58
61
  return [];
59
62
  }
60
63
 
61
- export class DNSService extends Base {
64
+ export class DNSService extends Service {
62
65
  allowedUpdates = [];
63
66
  recordTTL = "1W";
64
67
  hasSVRRecords = true;
@@ -85,13 +88,12 @@ export class DNSService extends Base {
85
88
  }
86
89
 
87
90
  constructor(owner, data) {
88
- if (!data.name) {
89
- data.name = DNSServiceTypeDefinition.name; // TODO
90
- }
91
91
  super(owner, data);
92
92
  this.read(data, DNSServiceTypeDefinition);
93
+ }
93
94
 
94
- owner.addObject(this);
95
+ get type() {
96
+ return DNSServiceTypeDefinition.name;
95
97
  }
96
98
 
97
99
  get soaUpdates() {
@@ -252,7 +254,9 @@ async function generateZoneDefs(dns, packageData) {
252
254
 
253
255
  const configs = [];
254
256
 
255
- for (const host of dns.owner.hosts()) {
257
+ const location = dns.location;
258
+
259
+ for (const host of location.hosts()) {
256
260
  for (const domain of host.foreignDomainNames) {
257
261
  const zone = {
258
262
  id: domain,
@@ -324,7 +328,7 @@ async function generateZoneDefs(dns, packageData) {
324
328
  subnet,
325
329
  networkInterface,
326
330
  domainNames
327
- } of dns.owner.networkAddresses()) {
331
+ } of location.networkAddresses()) {
328
332
  const host = networkInterface.host;
329
333
  if (
330
334
  !addresses.has(address) &&
@@ -379,12 +383,12 @@ async function generateZoneDefs(dns, packageData) {
379
383
 
380
384
  for (const service of host.findServices()) {
381
385
  //for (const domainName of domainNames) {
382
- for (const record of service.dnsRecordsForDomainName(
383
- host.domainName,
384
- dns.hasSVRRecords
385
- )) {
386
- zone.records.add(record);
387
- }
386
+ for (const record of service.dnsRecordsForDomainName(
387
+ host.domainName,
388
+ dns.hasSVRRecords
389
+ )) {
390
+ zone.records.add(record);
391
+ }
388
392
  //}
389
393
  }
390
394
  }
@@ -1,10 +1,13 @@
1
- import { Base } from "./base.mjs";
2
- import { addType } from "./types.mjs";
3
- import { serviceAddresses } from "./service.mjs";
1
+ import { addType } from "../types.mjs";
2
+ import {
3
+ Service,
4
+ ServiceTypeDefinition,
5
+ serviceAddresses
6
+ } from "../service.mjs";
4
7
 
5
8
  const NTPServiceTypeDefinition = {
6
9
  name: "ntp",
7
- owners: ["location", "owner", "network", "cluster", "root"],
10
+ owners: ServiceTypeDefinition.owners,
8
11
  priority: 0.1,
9
12
  properties: {
10
13
  source: { type: "network", collection: true, writeable: true }
@@ -13,7 +16,7 @@ const NTPServiceTypeDefinition = {
13
16
 
14
17
  const NTP_SERVICE_FILTER = { type: NTPServiceTypeDefinition.name };
15
18
 
16
- export class NTPService extends Base {
19
+ export class NTPService extends Service {
17
20
  #source = [];
18
21
 
19
22
  static {
@@ -25,13 +28,12 @@ export class NTPService extends Base {
25
28
  }
26
29
 
27
30
  constructor(owner, data) {
28
- if (!data.name) {
29
- data.name = NTPServiceTypeDefinition.name; // TODO
30
- }
31
31
  super(owner, data);
32
32
  this.read(data, NTPServiceTypeDefinition);
33
+ }
33
34
 
34
- owner.addObject(this);
35
+ get type() {
36
+ return NTPServiceTypeDefinition.name;
35
37
  }
36
38
 
37
39
  set source(value) {
@@ -91,118 +91,6 @@ export class Cluster extends Host {
91
91
  collection: boolean;
92
92
  writeable: boolean;
93
93
  };
94
- dns: {
95
- type: {
96
- name: string;
97
- owners: string[];
98
- priority: number;
99
- properties: {
100
- source: {
101
- type: string;
102
- collection: boolean;
103
- writeable: boolean;
104
- };
105
- trusted: {
106
- type: string;
107
- collection: boolean;
108
- writeable: boolean;
109
- };
110
- protected: {
111
- type: string;
112
- collection: boolean;
113
- writeable: boolean;
114
- };
115
- open: {
116
- type: string;
117
- collection: boolean;
118
- writeable: boolean;
119
- };
120
- hasSVRRecords: {
121
- type: string;
122
- collection: boolean;
123
- writeable: boolean;
124
- };
125
- hasCatalog: {
126
- type: string;
127
- collection: boolean;
128
- writeable: boolean;
129
- };
130
- hasLinkLocalAdresses: {
131
- type: string;
132
- collection: boolean;
133
- writeable: boolean;
134
- };
135
- notify: {
136
- type: string;
137
- collection: boolean;
138
- writeable: boolean;
139
- };
140
- recordTTL: {
141
- type: string;
142
- collection: boolean;
143
- writeable: boolean;
144
- };
145
- serial: {
146
- type: string;
147
- collection: boolean;
148
- writeable: boolean;
149
- };
150
- refresh: {
151
- type: string;
152
- collection: boolean;
153
- writeable: boolean;
154
- };
155
- retry: {
156
- type: string;
157
- collection: boolean;
158
- writeable: boolean;
159
- };
160
- expire: {
161
- type: string;
162
- collection: boolean;
163
- writeable: boolean;
164
- };
165
- minimum: {
166
- type: string;
167
- collection: boolean;
168
- writeable: boolean;
169
- };
170
- allowedUpdates: {
171
- type: string;
172
- collection: boolean;
173
- writeable: boolean;
174
- };
175
- };
176
- };
177
- collection: boolean;
178
- writeable: boolean;
179
- };
180
- ntp: {
181
- type: {
182
- name: string;
183
- owners: string[];
184
- priority: number;
185
- properties: {
186
- source: {
187
- type: string;
188
- collection: boolean;
189
- writeable: boolean;
190
- };
191
- };
192
- };
193
- collection: boolean;
194
- writeable: boolean;
195
- };
196
- dhcp: {
197
- type: {
198
- name: string;
199
- owners: string[];
200
- priority: number;
201
- properties: {};
202
- };
203
- collection: boolean;
204
- writeable: boolean;
205
- };
206
94
  country: {
207
95
  type: string;
208
96
  collection: boolean;
package/types/host.d.mts CHANGED
@@ -378,6 +378,7 @@ export class NetworkInterface extends Base {
378
378
  };
379
379
  };
380
380
  };
381
+ extends: any[];
381
382
  arpbridge: any;
382
383
  hwaddr: any;
383
384
  addSubnet(address: any): any;