pmcf 2.37.2 → 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/README.md +17 -0
- package/package.json +1 -1
- package/src/cluster.mjs +12 -6
- package/src/endpoint.mjs +37 -15
- package/src/owner.mjs +0 -4
- package/src/service.mjs +27 -42
- package/src/services/dns.mjs +4 -5
- package/types/endpoint.d.mts +13 -8
- package/types/service.d.mts +0 -2
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
* [subnet](#subnet)
|
|
28
28
|
* [networkInterface](#networkinterface)
|
|
29
29
|
* [address](#address)
|
|
30
|
+
* [serviceEndpoints](#serviceendpoints)
|
|
31
|
+
* [Parameters](#parameters-2)
|
|
30
32
|
|
|
31
33
|
## networkAddresses
|
|
32
34
|
|
|
@@ -56,6 +58,21 @@ Type: NetworkInterface
|
|
|
56
58
|
|
|
57
59
|
Type: ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Uint8Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | [Uint16Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array))
|
|
58
60
|
|
|
61
|
+
## serviceEndpoints
|
|
62
|
+
|
|
63
|
+
### Parameters
|
|
64
|
+
|
|
65
|
+
* `sources` **any** 
|
|
66
|
+
* `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`)
|
|
67
|
+
|
|
68
|
+
* `options.services` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** filter for services
|
|
69
|
+
* `options.endpoints` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** filter for endpoints
|
|
70
|
+
* `options.select` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** mapper from Endpoint into result
|
|
71
|
+
* `options.limit` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** upper limit of # result items
|
|
72
|
+
* `options.join` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** jount result into a string
|
|
73
|
+
|
|
74
|
+
Returns **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | any)** 
|
|
75
|
+
|
|
59
76
|
# install
|
|
60
77
|
|
|
61
78
|
With [npm](http://npmjs.org) do:
|
package/package.json
CHANGED
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
|
|
143
|
-
|
|
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 ${
|
|
151
|
+
cfg.push(` protocol ${endpoint.protocol.toUpperCase()}`);
|
|
148
152
|
|
|
149
153
|
for (const member of this.members) {
|
|
150
|
-
const memberService =
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
class _Endpoint {
|
|
2
|
+
#port;
|
|
3
|
+
#type;
|
|
4
|
+
constructor(service, data) {
|
|
3
5
|
this.service = service;
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
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", "
|
|
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
|
|
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, ...
|
|
204
|
+
d => new DomainNameEndpoint(this, this.domainName, { ...d, ...l })
|
|
213
205
|
);
|
|
214
206
|
}
|
|
215
207
|
|
|
@@ -229,15 +221,7 @@ export class Service extends Base {
|
|
|
229
221
|
}
|
|
230
222
|
|
|
231
223
|
get port() {
|
|
232
|
-
return this.endpoints()[0].port;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
get protocol() {
|
|
236
|
-
return this.endpoints()[0].protocol;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
get tls() {
|
|
240
|
-
return this.endpoints()[0].tls;
|
|
224
|
+
return this._port ?? this.endpoints()[0].port;
|
|
241
225
|
}
|
|
242
226
|
|
|
243
227
|
set weight(value) {
|
|
@@ -272,11 +256,7 @@ export class Service extends Base {
|
|
|
272
256
|
)) {
|
|
273
257
|
records.push(
|
|
274
258
|
DNSRecord(
|
|
275
|
-
dnsFullName(
|
|
276
|
-
`_${ServiceTypes[this.type]?.type ?? this.type}._${
|
|
277
|
-
ep.protocol
|
|
278
|
-
}.${domainName}`
|
|
279
|
-
),
|
|
259
|
+
dnsFullName(`_${this.type}._${ep.protocol}.${domainName}`),
|
|
280
260
|
"SRV",
|
|
281
261
|
this.priority ?? 10,
|
|
282
262
|
this.weight,
|
|
@@ -313,7 +293,12 @@ export class Service extends Base {
|
|
|
313
293
|
);
|
|
314
294
|
} else {
|
|
315
295
|
records.push(
|
|
316
|
-
DNSRecord(
|
|
296
|
+
DNSRecord(
|
|
297
|
+
"@",
|
|
298
|
+
dnsRecord.type,
|
|
299
|
+
this.priority ?? 10,
|
|
300
|
+
dnsFullName(domainName)
|
|
301
|
+
)
|
|
317
302
|
);
|
|
318
303
|
}
|
|
319
304
|
}
|
|
@@ -325,9 +310,9 @@ export class Service extends Base {
|
|
|
325
310
|
export const sortByPriority = (a, b) => a.priority - b.priority;
|
|
326
311
|
|
|
327
312
|
/**
|
|
328
|
-
*
|
|
329
|
-
* @param {*} sources
|
|
330
|
-
* @param {Object} [options]
|
|
313
|
+
*
|
|
314
|
+
* @param {*} sources
|
|
315
|
+
* @param {Object} [options]
|
|
331
316
|
* @param {Function} [options.services] filter for services
|
|
332
317
|
* @param {Function} [options.endpoints] filter for endpoints
|
|
333
318
|
* @param {Function} [options.select] mapper from Endpoint into result
|
package/src/services/dns.mjs
CHANGED
|
@@ -335,11 +335,10 @@ async function generateZoneDefs(dns, location, packageData) {
|
|
|
335
335
|
addHook(
|
|
336
336
|
packageData.properties.hooks,
|
|
337
337
|
"post_upgrade",
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
.join(" ")}|/usr/bin/named-hostname-update`
|
|
338
|
+
`rm -f ${foreignZones.map(zone => `/var/lib/named/${zone.file}.jnl`)}\n` +
|
|
339
|
+
`/usr/bin/named-hostname-info ${foreignZones
|
|
340
|
+
.map(zone => zone.id)
|
|
341
|
+
.join(" ")}|/usr/bin/named-hostname-update`
|
|
343
342
|
);
|
|
344
343
|
}
|
|
345
344
|
|
package/types/endpoint.d.mts
CHANGED
|
@@ -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 {};
|
package/types/service.d.mts
CHANGED