pmcf 2.38.0 → 2.38.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.38.0",
3
+ "version": "2.38.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/cluster.mjs CHANGED
@@ -2,6 +2,7 @@ import { join } from "node:path";
2
2
  import { FileContentProvider } from "npm-pkgbuild";
3
3
  import { Owner } from "./owner.mjs";
4
4
  import { Host } from "./host.mjs";
5
+ import { serviceEndpoints } from "pmcf";
5
6
  import { addType } from "./types.mjs";
6
7
  import { writeLines } from "./utils.mjs";
7
8
 
@@ -139,20 +140,25 @@ export class Cluster extends Host {
139
140
  cfg.push("}");
140
141
  cfg.push("");
141
142
 
142
- for (const service of cluster.findServices({ type: "http" })) {
143
- cfg.push(`virtual_server ${cluster.address} ${service.port} {`);
143
+ for (const endpoint of serviceEndpoints(cluster, {
144
+ services: { type: "http" },
145
+ endpoints: e => e.networkInterface.kind !== "loopback"
146
+ })) {
147
+ cfg.push(`virtual_server ${cluster.address} ${endpoint.port} {`);
144
148
  cfg.push(` delay_loop ${cluster.checkInterval}`);
145
149
  cfg.push(" lb_algo wlc");
146
150
  cfg.push(" persistence_timeout 600");
147
- cfg.push(` protocol ${service.protocol.toUpperCase()}`);
151
+ cfg.push(` protocol ${endpoint.protocol.toUpperCase()}`);
148
152
 
149
153
  for (const member of this.members) {
150
- const memberService = member.findService({ type: service.type }) || member.host.findService({ type: service.type }); // TODO
154
+ const memberService =
155
+ member.findService({ type: endpoint.type }) ||
156
+ member.host.findService({ type: endpoint.type }); // TODO
151
157
 
152
158
  cfg.push(` real_server ${member.address} ${memberService.port} {`);
153
159
  cfg.push(` weight ${memberService.weight}`);
154
160
 
155
- switch (service.type) {
161
+ switch (endpoint.type) {
156
162
  case "dns":
157
163
  cfg.push(` DNS_CHECK {`);
158
164
  cfg.push(" type A");
@@ -165,7 +171,7 @@ export class Cluster extends Host {
165
171
  break;
166
172
 
167
173
  default:
168
- switch (service.protocol) {
174
+ switch (endpoint.protocol) {
169
175
  case "tcp":
170
176
  cfg.push(` TCP_CHECK {`);
171
177
  cfg.push(" connect_timeout 10");
package/src/endpoint.mjs CHANGED
@@ -1,12 +1,37 @@
1
- export class Endpoint {
2
- constructor(service, networkAddress, data) {
1
+ class _Endpoint {
2
+ #port;
3
+ #type;
4
+ constructor(service, data) {
3
5
  this.service = service;
4
- this.networkAddress = networkAddress;
6
+ if (data.port) {
7
+ this.#port = data.port;
8
+ delete data.port;
9
+ }
10
+
11
+ if (data.type) {
12
+ this.#type = data.type;
13
+ delete data.type;
14
+ }
5
15
  Object.assign(this, data);
6
16
  }
7
17
 
18
+ get type() {
19
+ return this.#type ?? this.service.type;
20
+ }
21
+
22
+ get port() {
23
+ return this.#port ?? this.service._port;
24
+ }
25
+
8
26
  toString() {
9
- return `${this.address}[${this.port}]`;
27
+ return `${this.type}/${this.address}[${this.port}]`;
28
+ }
29
+ }
30
+
31
+ export class Endpoint extends _Endpoint {
32
+ constructor(service, networkAddress, data) {
33
+ super(service, data);
34
+ this.networkAddress = networkAddress;
10
35
  }
11
36
 
12
37
  get socketAddress() {
@@ -34,11 +59,10 @@ export class Endpoint {
34
59
  }
35
60
  }
36
61
 
37
- export class DomainNameEndpoint {
62
+ export class DomainNameEndpoint extends _Endpoint {
38
63
  constructor(service, domainName, data) {
39
- this.service = service;
64
+ super(service, data);
40
65
  this.domainName = domainName;
41
- Object.assign(this, data);
42
66
  }
43
67
 
44
68
  get networkInterface() {
@@ -48,17 +72,15 @@ export class DomainNameEndpoint {
48
72
  get address() {
49
73
  return this.domainName;
50
74
  }
51
-
52
- toString() {
53
- return `${this.address}[${this.port}]`;
54
- }
55
75
  }
56
76
 
57
- export class HTTPEndpoint {
77
+ export class HTTPEndpoint extends _Endpoint {
58
78
  constructor(service, url, data) {
59
- this.service = service;
79
+ super(service, data);
60
80
  this.url = url;
61
- Object.assign(this, data);
62
81
  }
63
82
 
64
- }
83
+ get address() {
84
+ return this.url;
85
+ }
86
+ }
package/src/owner.mjs CHANGED
@@ -175,10 +175,6 @@ export class Owner extends Base {
175
175
  yield* this.owner.subnets();
176
176
  }
177
177
  yield* this.typeList("subnet");
178
-
179
- /* for (const network of this.networks()) {
180
- yield* network.subnets();
181
- }*/
182
178
  }
183
179
 
184
180
  addSubnet(address) {
package/src/service.mjs CHANGED
@@ -24,7 +24,6 @@ const ServiceTypes = {
24
24
  },
25
25
  http3: {
26
26
  extends: ["https"],
27
- type: "https",
28
27
  dnsRecord: {
29
28
  type: "HTTPS",
30
29
  parameters: { "no-default-alpn": undefined, alpn: "h3" }
@@ -48,7 +47,6 @@ const ServiceTypes = {
48
47
  "dhcpv6-server": { endpoints: [{ port: 547, tls: false }] },
49
48
  smb: { endpoints: [{ protocol: "tcp", port: 445, tls: false }] },
50
49
  timemachine: {
51
- type: "adisk",
52
50
  extends: ["smb"],
53
51
  endpoints: [{ protocol: "tcp", port: 445, tls: false }],
54
52
  dnsRecord: {
@@ -68,13 +66,19 @@ function serviceTypeEndpoints(type) {
68
66
  if (st) {
69
67
  if (st.extends) {
70
68
  return st.extends.reduce(
71
- (a, c) => [...a, ...(ServiceTypes[c]?.endpoints||[])],
69
+ (a, c) => [...a, ...(ServiceTypes[c]?.endpoints || [])],
72
70
  st.endpoints || []
73
71
  );
74
72
  }
75
73
 
76
74
  return st.endpoints;
77
75
  }
76
+
77
+ return [
78
+ {
79
+ tls: false
80
+ }
81
+ ];
78
82
  }
79
83
 
80
84
  export const endpointProperties = {
@@ -96,7 +100,7 @@ export const endpointProperties = {
96
100
 
97
101
  export const EndpointTypeDefinition = {
98
102
  name: "endpoint",
99
- owners: ["service", "network-interface"],
103
+ owners: ["service", "network_interface"],
100
104
  priority: 0.4,
101
105
  specializations: {},
102
106
  properties: endpointProperties
@@ -149,6 +153,10 @@ export class Service extends Base {
149
153
  this.read(data, ServiceTypeDefinition);
150
154
  }
151
155
 
156
+ toString() {
157
+ return `${this.type}`;
158
+ }
159
+
152
160
  set extends(value) {
153
161
  this._extends.push(value);
154
162
  }
@@ -184,32 +192,16 @@ export class Service extends Base {
184
192
  }
185
193
 
186
194
  endpoints(filter) {
187
- const local =
188
- this._port === undefined
189
- ? { type: this.type }
190
- : { type: this.type, port: this._port };
191
-
192
- const data = serviceTypeEndpoints(this.type) || [
193
- {
194
- tls: false
195
- }
196
- ];
195
+ const data = serviceTypeEndpoints(this.type);
197
196
 
197
+ const l = this._port === undefined ? {} : { port: this._port };
198
198
  let result = [...this.host.networkAddresses()]
199
- .map(na =>
200
- data.map(
201
- d =>
202
- new Endpoint(this, na, {
203
- ...d,
204
- ...local
205
- })
206
- )
207
- )
199
+ .map(na => data.map(d => new Endpoint(this, na, { ...d, ...l })))
208
200
  .flat();
209
201
 
210
202
  if (result.length === 0) {
211
203
  result = data.map(
212
- d => new DomainNameEndpoint(this, this.domainName, { ...d, ...local })
204
+ d => new DomainNameEndpoint(this, this.domainName, { ...d, ...l })
213
205
  );
214
206
  }
215
207
 
@@ -229,7 +221,7 @@ export class Service extends Base {
229
221
  }
230
222
 
231
223
  get port() {
232
- return this.endpoints()[0].port;
224
+ return this._port ?? this.endpoints()[0].port;
233
225
  }
234
226
 
235
227
  set weight(value) {
@@ -264,11 +256,7 @@ export class Service extends Base {
264
256
  )) {
265
257
  records.push(
266
258
  DNSRecord(
267
- dnsFullName(
268
- `_${ServiceTypes[this.type]?.type ?? this.type}._${
269
- ep.protocol
270
- }.${domainName}`
271
- ),
259
+ dnsFullName(`_${this.type}._${ep.protocol}.${domainName}`),
272
260
  "SRV",
273
261
  this.priority ?? 10,
274
262
  this.weight,
@@ -305,7 +293,12 @@ export class Service extends Base {
305
293
  );
306
294
  } else {
307
295
  records.push(
308
- DNSRecord("@", dnsRecord.type, this.priority ?? 10, dnsFullName(domainName))
296
+ DNSRecord(
297
+ "@",
298
+ dnsRecord.type,
299
+ this.priority ?? 10,
300
+ dnsFullName(domainName)
301
+ )
309
302
  );
310
303
  }
311
304
  }
@@ -317,9 +310,9 @@ export class Service extends Base {
317
310
  export const sortByPriority = (a, b) => a.priority - b.priority;
318
311
 
319
312
  /**
320
- *
321
- * @param {*} sources
322
- * @param {Object} [options]
313
+ *
314
+ * @param {*} sources
315
+ * @param {Object} [options]
323
316
  * @param {Function} [options.services] filter for services
324
317
  * @param {Function} [options.endpoints] filter for endpoints
325
318
  * @param {Function} [options.select] mapper from Endpoint into result
@@ -1,8 +1,6 @@
1
- export class Endpoint {
1
+ export class Endpoint extends _Endpoint {
2
2
  constructor(service: any, networkAddress: any, data: any);
3
- service: any;
4
3
  networkAddress: any;
5
- toString(): string;
6
4
  get socketAddress(): string;
7
5
  get hostName(): any;
8
6
  get domainName(): any;
@@ -10,16 +8,23 @@ export class Endpoint {
10
8
  get family(): any;
11
9
  get networkInterface(): any;
12
10
  }
13
- export class DomainNameEndpoint {
11
+ export class DomainNameEndpoint extends _Endpoint {
14
12
  constructor(service: any, domainName: any, data: any);
15
- service: any;
16
13
  domainName: any;
17
14
  get networkInterface(): {};
18
15
  get address(): any;
19
- toString(): string;
20
16
  }
21
- export class HTTPEndpoint {
17
+ export class HTTPEndpoint extends _Endpoint {
22
18
  constructor(service: any, url: any, data: any);
23
- service: any;
24
19
  url: any;
20
+ get address(): any;
21
+ }
22
+ declare class _Endpoint {
23
+ constructor(service: any, data: any);
24
+ service: any;
25
+ get type(): any;
26
+ get port(): any;
27
+ toString(): string;
28
+ #private;
25
29
  }
30
+ export {};