pmcf 1.39.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/bin/pmcf-named-defs +12 -2
- 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 -136
- package/src/location.mjs +39 -0
- package/src/module.mjs +6 -1
- package/src/network.mjs +102 -0
- package/src/owner.mjs +8 -135
- 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 -19
- package/types/root.d.mts +8 -0
- package/types/subnet.d.mts +10 -0
- package/types/types.d.mts +3 -0
package/bin/pmcf-named-defs
CHANGED
|
@@ -58,7 +58,17 @@ async function generateNamedDefs(owner, targetDir) {
|
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
const subnets = [
|
|
62
|
+
...new Set([...owner.networks()].map(n => [...n.subnets()]).flat())
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
console.log(
|
|
66
|
+
owner.fullName,
|
|
67
|
+
domain,
|
|
68
|
+
nameserver?.hostName,
|
|
69
|
+
rname,
|
|
70
|
+
subnets.map(s => `${s.owner.name}/${s.name}`)
|
|
71
|
+
);
|
|
62
72
|
|
|
63
73
|
const SOARecord = createRecord(
|
|
64
74
|
"@",
|
|
@@ -87,7 +97,7 @@ async function generateNamedDefs(owner, targetDir) {
|
|
|
87
97
|
};
|
|
88
98
|
zones.push(zone);
|
|
89
99
|
|
|
90
|
-
for (const subnet of
|
|
100
|
+
for (const subnet of subnets) {
|
|
91
101
|
if (!subnet.isLinkLocal && subnet.prefix) {
|
|
92
102
|
const reverseArpa = reverseArpaAddress(subnet.prefix);
|
|
93
103
|
const reverseZone = {
|
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,132 +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
|
-
export class Root extends Location {
|
|
38
|
-
static get types() {
|
|
39
|
-
return _typesByName;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static get typeName() {
|
|
43
|
-
return "root";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
constructor(directory) {
|
|
47
|
-
super(undefined, { name: "" });
|
|
48
|
-
this.directory = directory;
|
|
49
|
-
this.addObject(this);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get types() {
|
|
53
|
-
return this.constructor.types;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get fullName() {
|
|
57
|
-
return "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get root() {
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async load(name, options) {
|
|
65
|
-
const fullName = Base.normalizeName(name);
|
|
66
|
-
let object = this.named(fullName);
|
|
67
|
-
if (object) {
|
|
68
|
-
return object;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//console.log("LOAD", fullName);
|
|
72
|
-
|
|
73
|
-
let path = fullName.split("/");
|
|
74
|
-
path.pop();
|
|
75
|
-
|
|
76
|
-
let data;
|
|
77
|
-
let type = options?.type;
|
|
78
|
-
if (type) {
|
|
79
|
-
data = JSON.parse(
|
|
80
|
-
await readFile(
|
|
81
|
-
join(this.directory, fullName, type.typeFileName),
|
|
82
|
-
"utf8"
|
|
83
|
-
)
|
|
84
|
-
);
|
|
85
|
-
} else {
|
|
86
|
-
for (type of _types) {
|
|
87
|
-
try {
|
|
88
|
-
data = JSON.parse(
|
|
89
|
-
await readFile(
|
|
90
|
-
join(this.directory, fullName, type.typeFileName),
|
|
91
|
-
"utf8"
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
break;
|
|
95
|
-
} catch {}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!data) {
|
|
99
|
-
return this.load(path.join("/"), options);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const owner = await this.load(path.join("/"));
|
|
104
|
-
|
|
105
|
-
const length = owner.fullName.length;
|
|
106
|
-
const n = fullName[length] === "/" ? length + 1 : length;
|
|
107
|
-
data.name = fullName.substring(n);
|
|
108
|
-
|
|
109
|
-
type = await type.prepareData(this, data);
|
|
110
|
-
|
|
111
|
-
object = new type(owner, data);
|
|
112
|
-
|
|
113
|
-
this._addObject(type.typeName, fullName, object);
|
|
114
|
-
|
|
115
|
-
return object;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async loadAll() {
|
|
119
|
-
for (let type of Object.values(Root.types)) {
|
|
120
|
-
for await (const name of glob(type.fileNameGlob, {
|
|
121
|
-
cwd: this.directory
|
|
122
|
-
})) {
|
|
123
|
-
await this.load(name, { type });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.execFinalize();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
10
|
+
import { addType } from "./types.mjs";
|
|
130
11
|
|
|
131
12
|
export class Host extends Base {
|
|
132
13
|
postinstall = [];
|
|
@@ -143,6 +24,10 @@ export class Host extends Base {
|
|
|
143
24
|
#chassis;
|
|
144
25
|
#vendor;
|
|
145
26
|
|
|
27
|
+
static {
|
|
28
|
+
addType(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
146
31
|
static get typeName() {
|
|
147
32
|
return "host";
|
|
148
33
|
}
|
|
@@ -422,6 +307,10 @@ export class Host extends Base {
|
|
|
422
307
|
}
|
|
423
308
|
|
|
424
309
|
export class NetworkInterface extends Base {
|
|
310
|
+
static {
|
|
311
|
+
addType(this);
|
|
312
|
+
}
|
|
313
|
+
|
|
425
314
|
static get typeName() {
|
|
426
315
|
return "network_interface";
|
|
427
316
|
}
|
|
@@ -603,16 +492,3 @@ export class NetworkInterface extends Base {
|
|
|
603
492
|
];
|
|
604
493
|
}
|
|
605
494
|
}
|
|
606
|
-
|
|
607
|
-
const _types = [
|
|
608
|
-
Owner,
|
|
609
|
-
Location,
|
|
610
|
-
Network,
|
|
611
|
-
Subnet,
|
|
612
|
-
Host,
|
|
613
|
-
Cluster,
|
|
614
|
-
Service,
|
|
615
|
-
DNSService,
|
|
616
|
-
NetworkInterface
|
|
617
|
-
];
|
|
618
|
-
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,136 +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
|
-
bridge;
|
|
288
|
-
gateway;
|
|
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
|
-
let bridge;
|
|
303
|
-
if (data.bridge) {
|
|
304
|
-
bridge = data.bridge;
|
|
305
|
-
delete data.bridge;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
Object.assign(this, data);
|
|
309
|
-
|
|
310
|
-
if (typeof this.gateway === "string") {
|
|
311
|
-
this.finalize(() => (this.gateway = this.owner.hostNamed(this.gateway)));
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
this.bridge = owner.addBridge(this, bridge);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
get network() {
|
|
318
|
-
return this;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
networkNamed(name) {
|
|
322
|
-
if (this.fullName === name) {
|
|
323
|
-
return this;
|
|
324
|
-
}
|
|
325
|
-
return super.networkNamed(name);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
addSubnets(value) {
|
|
329
|
-
for (const address of asArray(value)) {
|
|
330
|
-
const subnet = this.addSubnet(address);
|
|
331
|
-
subnet.networks.add(this);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
get propertyNames() {
|
|
336
|
-
return [
|
|
337
|
-
...super.propertyNames,
|
|
338
|
-
"kind",
|
|
339
|
-
"scope",
|
|
340
|
-
"metric",
|
|
341
|
-
"bridge",
|
|
342
|
-
"gateway"
|
|
343
|
-
];
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export class Subnet extends Base {
|
|
348
|
-
networks = new Set();
|
|
349
|
-
|
|
350
|
-
static get typeName() {
|
|
351
|
-
return "subnet";
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
constructor(owner, data) {
|
|
355
|
-
const { cidr } = normalizeCIDR(data.name);
|
|
356
|
-
|
|
357
|
-
if (!cidr) {
|
|
358
|
-
const error = Error(`Invalid address`);
|
|
359
|
-
error.address = data.name;
|
|
360
|
-
throw error;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
data.name = cidr;
|
|
364
|
-
|
|
365
|
-
super(owner, data);
|
|
366
|
-
|
|
367
|
-
Object.assign(this, data);
|
|
368
|
-
|
|
369
|
-
owner.addObject(this);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
get fullName() {
|
|
373
|
-
return this.name;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
matchesAddress(address) {
|
|
377
|
-
return address.startsWith(this.prefix);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
get isLinkLocal() {
|
|
381
|
-
return isLinkLocal(this.address);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
get prefix() {
|
|
385
|
-
const [prefix] = this.name.split("/");
|
|
386
|
-
return prefix;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
get prefixLength() {
|
|
390
|
-
const m = this.name.match(/\/(\d+)$/);
|
|
391
|
-
if (m) {
|
|
392
|
-
return parseInt(m[1]);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
get address() {
|
|
397
|
-
return this.name;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
get propertyNames() {
|
|
401
|
-
return [...super.propertyNames, "networks", "prefixLength"];
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
_traverse(...args) {
|
|
405
|
-
if (super._traverse(...args)) {
|
|
406
|
-
for (const network of this.networks) {
|
|
407
|
-
network._traverse(...args);
|
|
408
|
-
}
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return false;
|
|
413
|
-
}
|
|
414
|
-
}
|
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,24 +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
|
-
bridge: any;
|
|
40
|
-
gateway: any;
|
|
41
|
-
get network(): this;
|
|
42
|
-
addSubnets(value: any): void;
|
|
43
|
-
}
|
|
44
|
-
export class Subnet extends Base {
|
|
45
|
-
networks: Set<any>;
|
|
46
|
-
matchesAddress(address: any): any;
|
|
47
|
-
get isLinkLocal(): any;
|
|
48
|
-
get prefix(): any;
|
|
49
|
-
get prefixLength(): number;
|
|
50
|
-
get address(): any;
|
|
51
|
-
_traverse(...args: any[]): boolean;
|
|
52
|
-
}
|
|
53
34
|
import { Base } from "./base.mjs";
|
|
54
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";
|