Skip to content

Commit 3325114

Browse files
sujankotadmihalcik-virtruelizabethhealy
authored
feat(cmdline): assertions cli support (#204)
Co-authored-by: Dave Mihalcik <[email protected]> Co-authored-by: Elizabeth Healy <[email protected]>
1 parent 6301d32 commit 3325114

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cmdline/src/main/java/io/opentdf/platform/Command.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.opentdf.platform;
22

3+
import com.google.gson.JsonSyntaxException;
34
import com.nimbusds.jose.JOSEException;
45
import io.opentdf.platform.sdk.*;
56
import io.opentdf.platform.sdk.TDF;
67

8+
import com.google.gson.Gson;
79
import org.apache.commons.codec.DecoderException;
810
import picocli.CommandLine;
911
import picocli.CommandLine.HelpCommand;
@@ -64,7 +66,9 @@ void encrypt(
6466
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
6567
@Option(names = { "-c",
6668
"--autoconfigure" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
67-
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType)
69+
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType,
70+
@Option(names = { "--with-assertions" }, defaultValue = Option.NULL_VALUE) Optional<String> assertion)
71+
6872
throws IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
6973

7074
var sdk = buildSDK();
@@ -79,6 +83,21 @@ void encrypt(
7983
metadata.map(Config::withMetaData).ifPresent(configs::add);
8084
autoconfigure.map(Config::withAutoconfigure).ifPresent(configs::add);
8185
mimeType.map(Config::withMimeType).ifPresent(configs::add);
86+
87+
if (assertion.isPresent()) {
88+
var assertionConfig = assertion.get();
89+
Gson gson = new Gson();
90+
91+
AssertionConfig[] assertionConfigs;
92+
try {
93+
assertionConfigs = gson.fromJson(assertionConfig, AssertionConfig[].class);
94+
} catch (JsonSyntaxException e) {
95+
throw new RuntimeException("Failed to parse assertion, expects an list of assertions", e);
96+
}
97+
98+
configs.add(Config.withAssertionConfig(assertionConfigs));
99+
}
100+
82101
if (attributes.isPresent()) {
83102
configs.add(Config.withDataAttributes(attributes.get().split(",")));
84103
}

0 commit comments

Comments
 (0)