Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion cmdline/src/main/java/io/opentdf/platform/Command.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.opentdf.platform;

import com.google.gson.JsonSyntaxException;
import com.nimbusds.jose.JOSEException;
import io.opentdf.platform.sdk.*;
import io.opentdf.platform.sdk.TDF;

import com.google.gson.Gson;
import org.apache.commons.codec.DecoderException;
import picocli.CommandLine;
import picocli.CommandLine.HelpCommand;
Expand Down Expand Up @@ -64,7 +66,9 @@ void encrypt(
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
@Option(names = { "-c",
"--autoconfigure" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType)
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType,
@Option(names = { "--with-assertions" }, defaultValue = Option.NULL_VALUE) Optional<String> assertion)

throws IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {

var sdk = buildSDK();
Expand All @@ -79,6 +83,21 @@ void encrypt(
metadata.map(Config::withMetaData).ifPresent(configs::add);
autoconfigure.map(Config::withAutoconfigure).ifPresent(configs::add);
mimeType.map(Config::withMimeType).ifPresent(configs::add);

if (assertion.isPresent()) {
var assertionConfig = assertion.get();
Gson gson = new Gson();

AssertionConfig[] assertionConfigs;
try {
assertionConfigs = gson.fromJson(assertionConfig, AssertionConfig[].class);
} catch (JsonSyntaxException e) {
throw new RuntimeException("Failed to parse assertion, expects an list of assertions", e);
}

configs.add(Config.withAssertionConfig(assertionConfigs));
}

if (attributes.isPresent()) {
configs.add(Config.withDataAttributes(attributes.get().split(",")));
}
Expand Down