@gearbox-protocol/cli-utils 6.14.0 → 6.15.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/dist/createPinoCensor.d.ts +5 -0
- package/dist/createPinoCensor.js +53 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CensoredString } from "./CensoredString.js";
|
|
2
|
+
import { CensoredURL } from "./CensoredURL.js";
|
|
3
|
+
/**
|
|
4
|
+
* Raw values shorter than this are not censored, to avoid masking unrelated
|
|
5
|
+
* substrings throughout the log output.
|
|
6
|
+
*/
|
|
7
|
+
const MIN_SECRET_LENGTH = 4;
|
|
8
|
+
function escapeRegExp(value) {
|
|
9
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
10
|
+
}
|
|
11
|
+
function collectSecrets(value, out) {
|
|
12
|
+
if (value == null) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (value instanceof CensoredString || value instanceof CensoredURL) {
|
|
16
|
+
const raw = value.value;
|
|
17
|
+
if (raw.length >= MIN_SECRET_LENGTH) {
|
|
18
|
+
out.set(raw, value.toString());
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value !== "object") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
for (const item of value) {
|
|
27
|
+
collectSecrets(item, out);
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const item of Object.values(value)) {
|
|
32
|
+
collectSecrets(item, out);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gathers known secrets from a config and returns a function that replaces each raw secret with its masked representation.
|
|
37
|
+
* Intended for pino's `hooks.streamWrite`
|
|
38
|
+
*/
|
|
39
|
+
export function createPinoCensor(config) {
|
|
40
|
+
const map = new Map();
|
|
41
|
+
collectSecrets(config, map);
|
|
42
|
+
if (map.size === 0) {
|
|
43
|
+
return s => s;
|
|
44
|
+
}
|
|
45
|
+
// Longer secrets first so a secret that is a substring of another does not
|
|
46
|
+
// shadow the longer match.
|
|
47
|
+
const pattern = [...map.keys()]
|
|
48
|
+
.sort((a, b) => b.length - a.length)
|
|
49
|
+
.map(escapeRegExp)
|
|
50
|
+
.join("|");
|
|
51
|
+
const re = new RegExp(pattern, "g");
|
|
52
|
+
return s => s.replace(re, m => map.get(m) ?? m);
|
|
53
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./CensoredString.js";
|
|
2
2
|
export * from "./CensoredURL.js";
|
|
3
3
|
export * from "./compressedConfig.js";
|
|
4
|
+
export * from "./createPinoCensor.js";
|
|
4
5
|
export * from "./fetchRetry.js";
|
|
5
6
|
export * from "./getFirstHttpTransportOptions.js";
|
|
6
7
|
export * from "./getProviders.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./CensoredString.js";
|
|
2
2
|
export * from "./CensoredURL.js";
|
|
3
3
|
export * from "./compressedConfig.js";
|
|
4
|
+
export * from "./createPinoCensor.js";
|
|
4
5
|
export * from "./fetchRetry.js";
|
|
5
6
|
export * from "./getFirstHttpTransportOptions.js";
|
|
6
7
|
export * from "./getProviders.js";
|