pmcf 1.4.1 → 1.5.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.
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { writeFile, mkdir, copyFile, glob } from "node:fs/promises";
4
- import { cwd, argv } from "node:process";
5
4
  import { join } from "node:path";
6
- import { World, writeLines, sectionLines } from "../src/model.mjs";
5
+ import { writeLines, sectionLines } from "../src/model.mjs";
6
+ import { prepare } from "../src/cmd.mjs";
7
7
 
8
- const world = new World(argv[2] || cwd());
8
+ const { world, args } = prepare();
9
9
 
10
- const hostName = argv[3];
10
+ const hostName = args[0];
11
11
 
12
12
  const host = await world.host(hostName);
13
13
 
14
- const targetDir = argv[4] || `pkg/host-${host.hostName}`;
14
+ const targetDir = args[1] || `pkg/host-${host.hostName}`;
15
15
 
16
16
  await generateNetworkDefs(host, targetDir);
17
17
  await generateMachineInfo(host, targetDir);
package/bin/pmcf-info CHANGED
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { cwd, argv } from "node:process";
3
- import { World } from "../src/model.mjs";
2
+ import { prepare } from "../src/cmd.mjs";
3
+ const { world, args } = prepare();
4
4
 
5
- const world = new World(argv[2] || cwd());
6
-
7
- const objectName = argv[3];
5
+ const objectName = args[0];
8
6
 
9
7
  if (objectName) {
10
8
  const object = await world.named(objectName);
@@ -1,17 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { cwd, argv } from "node:process";
4
3
  import { mkdir, copyFile } from "node:fs/promises";
5
4
  import { join } from "node:path";
6
- import { World, writeLines, sectionLines } from "../src/model.mjs";
5
+ import { writeLines, sectionLines } from "../src/model.mjs";
6
+ import { prepare } from "../src/cmd.mjs";
7
7
 
8
- const world = new World(argv[2] || cwd());
9
- const location = await world.location(argv[3] || "SW");
10
- const targetDir = argv[4];
8
+ const { world, args } = prepare();
9
+
10
+ const location = await world.location(args[0] || "SW");
11
+ const targetDir = args[1];
11
12
 
12
13
  await generateLocationDefs(location, targetDir);
13
14
 
14
- console.log("provides", "location", "mf-location", `mf-location-${location.name}`);
15
+ console.log(
16
+ "provides",
17
+ "location",
18
+ "mf-location",
19
+ `mf-location-${location.name}`
20
+ );
15
21
  console.log("replaces", `mf-location-${location.name}`);
16
22
  console.log("description", `location definitions for ${location.name}`);
17
23
 
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { cwd, argv } from "node:process";
4
3
  import { join } from "node:path";
5
4
  import { createHmac } from "node:crypto";
5
+ import { writeLines } from "../src/model.mjs";
6
+ import { prepare } from "../src/cmd.mjs";
6
7
 
7
- import { World, writeLines } from "../src/model.mjs";
8
+ const { world, args } = prepare();
8
9
 
9
- const world = new World(argv[2] || cwd());
10
- const location = await world.location(argv[3] || "SW");
11
- const targetDir = argv[4] || `pkg/mf-named-${location.name}`;
10
+ const location = await world.location(args[0] || "SW");
11
+ const targetDir = args[1] || `pkg/mf-named-${location.name}`;
12
12
  const ttl = location.dnsRecordTTL;
13
13
  const updates = [
14
14
  Math.ceil(Date.now() / 1000),
@@ -38,7 +38,7 @@ async function generateNamedDefs(location, targetDir) {
38
38
  const records = new Set();
39
39
 
40
40
  const nameserver = (await location.service({ type: "dns" }))?.owner;
41
- const rname = location.administratorEmail.replace(/@/,'.');
41
+ const rname = location.administratorEmail.replace(/@/, ".");
42
42
 
43
43
  for await (const mail of location.services({ type: "smtp" })) {
44
44
  records.add(
@@ -48,12 +48,7 @@ async function generateNamedDefs(location, targetDir) {
48
48
  );
49
49
  }
50
50
 
51
- console.log(
52
- location.name,
53
- location.domain,
54
- nameserver?.hostName,
55
- rname
56
- );
51
+ console.log(location.name, location.domain, nameserver?.hostName, rname);
57
52
 
58
53
  const catalogZone = {
59
54
  id: `catalog.${domain}`,
@@ -63,7 +58,7 @@ async function generateNamedDefs(location, targetDir) {
63
58
  nameserver.domainName
64
59
  }. ${rname}. (${updates})`,
65
60
  `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
66
- `${("version."+domain+'.').padEnd(NAME_LEN, " ")} IN TXT "2"`
61
+ `${("version." + domain + ".").padEnd(NAME_LEN, " ")} IN TXT "2"`
67
62
  ])
68
63
  };
69
64
 
@@ -152,9 +147,11 @@ async function generateNamedDefs(location, targetDir) {
152
147
  zones.push(catalogZone);
153
148
 
154
149
  for (const zone of zones) {
155
- if(zone !== catalogZone) {
150
+ if (zone !== catalogZone) {
156
151
  const hash = createHmac("md5", zone.id).digest("hex");
157
- catalogZone.records.add(`${hash}.zones.${domain}. IN PTR ${zone.id}.`);
152
+ catalogZone.records.add(
153
+ `${hash}.zones.${domain}. IN PTR ${zone.id}.`
154
+ );
158
155
  }
159
156
 
160
157
  zoneConfig.push(`zone \"${zone.id}\" {`);
@@ -162,7 +159,9 @@ async function generateNamedDefs(location, targetDir) {
162
159
  zoneConfig.push(` file \"${zone.file}\";`);
163
160
 
164
161
  const u = location.dnsAllowedUpdates;
165
- zoneConfig.push(` allow-update { ${u.length ? u.join(';') : "none" }; };`);
162
+ zoneConfig.push(
163
+ ` allow-update { ${u.length ? u.join(";") : "none"}; };`
164
+ );
166
165
  zoneConfig.push(` notify yes;`);
167
166
  zoneConfig.push(`};`);
168
167
  zoneConfig.push("");
package/bin/pmcf-network CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { cwd, argv } from "node:process";
4
- import { World } from "../src/model.mjs";
3
+ import { prepare } from "../src/cmd.mjs";
5
4
 
6
- const world = new World(argv[2] || cwd());
7
- const location = await world.location(argv[3] || "SW");
5
+ const { world, args } = prepare();
6
+
7
+ const location = await world.location(args[0] || "SW");
8
8
 
9
9
  function q(str) {
10
10
  return str.match(/^\w+$/) ? str : `"${str}"`;
11
11
  }
12
12
  function id(str) {
13
- return str.replaceAll(/-/g,'');
13
+ return str.replaceAll(/-/g, "");
14
14
  }
15
15
 
16
16
  console.log("graph G {");
@@ -26,7 +26,11 @@ for await (const host of location.hosts()) {
26
26
  }
27
27
 
28
28
  for await (const network of location.networks()) {
29
- console.log(` ${id(network.name)} [label="${network.name}\\n${network.ipv4}" shape=circle];`);
29
+ console.log(
30
+ ` ${id(network.name)} [label="${network.name}\\n${
31
+ network.ipv4
32
+ }" shape=circle];`
33
+ );
30
34
 
31
35
  for await (const host of network.hosts()) {
32
36
  for (const [n, i] of Object.entries(host.networkInterfaces)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/cmd.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { parseArgs } from "node:util";
2
+ import { argv, cwd, env } from "node:process";
3
+ import { World } from "./model.mjs";
4
+
5
+ export function prepare() {
6
+ const { values, positionals } = parseArgs({
7
+ args: argv.slice(2),
8
+ options: {
9
+ world: {
10
+ type: "string",
11
+ short: "w",
12
+ default: env.PMCF_WORLD || cwd()
13
+ },
14
+ output: {
15
+ type: "string",
16
+ short: "o",
17
+ default: cwd()
18
+ }
19
+ },
20
+ allowPositionals: true
21
+ });
22
+
23
+ const world = new World(values.world);
24
+
25
+ return { world, options: values, args: positionals };
26
+ }
@@ -0,0 +1,9 @@
1
+ export function prepare(): {
2
+ world: World;
3
+ options: {
4
+ world: string;
5
+ output: string;
6
+ };
7
+ args: string[];
8
+ };
9
+ import { World } from "./model.mjs";