pmcf 1.40.0 → 1.41.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 +1 -1
- package/src/cluster.mjs +5 -0
- package/src/cmd.mjs +1 -1
- package/src/dns.mjs +5 -0
- package/src/{model.mjs → host.mjs} +12 -147
- package/src/location.mjs +39 -0
- package/src/module.mjs +6 -1
- package/src/network.mjs +102 -0
- package/src/owner.mjs +8 -166
- package/src/root.mjs +96 -0
- package/src/service.mjs +5 -0
- package/src/subnet.mjs +76 -0
- package/src/types.mjs +7 -0
- package/types/cmd.d.mts +1 -1
- package/types/{model.d.mts → host.d.mts} +1 -19
- package/types/location.d.mts +4 -0
- package/types/module.d.mts +6 -1
- package/types/network.d.mts +13 -0
- package/types/owner.d.mts +0 -21
- package/types/root.d.mts +8 -0
- package/types/subnet.d.mts +10 -0
- package/types/types.d.mts +3 -0
package/package.json
CHANGED
package/src/cluster.mjs
CHANGED
package/src/cmd.mjs
CHANGED
package/src/dns.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Base } from "./base.mjs";
|
|
2
2
|
import { asArray } from "./utils.mjs";
|
|
3
|
+
import { addType } from "./types.mjs";
|
|
3
4
|
|
|
4
5
|
export class DNSService extends Base {
|
|
5
6
|
allowedUpdates = [];
|
|
@@ -10,6 +11,10 @@ export class DNSService extends Base {
|
|
|
10
11
|
|
|
11
12
|
forwardsTo = [];
|
|
12
13
|
|
|
14
|
+
static {
|
|
15
|
+
addType(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
static get typeName() {
|
|
14
19
|
return "dns";
|
|
15
20
|
}
|
|
@@ -1,143 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Base } from "./base.mjs";
|
|
2
|
+
import { Network } from "./network.mjs";
|
|
3
|
+
import { Service } from "./service.mjs";
|
|
3
4
|
import {
|
|
4
5
|
asArray,
|
|
5
6
|
isIPv4Address,
|
|
6
7
|
isIPv6Address,
|
|
7
8
|
normalizeIPAddress
|
|
8
9
|
} from "./utils.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { Owner, Network, Subnet } from "./owner.mjs";
|
|
11
|
-
import { Service } from "./service.mjs";
|
|
12
|
-
import { Cluster } from "./cluster.mjs";
|
|
13
|
-
import { DNSService } from "./dns.mjs";
|
|
14
|
-
|
|
15
|
-
export class Location extends Owner {
|
|
16
|
-
static get typeName() {
|
|
17
|
-
return "location";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get location() {
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
locationNamed(name) {
|
|
25
|
-
if (this.fullName === name) {
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return super.locationNamed(name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get network() {
|
|
33
|
-
return [...this.typeList("network")][0] || super.network;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/*
|
|
37
|
-
*subnets() {
|
|
38
|
-
// yield* super.subnets();
|
|
39
|
-
|
|
40
|
-
for(const network of this.networks()) {
|
|
41
|
-
// console.log(network.toString());
|
|
42
|
-
yield* network.typeList("subnet");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
*/
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class Root extends Location {
|
|
49
|
-
static get types() {
|
|
50
|
-
return _typesByName;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static get typeName() {
|
|
54
|
-
return "root";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
constructor(directory) {
|
|
58
|
-
super(undefined, { name: "" });
|
|
59
|
-
this.directory = directory;
|
|
60
|
-
this.addObject(this);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get types() {
|
|
64
|
-
return this.constructor.types;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get fullName() {
|
|
68
|
-
return "";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get root() {
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async load(name, options) {
|
|
76
|
-
const fullName = Base.normalizeName(name);
|
|
77
|
-
let object = this.named(fullName);
|
|
78
|
-
if (object) {
|
|
79
|
-
return object;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//console.log("LOAD", fullName);
|
|
83
|
-
|
|
84
|
-
let path = fullName.split("/");
|
|
85
|
-
path.pop();
|
|
86
|
-
|
|
87
|
-
let data;
|
|
88
|
-
let type = options?.type;
|
|
89
|
-
if (type) {
|
|
90
|
-
data = JSON.parse(
|
|
91
|
-
await readFile(
|
|
92
|
-
join(this.directory, fullName, type.typeFileName),
|
|
93
|
-
"utf8"
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
} else {
|
|
97
|
-
for (type of _types) {
|
|
98
|
-
try {
|
|
99
|
-
data = JSON.parse(
|
|
100
|
-
await readFile(
|
|
101
|
-
join(this.directory, fullName, type.typeFileName),
|
|
102
|
-
"utf8"
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
break;
|
|
106
|
-
} catch {}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!data) {
|
|
110
|
-
return this.load(path.join("/"), options);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const owner = await this.load(path.join("/"));
|
|
115
|
-
|
|
116
|
-
const length = owner.fullName.length;
|
|
117
|
-
const n = fullName[length] === "/" ? length + 1 : length;
|
|
118
|
-
data.name = fullName.substring(n);
|
|
119
|
-
|
|
120
|
-
type = await type.prepareData(this, data);
|
|
121
|
-
|
|
122
|
-
object = new type(owner, data);
|
|
123
|
-
|
|
124
|
-
this._addObject(type.typeName, fullName, object);
|
|
125
|
-
|
|
126
|
-
return object;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async loadAll() {
|
|
130
|
-
for (let type of Object.values(Root.types)) {
|
|
131
|
-
for await (const name of glob(type.fileNameGlob, {
|
|
132
|
-
cwd: this.directory
|
|
133
|
-
})) {
|
|
134
|
-
await this.load(name, { type });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
this.execFinalize();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
10
|
+
import { addType } from "./types.mjs";
|
|
141
11
|
|
|
142
12
|
export class Host extends Base {
|
|
143
13
|
postinstall = [];
|
|
@@ -154,6 +24,10 @@ export class Host extends Base {
|
|
|
154
24
|
#chassis;
|
|
155
25
|
#vendor;
|
|
156
26
|
|
|
27
|
+
static {
|
|
28
|
+
addType(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
157
31
|
static get typeName() {
|
|
158
32
|
return "host";
|
|
159
33
|
}
|
|
@@ -433,6 +307,10 @@ export class Host extends Base {
|
|
|
433
307
|
}
|
|
434
308
|
|
|
435
309
|
export class NetworkInterface extends Base {
|
|
310
|
+
static {
|
|
311
|
+
addType(this);
|
|
312
|
+
}
|
|
313
|
+
|
|
436
314
|
static get typeName() {
|
|
437
315
|
return "network_interface";
|
|
438
316
|
}
|
|
@@ -614,16 +492,3 @@ export class NetworkInterface extends Base {
|
|
|
614
492
|
];
|
|
615
493
|
}
|
|
616
494
|
}
|
|
617
|
-
|
|
618
|
-
const _types = [
|
|
619
|
-
Owner,
|
|
620
|
-
Location,
|
|
621
|
-
Network,
|
|
622
|
-
Subnet,
|
|
623
|
-
Host,
|
|
624
|
-
Cluster,
|
|
625
|
-
Service,
|
|
626
|
-
DNSService,
|
|
627
|
-
NetworkInterface
|
|
628
|
-
];
|
|
629
|
-
const _typesByName = Object.fromEntries(_types.map(t => [t.typeName, t]));
|
package/src/location.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Owner } from "./owner.mjs";
|
|
2
|
+
import { addType } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
export class Location extends Owner {
|
|
5
|
+
static {
|
|
6
|
+
addType(this);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get typeName() {
|
|
10
|
+
return "location";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get location() {
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
locationNamed(name) {
|
|
18
|
+
if (this.fullName === name) {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return super.locationNamed(name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get network() {
|
|
26
|
+
return [...this.typeList("network")][0] || super.network;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
*subnets() {
|
|
31
|
+
// yield* super.subnets();
|
|
32
|
+
|
|
33
|
+
for(const network of this.networks()) {
|
|
34
|
+
// console.log(network.toString());
|
|
35
|
+
yield* network.typeList("subnet");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
*/
|
|
39
|
+
}
|
package/src/module.mjs
CHANGED
|
@@ -3,4 +3,9 @@ export * from "./service.mjs";
|
|
|
3
3
|
export * from "./dns.mjs";
|
|
4
4
|
export * from "./cluster.mjs";
|
|
5
5
|
export * from "./owner.mjs";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./location.mjs";
|
|
7
|
+
export * from "./root.mjs";
|
|
8
|
+
export * from "./subnet.mjs";
|
|
9
|
+
export * from "./network.mjs";
|
|
10
|
+
export * from "./host.mjs";
|
|
11
|
+
export * from "./types.mjs";
|
package/src/network.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Owner } from "./owner.mjs";
|
|
2
|
+
import { asArray } from "./utils.mjs";
|
|
3
|
+
import { addType } from "./types.mjs";
|
|
4
|
+
|
|
5
|
+
export class Network extends Owner {
|
|
6
|
+
kind;
|
|
7
|
+
scope;
|
|
8
|
+
metric;
|
|
9
|
+
gateway;
|
|
10
|
+
#bridge;
|
|
11
|
+
|
|
12
|
+
static {
|
|
13
|
+
addType(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static get typeName() {
|
|
17
|
+
return "network";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor(owner, data) {
|
|
21
|
+
super(owner, data);
|
|
22
|
+
|
|
23
|
+
if (data.subnets) {
|
|
24
|
+
this.addSubnets(data.subnets);
|
|
25
|
+
delete data.subnets;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (data.bridge) {
|
|
29
|
+
this.bridge = owner.addBridge(this, data.bridge);
|
|
30
|
+
delete data.bridge;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Object.assign(this, data);
|
|
34
|
+
|
|
35
|
+
if (typeof this.gateway === "string") {
|
|
36
|
+
this.finalize(() => (this.gateway = this.owner.hostNamed(this.gateway)));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get network() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
networkNamed(name) {
|
|
45
|
+
if (this.fullName === name) {
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
return super.networkNamed(name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
addSubnets(value) {
|
|
52
|
+
for (const address of asArray(value)) {
|
|
53
|
+
const subnet = this.addSubnet(address);
|
|
54
|
+
subnet.networks.add(this);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get bridge() {
|
|
59
|
+
return this.#bridge;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set bridge(bridge) {
|
|
63
|
+
for (const network of bridge) {
|
|
64
|
+
if (network instanceof Network && network !== this) {
|
|
65
|
+
for (const subnet of this.subnets()) {
|
|
66
|
+
for (const otherSubnet of network.subnets()) {
|
|
67
|
+
if (
|
|
68
|
+
subnet !== otherSubnet &&
|
|
69
|
+
subnet.address === otherSubnet.address
|
|
70
|
+
) {
|
|
71
|
+
/*console.log(
|
|
72
|
+
"SHARE SUBNETS",
|
|
73
|
+
subnet.owner.toString(),
|
|
74
|
+
otherSubnet.owner.toString()
|
|
75
|
+
);*/
|
|
76
|
+
|
|
77
|
+
otherSubnet.owner.addObject(subnet);
|
|
78
|
+
for (const n of otherSubnet.networks) {
|
|
79
|
+
subnet.networks.add(n);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//console.log(subnet.toString(),[...subnet.networks].map(n=>n.toString()));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.#bridge = bridge;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get propertyNames() {
|
|
93
|
+
return [
|
|
94
|
+
...super.propertyNames,
|
|
95
|
+
"kind",
|
|
96
|
+
"scope",
|
|
97
|
+
"metric",
|
|
98
|
+
"bridge",
|
|
99
|
+
"gateway"
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/owner.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { asArray, normalizeCIDR
|
|
1
|
+
import { asArray, normalizeCIDR } from "./utils.mjs";
|
|
2
2
|
import { Base } from "./base.mjs";
|
|
3
|
+
import { Subnet } from "./subnet.mjs";
|
|
3
4
|
import { DNSService } from "./dns.mjs";
|
|
5
|
+
import { addType, typesByName } from "./types.mjs";
|
|
4
6
|
|
|
5
7
|
export class Owner extends Base {
|
|
6
8
|
#membersByType = new Map();
|
|
@@ -10,6 +12,10 @@ export class Owner extends Base {
|
|
|
10
12
|
domain;
|
|
11
13
|
ntp = { servers: [] };
|
|
12
14
|
|
|
15
|
+
static {
|
|
16
|
+
addType(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
static get typeName() {
|
|
14
20
|
return "owner";
|
|
15
21
|
}
|
|
@@ -46,7 +52,7 @@ export class Owner extends Base {
|
|
|
46
52
|
|
|
47
53
|
for (const [name, data] of Object.entries(networks)) {
|
|
48
54
|
data.name = name;
|
|
49
|
-
new
|
|
55
|
+
new typesByName.network(this, data);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -279,167 +285,3 @@ export class Owner extends Base {
|
|
|
279
285
|
return json;
|
|
280
286
|
}
|
|
281
287
|
}
|
|
282
|
-
|
|
283
|
-
export class Network extends Owner {
|
|
284
|
-
kind;
|
|
285
|
-
scope;
|
|
286
|
-
metric;
|
|
287
|
-
gateway;
|
|
288
|
-
#bridge;
|
|
289
|
-
|
|
290
|
-
static get typeName() {
|
|
291
|
-
return "network";
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
constructor(owner, data) {
|
|
295
|
-
super(owner, data);
|
|
296
|
-
|
|
297
|
-
if (data.subnets) {
|
|
298
|
-
this.addSubnets(data.subnets);
|
|
299
|
-
delete data.subnets;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (data.bridge) {
|
|
303
|
-
this.bridge = owner.addBridge(this, data.bridge);
|
|
304
|
-
delete data.bridge;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
Object.assign(this, data);
|
|
308
|
-
|
|
309
|
-
if (typeof this.gateway === "string") {
|
|
310
|
-
this.finalize(() => (this.gateway = this.owner.hostNamed(this.gateway)));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
get network() {
|
|
315
|
-
return this;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
networkNamed(name) {
|
|
319
|
-
if (this.fullName === name) {
|
|
320
|
-
return this;
|
|
321
|
-
}
|
|
322
|
-
return super.networkNamed(name);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
addSubnets(value) {
|
|
326
|
-
for (const address of asArray(value)) {
|
|
327
|
-
const subnet = this.addSubnet(address);
|
|
328
|
-
subnet.networks.add(this);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
get bridge() {
|
|
333
|
-
return this.#bridge;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
set bridge(bridge) {
|
|
337
|
-
for (const network of bridge) {
|
|
338
|
-
if (network instanceof Network && network !== this) {
|
|
339
|
-
for (const subnet of this.subnets()) {
|
|
340
|
-
for (const otherSubnet of network.subnets()) {
|
|
341
|
-
if (
|
|
342
|
-
subnet !== otherSubnet &&
|
|
343
|
-
subnet.address === otherSubnet.address
|
|
344
|
-
) {
|
|
345
|
-
/*console.log(
|
|
346
|
-
"SHARE SUBNETS",
|
|
347
|
-
subnet.owner.toString(),
|
|
348
|
-
otherSubnet.owner.toString()
|
|
349
|
-
);*/
|
|
350
|
-
|
|
351
|
-
otherSubnet.owner.addObject(subnet);
|
|
352
|
-
for (const n of otherSubnet.networks) {
|
|
353
|
-
subnet.networks.add(n);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
//console.log(subnet.toString(),[...subnet.networks].map(n=>n.toString()));
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
this.#bridge = bridge;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
get propertyNames() {
|
|
367
|
-
return [
|
|
368
|
-
...super.propertyNames,
|
|
369
|
-
"kind",
|
|
370
|
-
"scope",
|
|
371
|
-
"metric",
|
|
372
|
-
"bridge",
|
|
373
|
-
"gateway"
|
|
374
|
-
];
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export class Subnet extends Base {
|
|
379
|
-
networks = new Set();
|
|
380
|
-
|
|
381
|
-
static get typeName() {
|
|
382
|
-
return "subnet";
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
constructor(owner, data) {
|
|
386
|
-
const { cidr } = normalizeCIDR(data.name);
|
|
387
|
-
|
|
388
|
-
if (!cidr) {
|
|
389
|
-
const error = Error(`Invalid address`);
|
|
390
|
-
error.address = data.name;
|
|
391
|
-
throw error;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
data.name = cidr;
|
|
395
|
-
|
|
396
|
-
super(owner, data);
|
|
397
|
-
|
|
398
|
-
Object.assign(this, data);
|
|
399
|
-
|
|
400
|
-
owner.addObject(this);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
get fullName() {
|
|
404
|
-
return this.name;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
matchesAddress(address) {
|
|
408
|
-
return address.startsWith(this.prefix);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
get isLinkLocal() {
|
|
412
|
-
return isLinkLocal(this.address);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
get prefix() {
|
|
416
|
-
const [prefix] = this.name.split("/");
|
|
417
|
-
return prefix;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
get prefixLength() {
|
|
421
|
-
const m = this.name.match(/\/(\d+)$/);
|
|
422
|
-
if (m) {
|
|
423
|
-
return parseInt(m[1]);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
get address() {
|
|
428
|
-
return this.name;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
get propertyNames() {
|
|
432
|
-
return [...super.propertyNames, "networks", "prefixLength"];
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
_traverse(...args) {
|
|
436
|
-
if (super._traverse(...args)) {
|
|
437
|
-
for (const network of this.networks) {
|
|
438
|
-
network._traverse(...args);
|
|
439
|
-
}
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
}
|
package/src/root.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFile, glob } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Base } from "./base.mjs";
|
|
4
|
+
import { Location } from "./location.mjs";
|
|
5
|
+
import { addType, types } from "./types.mjs";
|
|
6
|
+
|
|
7
|
+
export class Root extends Location {
|
|
8
|
+
|
|
9
|
+
static {
|
|
10
|
+
addType(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get typeName() {
|
|
14
|
+
return "root";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor(directory) {
|
|
18
|
+
super(undefined, { name: "" });
|
|
19
|
+
this.directory = directory;
|
|
20
|
+
this.addObject(this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get fullName() {
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get root() {
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async load(name, options) {
|
|
32
|
+
const fullName = Base.normalizeName(name);
|
|
33
|
+
let object = this.named(fullName);
|
|
34
|
+
if (object) {
|
|
35
|
+
return object;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//console.log("LOAD", fullName);
|
|
39
|
+
|
|
40
|
+
let path = fullName.split("/");
|
|
41
|
+
path.pop();
|
|
42
|
+
|
|
43
|
+
let data;
|
|
44
|
+
let type = options?.type;
|
|
45
|
+
if (type) {
|
|
46
|
+
data = JSON.parse(
|
|
47
|
+
await readFile(
|
|
48
|
+
join(this.directory, fullName, type.typeFileName),
|
|
49
|
+
"utf8"
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
for (type of types) {
|
|
54
|
+
try {
|
|
55
|
+
data = JSON.parse(
|
|
56
|
+
await readFile(
|
|
57
|
+
join(this.directory, fullName, type.typeFileName),
|
|
58
|
+
"utf8"
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
break;
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!data) {
|
|
66
|
+
return this.load(path.join("/"), options);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const owner = await this.load(path.join("/"));
|
|
71
|
+
|
|
72
|
+
const length = owner.fullName.length;
|
|
73
|
+
const n = fullName[length] === "/" ? length + 1 : length;
|
|
74
|
+
data.name = fullName.substring(n);
|
|
75
|
+
|
|
76
|
+
type = await type.prepareData(this, data);
|
|
77
|
+
|
|
78
|
+
object = new type(owner, data);
|
|
79
|
+
|
|
80
|
+
this._addObject(type.typeName, fullName, object);
|
|
81
|
+
|
|
82
|
+
return object;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async loadAll() {
|
|
86
|
+
for (let type of types) {
|
|
87
|
+
for await (const name of glob(type.fileNameGlob, {
|
|
88
|
+
cwd: this.directory
|
|
89
|
+
})) {
|
|
90
|
+
await this.load(name, { type });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.execFinalize();
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/service.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Base } from "./base.mjs";
|
|
2
|
+
import { addType } from "./types.mjs";
|
|
2
3
|
|
|
3
4
|
const ServiceTypes = {
|
|
4
5
|
dns: { protocol: "udp", port: 53 },
|
|
@@ -21,6 +22,10 @@ export class Service extends Base {
|
|
|
21
22
|
#port;
|
|
22
23
|
#ipAddresses;
|
|
23
24
|
|
|
25
|
+
static {
|
|
26
|
+
addType(this);
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
static get typeName() {
|
|
25
30
|
return "service";
|
|
26
31
|
}
|
package/src/subnet.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { normalizeCIDR, isLinkLocal } from "./utils.mjs";
|
|
2
|
+
import { Base } from "./base.mjs";
|
|
3
|
+
import { addType } from "./types.mjs";
|
|
4
|
+
|
|
5
|
+
export class Subnet extends Base {
|
|
6
|
+
networks = new Set();
|
|
7
|
+
|
|
8
|
+
static {
|
|
9
|
+
addType(this);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get typeName() {
|
|
13
|
+
return "subnet";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
constructor(owner, data) {
|
|
17
|
+
const { cidr } = normalizeCIDR(data.name);
|
|
18
|
+
|
|
19
|
+
if (!cidr) {
|
|
20
|
+
const error = Error(`Invalid address`);
|
|
21
|
+
error.address = data.name;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
data.name = cidr;
|
|
26
|
+
|
|
27
|
+
super(owner, data);
|
|
28
|
+
|
|
29
|
+
Object.assign(this, data);
|
|
30
|
+
|
|
31
|
+
owner.addObject(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get fullName() {
|
|
35
|
+
return this.name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
matchesAddress(address) {
|
|
39
|
+
return address.startsWith(this.prefix);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get isLinkLocal() {
|
|
43
|
+
return isLinkLocal(this.address);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get prefix() {
|
|
47
|
+
const [prefix] = this.name.split("/");
|
|
48
|
+
return prefix;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get prefixLength() {
|
|
52
|
+
const m = this.name.match(/\/(\d+)$/);
|
|
53
|
+
if (m) {
|
|
54
|
+
return parseInt(m[1]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get address() {
|
|
59
|
+
return this.name;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get propertyNames() {
|
|
63
|
+
return [...super.propertyNames, "networks", "prefixLength"];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_traverse(...args) {
|
|
67
|
+
if (super._traverse(...args)) {
|
|
68
|
+
for (const network of this.networks) {
|
|
69
|
+
network._traverse(...args);
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/types.mjs
ADDED
package/types/cmd.d.mts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
export class Location extends Owner {
|
|
2
|
-
get location(): this;
|
|
3
|
-
}
|
|
4
|
-
export class Root extends Location {
|
|
5
|
-
static get types(): {
|
|
6
|
-
[k: string]: typeof DNSService | typeof Owner | typeof Subnet | typeof Service | typeof Host | typeof NetworkInterface;
|
|
7
|
-
};
|
|
8
|
-
constructor(directory: any);
|
|
9
|
-
get types(): any;
|
|
10
|
-
get fullName(): string;
|
|
11
|
-
get root(): this;
|
|
12
|
-
load(name: any, options: any): any;
|
|
13
|
-
loadAll(): Promise<void>;
|
|
14
|
-
}
|
|
15
1
|
export class Host extends Base {
|
|
16
2
|
static prepareData(root: any, data: any): Promise<typeof Host>;
|
|
17
3
|
postinstall: any[];
|
|
@@ -47,7 +33,7 @@ export class Host extends Base {
|
|
|
47
33
|
get ipAddresses(): any[];
|
|
48
34
|
get ipAddressesWithPrefixLength(): any[];
|
|
49
35
|
get ipAddress(): any;
|
|
50
|
-
publicKey(type?: string): Promise<
|
|
36
|
+
publicKey(type?: string): Promise<any>;
|
|
51
37
|
toJSON(): {
|
|
52
38
|
extends: any[];
|
|
53
39
|
networkInterfaces: any;
|
|
@@ -78,8 +64,4 @@ export class NetworkInterface extends Base {
|
|
|
78
64
|
get kind(): any;
|
|
79
65
|
#private;
|
|
80
66
|
}
|
|
81
|
-
import { Owner } from "./owner.mjs";
|
|
82
|
-
import { DNSService } from "./dns.mjs";
|
|
83
|
-
import { Subnet } from "./owner.mjs";
|
|
84
|
-
import { Service } from "./service.mjs";
|
|
85
67
|
import { Base } from "./base.mjs";
|
package/types/module.d.mts
CHANGED
|
@@ -3,4 +3,9 @@ export * from "./service.mjs";
|
|
|
3
3
|
export * from "./dns.mjs";
|
|
4
4
|
export * from "./cluster.mjs";
|
|
5
5
|
export * from "./owner.mjs";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./location.mjs";
|
|
7
|
+
export * from "./root.mjs";
|
|
8
|
+
export * from "./subnet.mjs";
|
|
9
|
+
export * from "./network.mjs";
|
|
10
|
+
export * from "./host.mjs";
|
|
11
|
+
export * from "./types.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class Network extends Owner {
|
|
2
|
+
constructor(owner: any, data: any);
|
|
3
|
+
kind: any;
|
|
4
|
+
scope: any;
|
|
5
|
+
metric: any;
|
|
6
|
+
gateway: any;
|
|
7
|
+
set bridge(bridge: any);
|
|
8
|
+
get bridge(): any;
|
|
9
|
+
get network(): this;
|
|
10
|
+
addSubnets(value: any): void;
|
|
11
|
+
#private;
|
|
12
|
+
}
|
|
13
|
+
import { Owner } from "./owner.mjs";
|
package/types/owner.d.mts
CHANGED
|
@@ -31,26 +31,5 @@ export class Owner extends Base {
|
|
|
31
31
|
domains(): Generator<any, void, unknown>;
|
|
32
32
|
#private;
|
|
33
33
|
}
|
|
34
|
-
export class Network extends Owner {
|
|
35
|
-
constructor(owner: any, data: any);
|
|
36
|
-
kind: any;
|
|
37
|
-
scope: any;
|
|
38
|
-
metric: any;
|
|
39
|
-
gateway: any;
|
|
40
|
-
set bridge(bridge: any);
|
|
41
|
-
get bridge(): any;
|
|
42
|
-
get network(): this;
|
|
43
|
-
addSubnets(value: any): void;
|
|
44
|
-
#private;
|
|
45
|
-
}
|
|
46
|
-
export class Subnet extends Base {
|
|
47
|
-
networks: Set<any>;
|
|
48
|
-
matchesAddress(address: any): any;
|
|
49
|
-
get isLinkLocal(): any;
|
|
50
|
-
get prefix(): any;
|
|
51
|
-
get prefixLength(): number;
|
|
52
|
-
get address(): any;
|
|
53
|
-
_traverse(...args: any[]): boolean;
|
|
54
|
-
}
|
|
55
34
|
import { Base } from "./base.mjs";
|
|
56
35
|
import { DNSService } from "./dns.mjs";
|
package/types/root.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class Subnet extends Base {
|
|
2
|
+
networks: Set<any>;
|
|
3
|
+
matchesAddress(address: any): any;
|
|
4
|
+
get isLinkLocal(): any;
|
|
5
|
+
get prefix(): any;
|
|
6
|
+
get prefixLength(): number;
|
|
7
|
+
get address(): any;
|
|
8
|
+
_traverse(...args: any[]): boolean;
|
|
9
|
+
}
|
|
10
|
+
import { Base } from "./base.mjs";
|