@omen.foundation/node-microservice-runtime 0.1.76 → 0.1.77

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.
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultRoutingKeyForMachine = getDefaultRoutingKeyForMachine;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const node_os_1 = require("node:os");
6
+ function getMacAddressBytes() {
7
+ var _a, _b;
8
+ const interfaces = (0, node_os_1.networkInterfaces)();
9
+ const names = Object.keys(interfaces).sort((a, b) => a.localeCompare(b));
10
+ for (const name of names) {
11
+ const entries = interfaces[name];
12
+ if (!entries) {
13
+ continue;
14
+ }
15
+ for (const entry of entries) {
16
+ const mac = (_b = (_a = entry.mac) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
17
+ if (!mac || mac === '00:00:00:00:00:00') {
18
+ continue;
19
+ }
20
+ const sanitized = mac.replace(/:/g, '');
21
+ if (sanitized.length % 2 !== 0) {
22
+ continue;
23
+ }
24
+ const macBytes = Buffer.from(sanitized, 'hex');
25
+ if (macBytes.length > 0) {
26
+ return macBytes;
27
+ }
28
+ }
29
+ }
30
+ throw new Error('No network interface with a valid MAC address was found.');
31
+ }
32
+ function getDefaultRoutingKeyForMachine() {
33
+ const macBytes = getMacAddressBytes();
34
+ const hash = (0, node_crypto_1.createHash)('md5').update(macBytes).digest('hex');
35
+ const key = `${(0, node_os_1.hostname)()}_${hash}`
36
+ .replace(/[: ,]/g, '_')
37
+ .toLowerCase();
38
+ return key;
39
+ }