field-redactor 1.5.0 → 1.6.1
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/CHANGELOG.md +41 -0
- package/CONTRIBUTING.md +64 -0
- package/README.md +3 -0
- package/dist/api/fieldRedactor.d.ts +51 -0
- package/dist/api/fieldRedactor.d.ts.map +1 -0
- package/dist/api/fieldRedactor.js +165 -0
- package/dist/api/fieldRedactor.js.map +1 -0
- package/dist/api/fieldRedactorConfigBuilder.d.ts +57 -0
- package/dist/api/fieldRedactorConfigBuilder.d.ts.map +1 -0
- package/dist/api/fieldRedactorConfigBuilder.js +115 -0
- package/dist/api/fieldRedactorConfigBuilder.js.map +1 -0
- package/dist/api/fieldRedactorDeps.d.ts +19 -0
- package/dist/api/fieldRedactorDeps.d.ts.map +1 -0
- package/dist/api/fieldRedactorDeps.js +45 -0
- package/dist/api/fieldRedactorDeps.js.map +1 -0
- package/dist/arrayRedaction.d.ts +12 -0
- package/dist/arrayRedaction.d.ts.map +1 -0
- package/dist/arrayRedaction.js +70 -0
- package/dist/arrayRedaction.js.map +1 -0
- package/dist/config/configValidator.d.ts +9 -0
- package/dist/config/configValidator.d.ts.map +1 -0
- package/dist/config/configValidator.js +77 -0
- package/dist/config/configValidator.js.map +1 -0
- package/dist/config/customObjectSchemas.d.ts +7 -0
- package/dist/config/customObjectSchemas.d.ts.map +1 -0
- package/dist/config/customObjectSchemas.js +35 -0
- package/dist/config/customObjectSchemas.js.map +1 -0
- package/dist/config/presets.d.ts +22 -0
- package/dist/config/presets.d.ts.map +1 -0
- package/dist/config/presets.js +50 -0
- package/dist/config/presets.js.map +1 -0
- package/dist/config/redactionRules.d.ts +26 -0
- package/dist/config/redactionRules.d.ts.map +1 -0
- package/dist/config/redactionRules.js +107 -0
- package/dist/config/redactionRules.js.map +1 -0
- package/dist/configValidator.d.ts +3 -4
- package/dist/configValidator.d.ts.map +1 -1
- package/dist/configValidator.js +9 -26
- package/dist/configValidator.js.map +1 -1
- package/dist/customObjectFieldHandler.d.ts +21 -0
- package/dist/customObjectFieldHandler.d.ts.map +1 -0
- package/dist/customObjectFieldHandler.js +159 -0
- package/dist/customObjectFieldHandler.js.map +1 -0
- package/dist/customObjectManager.d.ts +1 -1
- package/dist/customObjectManager.js +3 -3
- package/dist/customObjectManager.js.map +1 -1
- package/dist/customObjectSchemas.d.ts +7 -0
- package/dist/customObjectSchemas.d.ts.map +1 -0
- package/dist/customObjectSchemas.js +35 -0
- package/dist/customObjectSchemas.js.map +1 -0
- package/dist/dryRun.d.ts +2 -1
- package/dist/dryRun.d.ts.map +1 -1
- package/dist/dryRun.js +2 -2
- package/dist/dryRun.js.map +1 -1
- package/dist/dryRunAttribution.d.ts +5 -3
- package/dist/dryRunAttribution.d.ts.map +1 -1
- package/dist/dryRunAttribution.js +9 -101
- package/dist/dryRunAttribution.js.map +1 -1
- package/dist/dryrun/dryRun.d.ts +9 -0
- package/dist/dryrun/dryRun.d.ts.map +1 -0
- package/dist/dryrun/dryRun.js +75 -0
- package/dist/dryrun/dryRun.js.map +1 -0
- package/dist/dryrun/dryRunAttribution.d.ts +10 -0
- package/dist/dryrun/dryRunAttribution.d.ts.map +1 -0
- package/dist/dryrun/dryRunAttribution.js +14 -0
- package/dist/dryrun/dryRunAttribution.js.map +1 -0
- package/dist/engine/arrayRedaction.d.ts +12 -0
- package/dist/engine/arrayRedaction.d.ts.map +1 -0
- package/dist/engine/arrayRedaction.js +70 -0
- package/dist/engine/arrayRedaction.js.map +1 -0
- package/dist/engine/customObjectFieldHandler.d.ts +30 -0
- package/dist/engine/customObjectFieldHandler.d.ts.map +1 -0
- package/dist/engine/customObjectFieldHandler.js +149 -0
- package/dist/engine/customObjectFieldHandler.js.map +1 -0
- package/dist/engine/objectRedactor.d.ts +18 -0
- package/dist/engine/objectRedactor.d.ts.map +1 -0
- package/dist/engine/objectRedactor.js +38 -0
- package/dist/engine/objectRedactor.js.map +1 -0
- package/dist/engine/objectRedactorCustomObject.d.ts +12 -0
- package/dist/engine/objectRedactorCustomObject.d.ts.map +1 -0
- package/dist/engine/objectRedactorCustomObject.js +22 -0
- package/dist/engine/objectRedactorCustomObject.js.map +1 -0
- package/dist/engine/objectRedactorHelpers.d.ts +8 -0
- package/dist/engine/objectRedactorHelpers.d.ts.map +1 -0
- package/dist/engine/objectRedactorHelpers.js +35 -0
- package/dist/engine/objectRedactorHelpers.js.map +1 -0
- package/dist/engine/objectRedactorMutation.d.ts +10 -0
- package/dist/engine/objectRedactorMutation.d.ts.map +1 -0
- package/dist/engine/objectRedactorMutation.js +89 -0
- package/dist/engine/objectRedactorMutation.js.map +1 -0
- package/dist/engine/objectRedactorSync.d.ts +2 -0
- package/dist/engine/objectRedactorSync.d.ts.map +1 -0
- package/dist/engine/objectRedactorSync.js +7 -0
- package/dist/engine/objectRedactorSync.js.map +1 -0
- package/dist/engine/objectRedactorTraversal.d.ts +41 -0
- package/dist/engine/objectRedactorTraversal.d.ts.map +1 -0
- package/dist/engine/objectRedactorTraversal.js +201 -0
- package/dist/engine/objectRedactorTraversal.js.map +1 -0
- package/dist/engine/primitiveRedactor.d.ts +33 -0
- package/dist/engine/primitiveRedactor.d.ts.map +1 -0
- package/dist/engine/primitiveRedactor.js +75 -0
- package/dist/engine/primitiveRedactor.js.map +1 -0
- package/dist/engine/traversalServices.d.ts +21 -0
- package/dist/engine/traversalServices.d.ts.map +1 -0
- package/dist/engine/traversalServices.js +3 -0
- package/dist/engine/traversalServices.js.map +1 -0
- package/dist/fieldDisposition.d.ts +3 -0
- package/dist/fieldDisposition.d.ts.map +1 -0
- package/dist/fieldDisposition.js +6 -0
- package/dist/fieldDisposition.js.map +1 -0
- package/dist/fieldRedactor.d.ts +6 -21
- package/dist/fieldRedactor.d.ts.map +1 -1
- package/dist/fieldRedactor.js +37 -56
- package/dist/fieldRedactor.js.map +1 -1
- package/dist/fieldRedactorConfigBuilder.d.ts +7 -1
- package/dist/fieldRedactorConfigBuilder.d.ts.map +1 -1
- package/dist/fieldRedactorConfigBuilder.js +14 -1
- package/dist/fieldRedactorConfigBuilder.js.map +1 -1
- package/dist/fieldRedactorDeps.d.ts +2 -0
- package/dist/fieldRedactorDeps.d.ts.map +1 -1
- package/dist/fieldRedactorDeps.js +11 -9
- package/dist/fieldRedactorDeps.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/jsonWalk.d.ts +1 -1
- package/dist/jsonWalk.d.ts.map +1 -1
- package/dist/jsonWalk.js +2 -33
- package/dist/jsonWalk.js.map +1 -1
- package/dist/maybeAsync.d.ts +7 -0
- package/dist/maybeAsync.d.ts.map +1 -0
- package/dist/maybeAsync.js +56 -0
- package/dist/maybeAsync.js.map +1 -0
- package/dist/objectRedactor.d.ts +2 -1
- package/dist/objectRedactor.d.ts.map +1 -1
- package/dist/objectRedactor.js +2 -2
- package/dist/objectRedactor.js.map +1 -1
- package/dist/objectRedactorCustomObject.d.ts +19 -40
- package/dist/objectRedactorCustomObject.d.ts.map +1 -1
- package/dist/objectRedactorCustomObject.js +20 -101
- package/dist/objectRedactorCustomObject.js.map +1 -1
- package/dist/objectRedactorHelpers.d.ts.map +1 -1
- package/dist/objectRedactorHelpers.js +3 -0
- package/dist/objectRedactorHelpers.js.map +1 -1
- package/dist/objectRedactorTraversal.d.ts +20 -36
- package/dist/objectRedactorTraversal.d.ts.map +1 -1
- package/dist/objectRedactorTraversal.js +141 -516
- package/dist/objectRedactorTraversal.js.map +1 -1
- package/dist/pathParsing.d.ts +11 -0
- package/dist/pathParsing.d.ts.map +1 -0
- package/dist/pathParsing.js +53 -0
- package/dist/pathParsing.js.map +1 -0
- package/dist/pathRuleMatcher.d.ts +19 -0
- package/dist/pathRuleMatcher.d.ts.map +1 -0
- package/dist/pathRuleMatcher.js +42 -0
- package/dist/pathRuleMatcher.js.map +1 -0
- package/dist/redactionRules.d.ts +3 -4
- package/dist/redactionRules.d.ts.map +1 -1
- package/dist/redactionRules.js +7 -9
- package/dist/redactionRules.js.map +1 -1
- package/dist/ruleResolver.d.ts +65 -0
- package/dist/ruleResolver.d.ts.map +1 -0
- package/dist/ruleResolver.js +193 -0
- package/dist/ruleResolver.js.map +1 -0
- package/dist/rules/customObjectManager.d.ts +28 -0
- package/dist/rules/customObjectManager.d.ts.map +1 -0
- package/dist/rules/customObjectManager.js +60 -0
- package/dist/rules/customObjectManager.js.map +1 -0
- package/dist/rules/fieldDisposition.d.ts +3 -0
- package/dist/rules/fieldDisposition.d.ts.map +1 -0
- package/dist/rules/fieldDisposition.js +6 -0
- package/dist/rules/fieldDisposition.js.map +1 -0
- package/dist/rules/pathRuleMatcher.d.ts +19 -0
- package/dist/rules/pathRuleMatcher.d.ts.map +1 -0
- package/dist/rules/pathRuleMatcher.js +40 -0
- package/dist/rules/pathRuleMatcher.js.map +1 -0
- package/dist/rules/ruleResolver.d.ts +63 -0
- package/dist/rules/ruleResolver.d.ts.map +1 -0
- package/dist/rules/ruleResolver.js +188 -0
- package/dist/rules/ruleResolver.js.map +1 -0
- package/dist/rules/schemaSiblingKey.d.ts +4 -0
- package/dist/rules/schemaSiblingKey.d.ts.map +1 -0
- package/dist/rules/schemaSiblingKey.js +19 -0
- package/dist/rules/schemaSiblingKey.js.map +1 -0
- package/dist/rules/secretManager.d.ts +31 -0
- package/dist/rules/secretManager.d.ts.map +1 -0
- package/dist/rules/secretManager.js +85 -0
- package/dist/rules/secretManager.js.map +1 -0
- package/dist/rules/valuePatternMatcher.d.ts +15 -0
- package/dist/rules/valuePatternMatcher.d.ts.map +1 -0
- package/dist/rules/valuePatternMatcher.js +30 -0
- package/dist/rules/valuePatternMatcher.js.map +1 -0
- package/dist/secretManager.d.ts +6 -19
- package/dist/secretManager.d.ts.map +1 -1
- package/dist/secretManager.js +19 -30
- package/dist/secretManager.js.map +1 -1
- package/dist/traversalServices.d.ts +21 -0
- package/dist/traversalServices.d.ts.map +1 -0
- package/dist/traversalServices.js +3 -0
- package/dist/traversalServices.js.map +1 -0
- package/dist/types.d.ts +41 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -1
- package/dist/types.js.map +1 -1
- package/dist/util/jsonWalk.d.ts +10 -0
- package/dist/util/jsonWalk.d.ts.map +1 -0
- package/dist/util/jsonWalk.js +53 -0
- package/dist/util/jsonWalk.js.map +1 -0
- package/dist/util/maybeAsync.d.ts +6 -0
- package/dist/util/maybeAsync.d.ts.map +1 -0
- package/dist/util/maybeAsync.js +54 -0
- package/dist/util/maybeAsync.js.map +1 -0
- package/dist/util/pathParsing.d.ts +11 -0
- package/dist/util/pathParsing.d.ts.map +1 -0
- package/dist/util/pathParsing.js +53 -0
- package/dist/util/pathParsing.js.map +1 -0
- package/dist/util/primitiveCoercion.d.ts +4 -0
- package/dist/util/primitiveCoercion.d.ts.map +1 -0
- package/dist/util/primitiveCoercion.js +21 -0
- package/dist/util/primitiveCoercion.js.map +1 -0
- package/dist/util/regexUtils.d.ts +3 -0
- package/dist/util/regexUtils.d.ts.map +1 -0
- package/dist/util/regexUtils.js +8 -0
- package/dist/util/regexUtils.js.map +1 -0
- package/docs/guides/migration-1.5-to-1.6.md +57 -0
- package/docs/guides/path-rules.md +47 -0
- package/docs/reference/config.md +5 -1
- package/docs/release-notes/README.md +4 -1
- package/docs/release-notes/v1.6.0.md +59 -0
- package/docs/release-notes/v1.6.1.md +24 -0
- package/jest.config.js +3 -1
- package/package.json +8 -2
|
@@ -1,575 +1,200 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ObjectRedactorTraversal = void 0;
|
|
13
4
|
const types_1 = require("./types");
|
|
14
5
|
const objectRedactorMutation_1 = require("./objectRedactorMutation");
|
|
15
6
|
const objectRedactorHelpers_1 = require("./objectRedactorHelpers");
|
|
16
|
-
const
|
|
7
|
+
const ruleResolver_1 = require("./ruleResolver");
|
|
8
|
+
const maybeAsync_1 = require("./maybeAsync");
|
|
9
|
+
const arrayRedaction_1 = require("./arrayRedaction");
|
|
10
|
+
const customObjectFieldHandler_1 = require("./customObjectFieldHandler");
|
|
17
11
|
/**
|
|
18
12
|
* Unified JSON traversal for in-place and copy-on-write redaction.
|
|
19
|
-
* Sync paths
|
|
13
|
+
* Sync and async paths share one implementation; async mode propagates Promises only when configured.
|
|
20
14
|
*/
|
|
21
15
|
class ObjectRedactorTraversal {
|
|
22
|
-
constructor(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher) {
|
|
16
|
+
constructor(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher, pathRuleMatcher) {
|
|
23
17
|
this.primitiveRedactor = primitiveRedactor;
|
|
24
18
|
this.secretManager = secretManager;
|
|
25
|
-
this.customObjManager = customObjManager;
|
|
26
19
|
this.valuePatternMatcher = valuePatternMatcher;
|
|
20
|
+
this.ruleResolver = new ruleResolver_1.RuleResolver(secretManager, pathRuleMatcher, valuePatternMatcher, customObjManager);
|
|
21
|
+
this.services = {
|
|
22
|
+
get asyncMode() {
|
|
23
|
+
return primitiveRedactor.usesAsyncRedactor();
|
|
24
|
+
},
|
|
25
|
+
ruleResolver: this.ruleResolver,
|
|
26
|
+
secretManager,
|
|
27
|
+
valuePatternMatcher,
|
|
28
|
+
setPrimitive: (container, key, primitive) => this.setPrimitive(container, key, primitive),
|
|
29
|
+
setPrimitiveFromValue: (container, key, value) => this.setPrimitiveFromValue(container, key, value),
|
|
30
|
+
setPrimitiveValueIfSecret: (container, key, secretKey, value, forceDeepRedaction) => this.setPrimitiveValueIfSecret(container, key, secretKey, value, forceDeepRedaction),
|
|
31
|
+
redactSecretFields: (container, forceDeepRedaction, pathSegments) => this.redactSecretFields(container, forceDeepRedaction, pathSegments),
|
|
32
|
+
handleCustomObject: (container, customObject) => this.handleCustomObject(container, customObject),
|
|
33
|
+
redactArrayInObject: (array, key, forceDeepRedaction, parent, pathSegments) => this.redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments),
|
|
34
|
+
redactAllArrayValues: (array, forceDeepRedaction, copyOnWrite, pathSegments) => this.redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments)
|
|
35
|
+
};
|
|
36
|
+
this.arrayRedactor = new arrayRedaction_1.ArrayRedactor(this.services);
|
|
37
|
+
this.customObjectHandler = new customObjectFieldHandler_1.CustomObjectFieldHandler(this.services);
|
|
27
38
|
}
|
|
28
39
|
usesAsyncRedactor() {
|
|
29
40
|
return this.primitiveRedactor.usesAsyncRedactor();
|
|
30
41
|
}
|
|
31
42
|
redactInPlace(value) {
|
|
32
|
-
|
|
43
|
+
const result = this.traverseRedact(value, false);
|
|
44
|
+
if (result instanceof Promise) {
|
|
45
|
+
throw new Error('Unexpected async work on sync traversal path');
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
33
48
|
}
|
|
34
49
|
redactCopyOnWrite(value) {
|
|
35
|
-
|
|
50
|
+
const result = this.traverseRedact(value, true);
|
|
51
|
+
if (result instanceof Promise) {
|
|
52
|
+
throw new Error('Unexpected async work on sync traversal path');
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
36
55
|
}
|
|
37
56
|
redactInPlaceAsync(value) {
|
|
38
|
-
return this.
|
|
57
|
+
return Promise.resolve(this.traverseRedact(value, false));
|
|
39
58
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
43
|
-
if (customObject && (0, types_1.isJsonObject)(value)) {
|
|
44
|
-
this.handleCustomObject(container, customObject);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
this.redactSecretFields(container, false);
|
|
48
|
-
}
|
|
49
|
-
return (copyOnWrite ? container.result() : value);
|
|
59
|
+
get asyncMode() {
|
|
60
|
+
return this.primitiveRedactor.usesAsyncRedactor();
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.handleCustomObject(child, customObject);
|
|
59
|
-
if (container.copyOnWrite) {
|
|
60
|
-
container.set(key, child.result());
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (this.secretManager.isDeleteSecretKey(key)) {
|
|
64
|
-
container.remove(key);
|
|
65
|
-
}
|
|
66
|
-
else if (this.secretManager.isFullSecretKey(key)) {
|
|
67
|
-
container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(value)));
|
|
68
|
-
}
|
|
69
|
-
else if (Array.isArray(value)) {
|
|
70
|
-
this.redactArrayInObject(value, key, forceDeepRedaction, container);
|
|
71
|
-
}
|
|
72
|
-
else if ((0, types_1.isJsonObject)(value)) {
|
|
73
|
-
this.redactNestedObject(value, key, forceDeepRedaction, container);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
container.set(key, this.redactPrimitiveValueIfSecret(key, value, forceDeepRedaction));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
62
|
+
traverseRedact(value, copyOnWrite) {
|
|
63
|
+
const container = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
|
|
64
|
+
const customObject = this.ruleResolver.getMatchingSchema(value);
|
|
65
|
+
const work = customObject && (0, types_1.isJsonObject)(value)
|
|
66
|
+
? this.handleCustomObject(container, customObject)
|
|
67
|
+
: this.redactSecretFields(container, false, []);
|
|
68
|
+
return (0, maybeAsync_1.finalizeMaybeAsync)(work, () => (copyOnWrite ? container.result() : value), this.asyncMode);
|
|
79
69
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const result = this.secretManager.isSecretKey(key) || deepSecretKey || forceDeepRedaction
|
|
83
|
-
? this.redactAllArrayValues(array, forceDeepRedaction || deepSecretKey, parent.copyOnWrite)
|
|
84
|
-
: this.redactObjectsInArray(array, parent.copyOnWrite);
|
|
85
|
-
parent.set(key, result);
|
|
70
|
+
handleCustomObject(container, customObject) {
|
|
71
|
+
return this.customObjectHandler.handleCustomObject(container, customObject);
|
|
86
72
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (let index = 0; index < array.length; index++) {
|
|
90
|
-
const value = array[index];
|
|
91
|
-
if ((0, types_1.isJsonObject)(value)) {
|
|
92
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
93
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
|
|
94
|
-
if (customObject) {
|
|
95
|
-
this.handleCustomObject(child, customObject);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.redactSecretFields(child, false);
|
|
99
|
-
}
|
|
100
|
-
container.set(String(index), child.result());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return container.result();
|
|
73
|
+
redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments) {
|
|
74
|
+
return this.arrayRedactor.redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments);
|
|
104
75
|
}
|
|
105
|
-
redactAllArrayValues(array, forceDeepRedaction, copyOnWrite) {
|
|
106
|
-
|
|
107
|
-
for (let index = 0; index < array.length; index++) {
|
|
108
|
-
const value = array[index];
|
|
109
|
-
const key = String(index);
|
|
110
|
-
if (Array.isArray(value)) {
|
|
111
|
-
container.set(key, this.redactAllArrayValues(value, forceDeepRedaction, copyOnWrite));
|
|
112
|
-
}
|
|
113
|
-
else if (!(0, types_1.isJsonObject)(value)) {
|
|
114
|
-
container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.toRedactablePrimitive)(value)));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
118
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
|
|
119
|
-
if (customObject) {
|
|
120
|
-
this.handleCustomObject(child, customObject);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this.redactSecretFields(child, forceDeepRedaction);
|
|
124
|
-
}
|
|
125
|
-
container.set(key, child.result());
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return container.result();
|
|
76
|
+
redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments) {
|
|
77
|
+
return this.arrayRedactor.redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments);
|
|
129
78
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
133
|
-
if (customObject) {
|
|
134
|
-
this.handleCustomObject(child, customObject);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.redactSecretFields(child, forceDeepRedaction || this.secretManager.isDeepSecretKey(key));
|
|
138
|
-
}
|
|
139
|
-
if (parent.copyOnWrite) {
|
|
140
|
-
parent.set(key, child.result());
|
|
141
|
-
}
|
|
79
|
+
redactPrimitive(value) {
|
|
80
|
+
return this.asyncMode ? this.primitiveRedactor.redactValue(value) : this.primitiveRedactor.redactValueSync(value);
|
|
142
81
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
else if ((0, types_1.isJsonObject)(fieldValue)) {
|
|
150
|
-
this.handleCustomObjectValueIfObject(container, key, customObject);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
this.handleCustomObjectValueIfPrimitive(container, customObject, key);
|
|
154
|
-
}
|
|
82
|
+
setPrimitive(container, key, primitive) {
|
|
83
|
+
const redacted = this.redactPrimitive(primitive);
|
|
84
|
+
if (redacted instanceof Promise) {
|
|
85
|
+
return redacted.then((result) => {
|
|
86
|
+
container.set(key, result);
|
|
87
|
+
});
|
|
155
88
|
}
|
|
89
|
+
container.set(key, redacted);
|
|
156
90
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (stringKey !== undefined) {
|
|
160
|
-
this.handleCustomObjectArrayValueIfStringKeySpecified(container, key, stringKey);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this.handleCustomObjectArrayValueIfMatchTypeSpecified(container, key, customObject[key]);
|
|
164
|
-
}
|
|
91
|
+
setPrimitiveFromValue(container, key, value) {
|
|
92
|
+
return this.setPrimitive(container, key, (0, objectRedactorHelpers_1.getStringValue)(value));
|
|
165
93
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (this.secretManager.isDeleteSecretKey(stringKey)) {
|
|
172
|
-
container.remove(key);
|
|
173
|
-
}
|
|
174
|
-
else if (this.secretManager.isFullSecretKey(stringKey)) {
|
|
175
|
-
container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const isDeepSecretKey = this.secretManager.isDeepSecretKey(stringKey);
|
|
179
|
-
if (isDeepSecretKey || this.secretManager.isSecretKey(stringKey)) {
|
|
180
|
-
container.set(key, this.redactAllArrayValues(fieldValue, isDeepSecretKey, container.copyOnWrite));
|
|
181
|
-
}
|
|
94
|
+
chainHandled(work) {
|
|
95
|
+
if (work instanceof Promise) {
|
|
96
|
+
return work.then(() => 'handled');
|
|
182
97
|
}
|
|
98
|
+
return 'handled';
|
|
183
99
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
100
|
+
applyFieldDisposition(disposition, value, key, fieldPath, container) {
|
|
101
|
+
switch (disposition.action) {
|
|
102
|
+
case 'skip':
|
|
103
|
+
return 'handled';
|
|
104
|
+
case 'remove':
|
|
105
|
+
container.remove(key);
|
|
106
|
+
return 'handled';
|
|
107
|
+
case 'opaque':
|
|
108
|
+
return this.chainHandled(this.setPrimitiveFromValue(container, key, value));
|
|
109
|
+
case 'deep':
|
|
110
|
+
return this.chainHandled(this.redactFieldValue(value, key, true, container, fieldPath));
|
|
111
|
+
case 'shallow':
|
|
112
|
+
if (Array.isArray(value) || (0, types_1.isJsonObject)(value)) {
|
|
113
|
+
return this.chainHandled(this.redactFieldValue(value, key, false, container, fieldPath));
|
|
114
|
+
}
|
|
115
|
+
return this.chainHandled(this.setPrimitive(container, key, (0, objectRedactorHelpers_1.toRedactablePrimitive)(value)));
|
|
116
|
+
case 'pass-key-recurse':
|
|
117
|
+
if (Array.isArray(value) || (0, types_1.isJsonObject)(value)) {
|
|
118
|
+
return this.chainHandled(this.redactFieldValue(value, key, false, container, fieldPath));
|
|
119
|
+
}
|
|
120
|
+
return 'handled';
|
|
121
|
+
default:
|
|
122
|
+
return 'default';
|
|
188
123
|
}
|
|
189
|
-
(0, objectRedactorCustomObject_1.applyCustomObjectArrayMatchType)(matchType, {
|
|
190
|
-
deleteKey: () => container.remove(key),
|
|
191
|
-
redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue))),
|
|
192
|
-
redactDeep: () => container.set(key, this.redactAllArrayValues(fieldValue, true, container.copyOnWrite)),
|
|
193
|
-
redactShallow: () => container.set(key, this.redactAllArrayValues(fieldValue, false, container.copyOnWrite)),
|
|
194
|
-
passThrough: () => {
|
|
195
|
-
this.redactArrayInObject(fieldValue, key, false, container);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
124
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.handleCustomObjectObjectValueIfStringKeySpecified(container, key, stringKey);
|
|
125
|
+
redactFieldValue(value, key, forceDeepRedaction, container, fieldPath) {
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
return this.redactArrayInObject(value, key, forceDeepRedaction, container, fieldPath);
|
|
203
128
|
}
|
|
204
|
-
|
|
205
|
-
this.
|
|
129
|
+
if ((0, types_1.isJsonObject)(value)) {
|
|
130
|
+
return this.redactNestedObject(value, key, forceDeepRedaction, container, fieldPath);
|
|
206
131
|
}
|
|
132
|
+
return this.setPrimitiveValueIfSecret(container, key, key, value, forceDeepRedaction);
|
|
207
133
|
}
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
container.set(key, child.result());
|
|
218
|
-
}
|
|
219
|
-
else if (this.secretManager.isDeleteSecretKey(stringKey)) {
|
|
220
|
-
container.remove(key);
|
|
221
|
-
}
|
|
222
|
-
else if (this.secretManager.isFullSecretKey(stringKey)) {
|
|
223
|
-
container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
|
|
224
|
-
}
|
|
225
|
-
else if (this.secretManager.isDeepSecretKey(stringKey)) {
|
|
134
|
+
redactSecretFields(container, forceDeepRedaction, pathSegments) {
|
|
135
|
+
const record = container.source;
|
|
136
|
+
return (0, maybeAsync_1.runSequential)(Object.keys(record), (key) => this.processSecretField(record, key, forceDeepRedaction, pathSegments, container), this.asyncMode);
|
|
137
|
+
}
|
|
138
|
+
processSecretField(record, key, forceDeepRedaction, pathSegments, container) {
|
|
139
|
+
const fieldValue = record[key];
|
|
140
|
+
const fieldPath = [...pathSegments, key];
|
|
141
|
+
const customObject = (0, types_1.isJsonObject)(fieldValue) ? this.ruleResolver.getMatchingSchema(fieldValue) : undefined;
|
|
142
|
+
if (customObject && (0, types_1.isJsonObject)(fieldValue)) {
|
|
226
143
|
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
227
|
-
this.
|
|
228
|
-
|
|
144
|
+
return (0, maybeAsync_1.finalizeMaybeAsync)(this.handleCustomObject(child, customObject), () => {
|
|
145
|
+
if (container.copyOnWrite) {
|
|
146
|
+
container.set(key, child.result());
|
|
147
|
+
}
|
|
148
|
+
}, this.asyncMode);
|
|
229
149
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
150
|
+
const disposition = this.ruleResolver.resolvePathDisposition(pathSegments, key, forceDeepRedaction);
|
|
151
|
+
const dispositionResult = this.applyFieldDisposition(disposition, fieldValue, key, fieldPath, container);
|
|
152
|
+
if (dispositionResult instanceof Promise) {
|
|
153
|
+
return dispositionResult.then((handled) => handled === 'handled'
|
|
154
|
+
? undefined
|
|
155
|
+
: this.applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath));
|
|
234
156
|
}
|
|
235
|
-
|
|
236
|
-
handleCustomObjectObjectValueIfMatchTypeSpecified(container, key, matchType) {
|
|
237
|
-
const fieldValue = container.source[key];
|
|
238
|
-
if (!(0, types_1.isJsonObject)(fieldValue)) {
|
|
157
|
+
if (dispositionResult === 'handled') {
|
|
239
158
|
return;
|
|
240
159
|
}
|
|
241
|
-
|
|
242
|
-
deleteKey: () => container.remove(key),
|
|
243
|
-
redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue))),
|
|
244
|
-
redactDeep: () => {
|
|
245
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
246
|
-
this.redactSecretFields(child, true);
|
|
247
|
-
container.set(key, child.result());
|
|
248
|
-
},
|
|
249
|
-
redactShallowOrPass: () => {
|
|
250
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
251
|
-
this.redactSecretFields(child, false);
|
|
252
|
-
container.set(key, child.result());
|
|
253
|
-
},
|
|
254
|
-
ignore: () => undefined
|
|
255
|
-
});
|
|
160
|
+
return this.applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath);
|
|
256
161
|
}
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
|
|
162
|
+
applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath) {
|
|
163
|
+
if (this.ruleResolver.shouldRemoveByKey(key)) {
|
|
164
|
+
container.remove(key);
|
|
260
165
|
return;
|
|
261
166
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return;
|
|
167
|
+
if (this.ruleResolver.shouldOpaqueByKey(key)) {
|
|
168
|
+
return this.setPrimitiveFromValue(container, key, fieldValue);
|
|
265
169
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
handleCustomObjectPrimitiveValueIfMatchTypeSpecified(container, key, matchValue) {
|
|
269
|
-
(0, objectRedactorCustomObject_1.applyCustomObjectPrimitiveMatchType)(matchValue, {
|
|
270
|
-
deleteKey: () => container.remove(key),
|
|
271
|
-
redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(container.source[key]))),
|
|
272
|
-
redactScalar: () => container.set(key, this.redactPrimitive(container.source[key])),
|
|
273
|
-
passThrough: () => undefined
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
handleCustomObjectPrimitiveValueIfStringKeySpecified(container, secretKey, key) {
|
|
277
|
-
if (this.secretManager.isDeleteSecretKey(secretKey)) {
|
|
278
|
-
container.remove(key);
|
|
170
|
+
if (Array.isArray(fieldValue)) {
|
|
171
|
+
return this.redactArrayInObject(fieldValue, key, forceDeepRedaction, container, fieldPath);
|
|
279
172
|
}
|
|
280
|
-
|
|
281
|
-
|
|
173
|
+
if ((0, types_1.isJsonObject)(fieldValue)) {
|
|
174
|
+
return this.redactNestedObject(fieldValue, key, forceDeepRedaction, container, fieldPath);
|
|
282
175
|
}
|
|
176
|
+
return this.setPrimitiveValueIfSecret(container, key, key, fieldValue, forceDeepRedaction);
|
|
283
177
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
const container = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
|
|
293
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
294
|
-
if (customObject && (0, types_1.isJsonObject)(value)) {
|
|
295
|
-
yield this.handleCustomObjectAsync(container, customObject);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
yield this.redactSecretFieldsAsync(container, false);
|
|
299
|
-
}
|
|
300
|
-
return (copyOnWrite ? container.result() : value);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
redactSecretFieldsAsync(container, forceDeepRedaction) {
|
|
304
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
const record = container.source;
|
|
306
|
-
for (const key of Object.keys(record)) {
|
|
307
|
-
const fieldValue = record[key];
|
|
308
|
-
const customObject = (0, types_1.isJsonObject)(fieldValue) ? this.customObjManager.getMatchingCustomObject(fieldValue) : undefined;
|
|
309
|
-
if (customObject && (0, types_1.isJsonObject)(fieldValue)) {
|
|
310
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
311
|
-
yield this.handleCustomObjectAsync(child, customObject);
|
|
312
|
-
if (container.copyOnWrite) {
|
|
313
|
-
container.set(key, child.result());
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
else if (this.secretManager.isDeleteSecretKey(key)) {
|
|
317
|
-
container.remove(key);
|
|
318
|
-
}
|
|
319
|
-
else if (this.secretManager.isFullSecretKey(key)) {
|
|
320
|
-
container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
|
|
321
|
-
}
|
|
322
|
-
else if (Array.isArray(fieldValue)) {
|
|
323
|
-
yield this.redactArrayInObjectAsync(fieldValue, key, forceDeepRedaction, container);
|
|
324
|
-
}
|
|
325
|
-
else if ((0, types_1.isJsonObject)(fieldValue)) {
|
|
326
|
-
yield this.redactNestedObjectAsync(fieldValue, key, forceDeepRedaction, container);
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
container.set(key, yield this.redactPrimitiveValueIfSecretAsync(key, fieldValue, forceDeepRedaction));
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
redactArrayInObjectAsync(array, key, forceDeepRedaction, parent) {
|
|
335
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
const deepSecretKey = this.secretManager.isDeepSecretKey(key);
|
|
337
|
-
const result = this.secretManager.isSecretKey(key) || deepSecretKey || forceDeepRedaction
|
|
338
|
-
? yield this.redactAllArrayValuesAsync(array, forceDeepRedaction || deepSecretKey, parent.copyOnWrite)
|
|
339
|
-
: yield this.redactObjectsInArrayAsync(array, parent.copyOnWrite);
|
|
340
|
-
parent.set(key, result);
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
redactObjectsInArrayAsync(array, copyOnWrite) {
|
|
344
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
-
const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
|
|
346
|
-
for (let index = 0; index < array.length; index++) {
|
|
347
|
-
const item = array[index];
|
|
348
|
-
if ((0, types_1.isJsonObject)(item)) {
|
|
349
|
-
const customObject = this.customObjManager.getMatchingCustomObject(item);
|
|
350
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(item, copyOnWrite);
|
|
351
|
-
if (customObject) {
|
|
352
|
-
yield this.handleCustomObjectAsync(child, customObject);
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
yield this.redactSecretFieldsAsync(child, false);
|
|
356
|
-
}
|
|
357
|
-
container.set(String(index), child.result());
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return container.result();
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
redactAllArrayValuesAsync(array, forceDeepRedaction, copyOnWrite) {
|
|
364
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
-
const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
|
|
366
|
-
for (let index = 0; index < array.length; index++) {
|
|
367
|
-
const item = array[index];
|
|
368
|
-
const key = String(index);
|
|
369
|
-
if (Array.isArray(item)) {
|
|
370
|
-
container.set(key, yield this.redactAllArrayValuesAsync(item, forceDeepRedaction, copyOnWrite));
|
|
371
|
-
}
|
|
372
|
-
else if (!(0, types_1.isJsonObject)(item)) {
|
|
373
|
-
container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.toRedactablePrimitive)(item)));
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
const customObject = this.customObjManager.getMatchingCustomObject(item);
|
|
377
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(item, copyOnWrite);
|
|
378
|
-
if (customObject) {
|
|
379
|
-
yield this.handleCustomObjectAsync(child, customObject);
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
yield this.redactSecretFieldsAsync(child, forceDeepRedaction);
|
|
383
|
-
}
|
|
384
|
-
container.set(key, child.result());
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return container.result();
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
redactNestedObjectAsync(value, key, forceDeepRedaction, parent) {
|
|
391
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
392
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(value, parent.copyOnWrite);
|
|
393
|
-
const customObject = this.customObjManager.getMatchingCustomObject(value);
|
|
394
|
-
if (customObject) {
|
|
395
|
-
yield this.handleCustomObjectAsync(child, customObject);
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
yield this.redactSecretFieldsAsync(child, forceDeepRedaction || this.secretManager.isDeepSecretKey(key));
|
|
399
|
-
}
|
|
178
|
+
redactNestedObject(value, key, forceDeepRedaction, parent, pathSegments) {
|
|
179
|
+
const child = (0, objectRedactorMutation_1.createContainerMutation)(value, parent.copyOnWrite);
|
|
180
|
+
const customObject = this.ruleResolver.getMatchingSchema(value);
|
|
181
|
+
const work = customObject
|
|
182
|
+
? this.handleCustomObject(child, customObject)
|
|
183
|
+
: this.redactSecretFields(child, this.ruleResolver.nestedObjectForceDeepRedaction(key, forceDeepRedaction), pathSegments);
|
|
184
|
+
return (0, maybeAsync_1.finalizeMaybeAsync)(work, () => {
|
|
400
185
|
if (parent.copyOnWrite) {
|
|
401
186
|
parent.set(key, child.result());
|
|
402
187
|
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
handleCustomObjectAsync(container, customObject) {
|
|
406
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
407
|
-
for (const key of Object.keys(customObject)) {
|
|
408
|
-
const fieldValue = container.source[key];
|
|
409
|
-
if (Array.isArray(fieldValue)) {
|
|
410
|
-
yield this.handleCustomObjectValueIfArrayAsync(container, key, customObject);
|
|
411
|
-
}
|
|
412
|
-
else if ((0, types_1.isJsonObject)(fieldValue)) {
|
|
413
|
-
yield this.handleCustomObjectValueIfObjectAsync(container, key, customObject);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
yield this.handleCustomObjectValueIfPrimitiveAsync(container, customObject, key);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
handleCustomObjectValueIfArrayAsync(container, key, customObject) {
|
|
422
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
423
|
-
const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
|
|
424
|
-
if (stringKey !== undefined) {
|
|
425
|
-
yield this.handleCustomObjectArrayValueIfStringKeySpecifiedAsync(container, key, stringKey);
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
yield this.handleCustomObjectArrayValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
188
|
+
}, this.asyncMode);
|
|
431
189
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
if (this.secretManager.isDeleteSecretKey(stringKey)) {
|
|
439
|
-
container.remove(key);
|
|
440
|
-
}
|
|
441
|
-
else if (this.secretManager.isFullSecretKey(stringKey)) {
|
|
442
|
-
container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
const isDeepSecretKey = this.secretManager.isDeepSecretKey(stringKey);
|
|
446
|
-
if (isDeepSecretKey || this.secretManager.isSecretKey(stringKey)) {
|
|
447
|
-
container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, isDeepSecretKey, container.copyOnWrite));
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
handleCustomObjectArrayValueIfMatchTypeSpecifiedAsync(container, key, matchType) {
|
|
453
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
-
const fieldValue = container.source[key];
|
|
455
|
-
if (!Array.isArray(fieldValue)) {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
yield (0, objectRedactorCustomObject_1.applyCustomObjectArrayMatchTypeAsync)(matchType, {
|
|
459
|
-
deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
|
|
460
|
-
redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue))); }),
|
|
461
|
-
redactDeep: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, true, container.copyOnWrite)); }),
|
|
462
|
-
redactShallow: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, false, container.copyOnWrite)); }),
|
|
463
|
-
passThrough: () => __awaiter(this, void 0, void 0, function* () {
|
|
464
|
-
yield this.redactArrayInObjectAsync(fieldValue, key, false, container);
|
|
465
|
-
})
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
handleCustomObjectValueIfObjectAsync(container, key, customObject) {
|
|
470
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
471
|
-
const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
|
|
472
|
-
if (stringKey !== undefined) {
|
|
473
|
-
yield this.handleCustomObjectObjectValueIfStringKeySpecifiedAsync(container, key, stringKey);
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
yield this.handleCustomObjectObjectValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
handleCustomObjectObjectValueIfStringKeySpecifiedAsync(container, key, stringKey) {
|
|
481
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
482
|
-
const fieldValue = container.source[key];
|
|
483
|
-
if (!(0, types_1.isJsonObject)(fieldValue)) {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
const customObject = this.customObjManager.getMatchingCustomObject(fieldValue);
|
|
487
|
-
if (customObject) {
|
|
488
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
489
|
-
yield this.handleCustomObjectAsync(child, customObject);
|
|
490
|
-
container.set(key, child.result());
|
|
491
|
-
}
|
|
492
|
-
else if (this.secretManager.isDeleteSecretKey(stringKey)) {
|
|
493
|
-
container.remove(key);
|
|
494
|
-
}
|
|
495
|
-
else if (this.secretManager.isFullSecretKey(stringKey)) {
|
|
496
|
-
container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
|
|
497
|
-
}
|
|
498
|
-
else if (this.secretManager.isDeepSecretKey(stringKey)) {
|
|
499
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
500
|
-
yield this.redactSecretFieldsAsync(child, true);
|
|
501
|
-
container.set(key, child.result());
|
|
502
|
-
}
|
|
503
|
-
else if (this.secretManager.isSecretKey(stringKey)) {
|
|
504
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
505
|
-
yield this.redactSecretFieldsAsync(child, false);
|
|
506
|
-
container.set(key, child.result());
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
handleCustomObjectObjectValueIfMatchTypeSpecifiedAsync(container, key, matchType) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
const fieldValue = container.source[key];
|
|
513
|
-
if (!(0, types_1.isJsonObject)(fieldValue)) {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
yield (0, objectRedactorCustomObject_1.applyCustomObjectObjectMatchTypeAsync)(matchType, {
|
|
517
|
-
deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
|
|
518
|
-
redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue))); }),
|
|
519
|
-
redactDeep: () => __awaiter(this, void 0, void 0, function* () {
|
|
520
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
521
|
-
yield this.redactSecretFieldsAsync(child, true);
|
|
522
|
-
container.set(key, child.result());
|
|
523
|
-
}),
|
|
524
|
-
redactShallowOrPass: () => __awaiter(this, void 0, void 0, function* () {
|
|
525
|
-
const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
|
|
526
|
-
yield this.redactSecretFieldsAsync(child, false);
|
|
527
|
-
container.set(key, child.result());
|
|
528
|
-
}),
|
|
529
|
-
ignore: () => __awaiter(this, void 0, void 0, function* () { return undefined; })
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
handleCustomObjectValueIfPrimitiveAsync(container, customObject, key) {
|
|
534
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
if (typeof customObject[key] === 'number') {
|
|
536
|
-
yield this.handleCustomObjectPrimitiveValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
const secretKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
|
|
540
|
-
if (secretKey === undefined) {
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
yield this.handleCustomObjectPrimitiveValueIfStringKeySpecifiedAsync(container, secretKey, key);
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
handleCustomObjectPrimitiveValueIfMatchTypeSpecifiedAsync(container, key, matchValue) {
|
|
547
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
548
|
-
yield (0, objectRedactorCustomObject_1.applyCustomObjectPrimitiveMatchTypeAsync)(matchValue, {
|
|
549
|
-
deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
|
|
550
|
-
redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(container.source[key]))); }),
|
|
551
|
-
redactScalar: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync(container.source[key])); }),
|
|
552
|
-
passThrough: () => __awaiter(this, void 0, void 0, function* () { return undefined; })
|
|
190
|
+
setPrimitiveValueIfSecret(container, key, secretKey, value, forceDeepRedaction) {
|
|
191
|
+
const redacted = (0, objectRedactorHelpers_1.redactPrimitiveValueIfSecret)(this.secretManager, this.valuePatternMatcher, (primitive) => this.redactPrimitive(primitive), secretKey, value, forceDeepRedaction);
|
|
192
|
+
if (redacted instanceof Promise) {
|
|
193
|
+
return redacted.then((result) => {
|
|
194
|
+
container.set(key, result);
|
|
553
195
|
});
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
handleCustomObjectPrimitiveValueIfStringKeySpecifiedAsync(container, secretKey, key) {
|
|
557
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
558
|
-
if (this.secretManager.isDeleteSecretKey(secretKey)) {
|
|
559
|
-
container.remove(key);
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
container.set(key, yield this.redactPrimitiveValueIfSecretAsync(secretKey, container.source[key], false));
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
redactPrimitiveValueIfSecretAsync(key, value, forceDeepRedaction) {
|
|
567
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
568
|
-
return (0, objectRedactorHelpers_1.redactPrimitiveValueIfSecret)(this.secretManager, this.valuePatternMatcher, (primitive) => this.redactPrimitiveAsync(primitive), key, value, forceDeepRedaction);
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
redactPrimitiveAsync(value) {
|
|
572
|
-
return this.primitiveRedactor.redactValue(value);
|
|
196
|
+
}
|
|
197
|
+
container.set(key, redacted);
|
|
573
198
|
}
|
|
574
199
|
}
|
|
575
200
|
exports.ObjectRedactorTraversal = ObjectRedactorTraversal;
|