Skip to content

Commit c0edd22

Browse files
authored
runtime-v2: add EL function to mark strings as sensitive (#1230)
1 parent e48ee94 commit c0edd22

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

runtime/v2/runner-test/src/test/java/com/walmartlabs/concord/runtime/v2/runner/MainTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,17 @@ public void prefixedFunctionsInExpressions() throws Exception {
17601760
assertLog(runtime.allLogs(), ".*Hello, world!.*");
17611761
}
17621762

1763+
@Test
1764+
public void sensitiveFunction() throws Exception {
1765+
deploy("sensitiveFunction");
1766+
1767+
save(ProcessConfiguration.builder().build());
1768+
1769+
run();
1770+
1771+
assertLog(runtime.allLogs(), ".*" + Pattern.quote("The '******' is masked now") + ".*");
1772+
}
1773+
17631774
private void deploy(String name) throws URISyntaxException, IOException {
17641775
runtime.deploy(name);
17651776
}

runtime/v2/runner-test/src/test/java/com/walmartlabs/concord/runtime/v2/runner/functions/TestFunction.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package com.walmartlabs.concord.runtime.v2.runner.functions;
22

3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
323
import com.walmartlabs.concord.runtime.v2.sdk.ELFunction;
424

525
import javax.inject.Named;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flows:
2+
default:
3+
- set:
4+
regularValue: "regularValue"
5+
secretValue: "${sensitive(regularValue)}"
6+
- log: "The 'regularValue' is masked now"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.walmartlabs.concord.runtime.v2.runner.el.functions;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
23+
import com.walmartlabs.concord.runtime.v2.sdk.ELFunction;
24+
import com.walmartlabs.concord.runtime.v2.sdk.SensitiveDataHolder;
25+
26+
import javax.inject.Inject;
27+
28+
import static java.util.Objects.requireNonNull;
29+
30+
public class MarkAsSensitiveFunction {
31+
32+
private static SensitiveDataHolder sensitiveData;
33+
34+
@Inject
35+
public MarkAsSensitiveFunction(SensitiveDataHolder sensitiveData) {
36+
MarkAsSensitiveFunction.sensitiveData = requireNonNull(sensitiveData);
37+
}
38+
39+
@ELFunction
40+
public static String sensitive(Object v) {
41+
if (MarkAsSensitiveFunction.sensitiveData == null) {
42+
throw new IllegalStateException("MaskFunction must be initialized first");
43+
}
44+
45+
if (v == null) {
46+
return null;
47+
}
48+
49+
if (v instanceof String s) {
50+
if (s.isBlank()) {
51+
return s;
52+
}
53+
sensitiveData.add(s);
54+
return s;
55+
}
56+
57+
throw new IllegalArgumentException("Only string values can be masked. Got a " + v.getClass() + " instead");
58+
}
59+
}

runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/guice/ExpressionSupportModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import com.google.inject.spi.TypeEncounter;
2828
import com.google.inject.spi.TypeListener;
2929
import com.walmartlabs.concord.runtime.v2.runner.el.DefaultExpressionEvaluator;
30-
import com.walmartlabs.concord.runtime.v2.sdk.ELFunction;
3130
import com.walmartlabs.concord.runtime.v2.runner.el.FunctionHolder;
3231
import com.walmartlabs.concord.runtime.v2.runner.el.functions.*;
32+
import com.walmartlabs.concord.runtime.v2.sdk.ELFunction;
3333
import com.walmartlabs.concord.runtime.v2.sdk.ExpressionEvaluator;
3434

3535
import java.lang.reflect.Modifier;
@@ -84,6 +84,7 @@ public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
8484
binder.bind(HasVariableFunction.class).asEagerSingleton();
8585
binder.bind(IsDebugFunction.class).asEagerSingleton();
8686
binder.bind(IsDryRunFunction.class).asEagerSingleton();
87+
binder.bind(MarkAsSensitiveFunction.class).asEagerSingleton();
8788
binder.bind(OrDefaultFunction.class).asEagerSingleton();
8889
binder.bind(ThrowFunction.class).asEagerSingleton();
8990
binder.bind(UuidFunction.class).asEagerSingleton();

0 commit comments

Comments
 (0)