@opsimathically/nodenetproccalld 0.0.1 → 0.0.2

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/dist/index.mjs CHANGED
@@ -1580,6 +1580,7 @@ var ConfigFileLoader = _ConfigFileLoader;
1580
1580
  // src/classes/daemoncli/DaemonCli.class.ts
1581
1581
  var default_server_config_path = "./config/server.config.json5";
1582
1582
  var default_api_keys_config_path = "./config/api_keys.config.json5";
1583
+ var default_config_output_dir = "./config";
1583
1584
  var default_tls_output_dir = "./config/certs";
1584
1585
  var default_ca_common_name = "nodenetproccalld-local-ca";
1585
1586
  var default_server_common_name = "localhost";
@@ -1591,6 +1592,11 @@ var _DaemonCli = class _DaemonCli {
1591
1592
  server_config_path: default_server_config_path,
1592
1593
  api_keys_config_path: default_api_keys_config_path,
1593
1594
  help: false,
1595
+ default_config_generation: {
1596
+ enabled: false,
1597
+ output_dir: default_config_output_dir,
1598
+ overwrite: false
1599
+ },
1594
1600
  tls_generation: {
1595
1601
  enabled: false,
1596
1602
  output_dir: default_tls_output_dir,
@@ -1626,6 +1632,23 @@ var _DaemonCli = class _DaemonCli {
1626
1632
  index += 1;
1627
1633
  continue;
1628
1634
  }
1635
+ if (token2 === "--generate-default-config") {
1636
+ options.default_config_generation.enabled = true;
1637
+ continue;
1638
+ }
1639
+ if (token2 === "--default-config-output-dir") {
1640
+ const next_value = argv[index + 1];
1641
+ if (!next_value) {
1642
+ throw new Error("Missing value for --default-config-output-dir");
1643
+ }
1644
+ options.default_config_generation.output_dir = next_value;
1645
+ index += 1;
1646
+ continue;
1647
+ }
1648
+ if (token2 === "--default-config-overwrite") {
1649
+ options.default_config_generation.overwrite = true;
1650
+ continue;
1651
+ }
1629
1652
  if (token2 === "--generate-tls-material") {
1630
1653
  options.tls_generation.enabled = true;
1631
1654
  continue;
@@ -1692,13 +1715,18 @@ var _DaemonCli = class _DaemonCli {
1692
1715
  "nodenetproccalld",
1693
1716
  "",
1694
1717
  "Usage:",
1695
- " node dist/index.js [options]",
1718
+ " nodenetproccalld [options]",
1696
1719
  "",
1697
1720
  "Options:",
1698
1721
  " --server-config <path> Path to server JSON5 config file.",
1699
1722
  " Default: ./config/server.config.json5",
1700
1723
  " --api-keys-config <path> Path to api keys JSON5 config file.",
1701
1724
  " Default: ./config/api_keys.config.json5",
1725
+ " --generate-default-config Generate default JSON5 daemon config files and exit.",
1726
+ " --default-config-output-dir <path>",
1727
+ " Output directory for server/api-key config files.",
1728
+ " Default: ./config",
1729
+ " --default-config-overwrite Overwrite existing default config files.",
1702
1730
  " --generate-tls-material Generate CA/server/client TLS material and exit.",
1703
1731
  " --tls-output-dir <path> Output directory for generated TLS files.",
1704
1732
  " Default: ./config/certs",
@@ -2040,10 +2068,160 @@ var _DaemonProcess = class _DaemonProcess {
2040
2068
  __name(_DaemonProcess, "DaemonProcess");
2041
2069
  var DaemonProcess = _DaemonProcess;
2042
2070
 
2043
- // src/classes/tlsmaterialgenerator/TlsMaterialGenerator.class.ts
2044
- import { execFileSync } from "child_process";
2071
+ // src/classes/defaultconfiggenerator/DefaultConfigGenerator.class.ts
2045
2072
  import fs2 from "fs";
2046
2073
  import path2 from "path";
2074
+ var default_server_config_template = `{
2075
+ // Friendly name that clients can use in their own config maps.
2076
+ information: {
2077
+ server_name: 'daemon_server_1'
2078
+ },
2079
+
2080
+ // Bind target for tls.createServer.
2081
+ network: {
2082
+ bind_addr: '0.0.0.0',
2083
+ tcp_listen_port: 6767
2084
+ },
2085
+
2086
+ // PEM files are resolved relative to this config file unless absolute paths are used.
2087
+ tls_mtls: {
2088
+ key_file: './certs/server.key.pem',
2089
+ cert_file: './certs/server.cert.pem',
2090
+ ca_file: './certs/ca.cert.pem',
2091
+ // crl_file: './certs/ca.crl.pem',
2092
+ min_version: 'TLSv1.3',
2093
+ handshake_timeout_ms: 5000,
2094
+ request_timeout_ms: 15000,
2095
+ max_frame_bytes: 1048576
2096
+ },
2097
+
2098
+ workerprocedurecall: {
2099
+ count: 4,
2100
+ constructor_options: {
2101
+ call_timeout_ms: 30000,
2102
+ control_timeout_ms: 10000,
2103
+ restart_on_failure: true,
2104
+ max_restarts_per_worker: 6,
2105
+ max_pending_calls_per_worker: 500
2106
+ },
2107
+ start_options: {
2108
+ restart_base_delay_ms: 150,
2109
+ restart_max_delay_ms: 5000,
2110
+ restart_jitter_ms: 250
2111
+ }
2112
+ },
2113
+
2114
+ // Optional abuse controls from @opsimathically/networkprocedurecall.
2115
+ abuse_controls: {
2116
+ connection_controls: {
2117
+ max_concurrent_sockets: 1024,
2118
+ max_concurrent_handshakes: 256,
2119
+ max_unauthenticated_sessions: 256,
2120
+ per_ip_max_new_connections_per_window: 64,
2121
+ tls_handshake_timeout_ms: 5000,
2122
+ auth_message_timeout_ms: 5000
2123
+ },
2124
+ request_controls: {
2125
+ max_in_flight_requests_per_connection: 128,
2126
+ per_connection: {
2127
+ enabled: true,
2128
+ tokens_per_interval: 200,
2129
+ interval_ms: 1000,
2130
+ burst_tokens: 400
2131
+ },
2132
+ per_api_key: {
2133
+ enabled: true,
2134
+ tokens_per_interval: 1000,
2135
+ interval_ms: 1000,
2136
+ burst_tokens: 2000
2137
+ },
2138
+ per_ip: {
2139
+ enabled: true,
2140
+ tokens_per_interval: 500,
2141
+ interval_ms: 1000,
2142
+ burst_tokens: 1000
2143
+ }
2144
+ }
2145
+ },
2146
+
2147
+ observability: {
2148
+ enable_console_log: true,
2149
+ log_worker_events: true,
2150
+ metrics_log_interval_ms: 30000
2151
+ }
2152
+ }
2153
+ `;
2154
+ var default_api_keys_config_template = `{
2155
+ // API keys and privilege grants for auth_callback.
2156
+ api_keys: [
2157
+ {
2158
+ key_id: 'admin_key_1',
2159
+ api_key: 'replace_me_with_random_secret',
2160
+ privileges: ['all_privileges'],
2161
+ enabled: true,
2162
+ identity_constraints: {
2163
+ // Example: accept loopback clients only.
2164
+ remote_address_regex: '^(127\\\\.0\\\\.0\\\\.1|::1|::ffff:127\\\\.0\\\\.0\\\\.1)$'
2165
+ }
2166
+ },
2167
+ {
2168
+ key_id: 'invoke_only_key_1',
2169
+ api_key: 'replace_me_with_second_secret',
2170
+ privileges: ['invoke_functions'],
2171
+ enabled: false
2172
+ }
2173
+ ]
2174
+ }
2175
+ `;
2176
+ function EnsureParentDirectory(params) {
2177
+ fs2.mkdirSync(path2.dirname(params.file_path), {
2178
+ recursive: true
2179
+ });
2180
+ }
2181
+ __name(EnsureParentDirectory, "EnsureParentDirectory");
2182
+ function WriteFileIfAllowed(params) {
2183
+ if (!params.overwrite && fs2.existsSync(params.file_path)) {
2184
+ throw new Error(`Refusing to overwrite existing config "${params.file_path}". Use --default-config-overwrite to replace it.`);
2185
+ }
2186
+ EnsureParentDirectory({
2187
+ file_path: params.file_path
2188
+ });
2189
+ fs2.writeFileSync(params.file_path, params.content, "utf8");
2190
+ }
2191
+ __name(WriteFileIfAllowed, "WriteFileIfAllowed");
2192
+ var _DefaultConfigGenerator = class _DefaultConfigGenerator {
2193
+ generateDefaultConfig(params) {
2194
+ const options = params.default_config_generation_options;
2195
+ const output_dir = path2.resolve(process.cwd(), options.output_dir);
2196
+ const server_config_path = path2.join(output_dir, "server.config.json5");
2197
+ const api_keys_config_path = path2.join(output_dir, "api_keys.config.json5");
2198
+ fs2.mkdirSync(output_dir, {
2199
+ recursive: true
2200
+ });
2201
+ WriteFileIfAllowed({
2202
+ file_path: server_config_path,
2203
+ content: default_server_config_template,
2204
+ overwrite: options.overwrite
2205
+ });
2206
+ WriteFileIfAllowed({
2207
+ file_path: api_keys_config_path,
2208
+ content: default_api_keys_config_template,
2209
+ overwrite: options.overwrite
2210
+ });
2211
+ return {
2212
+ output_dir,
2213
+ server_config_path,
2214
+ api_keys_config_path
2215
+ };
2216
+ }
2217
+ };
2218
+ __name(_DefaultConfigGenerator, "DefaultConfigGenerator");
2219
+ var DefaultConfigGenerator = _DefaultConfigGenerator;
2220
+
2221
+ // src/classes/tlsmaterialgenerator/TlsMaterialGenerator.class.ts
2222
+ import { execFileSync } from "child_process";
2223
+ import fs3 from "fs";
2224
+ import path3 from "path";
2047
2225
  function EnsurePositiveInteger(params) {
2048
2226
  if (!Number.isInteger(params.value) || params.value <= 0) {
2049
2227
  throw new Error(`${params.label} must be a positive integer.`);
@@ -2051,13 +2229,13 @@ function EnsurePositiveInteger(params) {
2051
2229
  }
2052
2230
  __name(EnsurePositiveInteger, "EnsurePositiveInteger");
2053
2231
  function MakeDirRecursive(params) {
2054
- fs2.mkdirSync(params.dir_path, {
2232
+ fs3.mkdirSync(params.dir_path, {
2055
2233
  recursive: true
2056
2234
  });
2057
2235
  }
2058
2236
  __name(MakeDirRecursive, "MakeDirRecursive");
2059
2237
  function WriteTextFile(params) {
2060
- fs2.writeFileSync(params.file_path, params.content, "utf8");
2238
+ fs3.writeFileSync(params.file_path, params.content, "utf8");
2061
2239
  }
2062
2240
  __name(WriteTextFile, "WriteTextFile");
2063
2241
  var _TlsMaterialGenerator = class _TlsMaterialGenerator {
@@ -2067,7 +2245,7 @@ var _TlsMaterialGenerator = class _TlsMaterialGenerator {
2067
2245
  value: options.valid_days,
2068
2246
  label: "tls_generation.valid_days"
2069
2247
  });
2070
- const output_dir = path2.resolve(process.cwd(), options.output_dir);
2248
+ const output_dir = path3.resolve(process.cwd(), options.output_dir);
2071
2249
  MakeDirRecursive({
2072
2250
  dir_path: output_dir
2073
2251
  });
@@ -2126,17 +2304,17 @@ var _TlsMaterialGenerator = class _TlsMaterialGenerator {
2126
2304
  }
2127
2305
  buildTlsFileMap(params) {
2128
2306
  return {
2129
- ca_key_path: path2.join(params.output_dir, "ca.key.pem"),
2130
- ca_cert_path: path2.join(params.output_dir, "ca.cert.pem"),
2131
- server_key_path: path2.join(params.output_dir, "server.key.pem"),
2132
- server_csr_path: path2.join(params.output_dir, "server.csr.pem"),
2133
- server_cert_path: path2.join(params.output_dir, "server.cert.pem"),
2134
- server_ext_path: path2.join(params.output_dir, "server.ext"),
2135
- client_key_path: path2.join(params.output_dir, "client.key.pem"),
2136
- client_csr_path: path2.join(params.output_dir, "client.csr.pem"),
2137
- client_cert_path: path2.join(params.output_dir, "client.cert.pem"),
2138
- client_ext_path: path2.join(params.output_dir, "client.ext"),
2139
- ca_serial_path: path2.join(params.output_dir, "ca.cert.srl")
2307
+ ca_key_path: path3.join(params.output_dir, "ca.key.pem"),
2308
+ ca_cert_path: path3.join(params.output_dir, "ca.cert.pem"),
2309
+ server_key_path: path3.join(params.output_dir, "server.key.pem"),
2310
+ server_csr_path: path3.join(params.output_dir, "server.csr.pem"),
2311
+ server_cert_path: path3.join(params.output_dir, "server.cert.pem"),
2312
+ server_ext_path: path3.join(params.output_dir, "server.ext"),
2313
+ client_key_path: path3.join(params.output_dir, "client.key.pem"),
2314
+ client_csr_path: path3.join(params.output_dir, "client.csr.pem"),
2315
+ client_cert_path: path3.join(params.output_dir, "client.cert.pem"),
2316
+ client_ext_path: path3.join(params.output_dir, "client.ext"),
2317
+ ca_serial_path: path3.join(params.output_dir, "ca.cert.srl")
2140
2318
  };
2141
2319
  }
2142
2320
  assertTargetFilesAreWritable(params) {
@@ -2150,18 +2328,18 @@ var _TlsMaterialGenerator = class _TlsMaterialGenerator {
2150
2328
  ];
2151
2329
  if (!params.overwrite) {
2152
2330
  for (const target_path of target_paths) {
2153
- if (fs2.existsSync(target_path)) {
2331
+ if (fs3.existsSync(target_path)) {
2154
2332
  throw new Error(`Refusing to overwrite existing file "${target_path}". Use --tls-overwrite to replace existing material.`);
2155
2333
  }
2156
2334
  }
2157
2335
  return;
2158
2336
  }
2159
2337
  for (const target_path of target_paths) {
2160
- fs2.rmSync(target_path, {
2338
+ fs3.rmSync(target_path, {
2161
2339
  force: true
2162
2340
  });
2163
2341
  }
2164
- fs2.rmSync(params.tls_files.ca_serial_path, {
2342
+ fs3.rmSync(params.tls_files.ca_serial_path, {
2165
2343
  force: true
2166
2344
  });
2167
2345
  }
@@ -2282,19 +2460,19 @@ var _TlsMaterialGenerator = class _TlsMaterialGenerator {
2282
2460
  });
2283
2461
  }
2284
2462
  cleanupIntermediateFiles(params) {
2285
- fs2.rmSync(params.tls_files.server_csr_path, {
2463
+ fs3.rmSync(params.tls_files.server_csr_path, {
2286
2464
  force: true
2287
2465
  });
2288
- fs2.rmSync(params.tls_files.client_csr_path, {
2466
+ fs3.rmSync(params.tls_files.client_csr_path, {
2289
2467
  force: true
2290
2468
  });
2291
- fs2.rmSync(params.tls_files.server_ext_path, {
2469
+ fs3.rmSync(params.tls_files.server_ext_path, {
2292
2470
  force: true
2293
2471
  });
2294
- fs2.rmSync(params.tls_files.client_ext_path, {
2472
+ fs3.rmSync(params.tls_files.client_ext_path, {
2295
2473
  force: true
2296
2474
  });
2297
- fs2.rmSync(params.tls_files.ca_serial_path, {
2475
+ fs3.rmSync(params.tls_files.ca_serial_path, {
2298
2476
  force: true
2299
2477
  });
2300
2478
  }
@@ -2321,6 +2499,17 @@ async function StartDaemonFromCli() {
2321
2499
  daemon_cli.printHelp();
2322
2500
  return;
2323
2501
  }
2502
+ if (cli_options.default_config_generation.enabled) {
2503
+ const default_config_generator = new DefaultConfigGenerator();
2504
+ const generated_default_config = default_config_generator.generateDefaultConfig({
2505
+ default_config_generation_options: cli_options.default_config_generation
2506
+ });
2507
+ console.log("Default config generated successfully.");
2508
+ console.log(`Output directory: ${generated_default_config.output_dir}`);
2509
+ console.log(`Server config: ${generated_default_config.server_config_path}`);
2510
+ console.log(`API keys config: ${generated_default_config.api_keys_config_path}`);
2511
+ return;
2512
+ }
2324
2513
  if (cli_options.tls_generation.enabled) {
2325
2514
  const tls_material_generator = new TlsMaterialGenerator();
2326
2515
  const generated_tls_material = tls_material_generator.generateTlsMaterial({
@@ -2359,6 +2548,7 @@ export {
2359
2548
  ConfigValidator,
2360
2549
  DaemonCli,
2361
2550
  DaemonProcess,
2551
+ DefaultConfigGenerator,
2362
2552
  NetworkProcedureCallDaemon,
2363
2553
  TlsMaterialGenerator
2364
2554
  };