Skip to content

Commit ba9b2d5

Browse files
authored
refactor!: move to single jar (#160)
resolves: #156
1 parent 6fa6823 commit ba9b2d5

32 files changed

+1191
-1125
lines changed

.github/workflows/checks.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ jobs:
138138
--client-id=opentdf-sdk \
139139
--client-secret=secret \
140140
--platform-endpoint=localhost:8080 \
141-
-i -h \
141+
-h\
142142
encrypt --kas-url=localhost:8080 --mime-type=text/plain --attr https://example.com/attr/attr1/value/value1 --autoconfigure=false -f data -m 'here is some metadata' > test.tdf
143143
144144
java -jar target/cmdline.jar \
145145
--client-id=opentdf-sdk \
146146
--client-secret=secret \
147147
--platform-endpoint=localhost:8080 \
148-
-i -h \
148+
-h\
149149
decrypt -f test.tdf > decrypted
150150
151151
java -jar target/cmdline.jar \
152152
--client-id=opentdf-sdk \
153153
--client-secret=secret \
154154
--platform-endpoint=localhost:8080 \
155-
-i -h \
155+
-h\
156156
metadata -f test.tdf > metadata
157157
158158
if ! diff -q data decrypted; then
@@ -174,14 +174,14 @@ jobs:
174174
--client-id=opentdf-sdk \
175175
--client-secret=secret \
176176
--platform-endpoint=localhost:8080 \
177-
-i -h \
177+
-h\
178178
encryptnano --kas-url=http://localhost:8080 --attr https://example.com/attr/attr1/value/value1 -f data -m 'here is some metadata' > nano.ntdf
179179
180180
java -jar target/cmdline.jar \
181181
--client-id=opentdf-sdk \
182182
--client-secret=secret \
183183
--platform-endpoint=localhost:8080 \
184-
-i -h \
184+
-h\
185185
decryptnano -f nano.ntdf > decrypted
186186
187187
if ! diff -q data decrypted; then
@@ -216,21 +216,21 @@ jobs:
216216
--client-id=opentdf-sdk \
217217
--client-secret=secret \
218218
--platform-endpoint=localhost:8080 \
219-
-i -h \
219+
-h\
220220
encrypt --kas-url=localhost:8080,localhost:8282 -f data -m 'here is some metadata' > test.tdf
221221
222222
java -jar target/cmdline.jar \
223223
--client-id=opentdf-sdk \
224224
--client-secret=secret \
225225
--platform-endpoint=localhost:8080 \
226-
-i -h \
226+
-h\
227227
decrypt -f test.tdf > decrypted
228228
229229
java -jar target/cmdline.jar \
230230
--client-id=opentdf-sdk \
231231
--client-secret=secret \
232232
--platform-endpoint=localhost:8080 \
233-
-i -h \
233+
-h\
234234
metadata -f test.tdf > metadata
235235
236236
if ! diff -q data decrypted; then

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
protocol/src/main/protogen
1+
sdk/src/main/protogen
22
/.idea/
33
target/
44
.vscode/
55
.DS_Store
6+
sdk/sample.tdf

buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ managed:
99
- buf.build/grpc-ecosystem/grpc-gateway
1010
plugins:
1111
- plugin: buf.build/protocolbuffers/java:v25.3
12-
out: protocol/src/main/protogen
12+
out: sdk/src/main/protogen
1313
- plugin: buf.build/grpc/java:v1.61.1
14-
out: protocol/src/main/protogen
14+
out: sdk/src/main/protogen

cmdline/pom.xml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
77
<groupId>io.opentdf.platform</groupId>
88
<artifactId>sdk-pom</artifactId>
9-
<version>0.6.2-SNAPSHOT</version><!-- {x-version-update:java-sdk:current} -->
9+
<version>${revision}</version>
1010
</parent>
1111
<artifactId>cmdline</artifactId>
1212
<properties>
@@ -18,27 +18,52 @@
1818
<plugins>
1919
<plugin>
2020
<groupId>org.apache.maven.plugins</groupId>
21-
<artifactId>maven-assembly-plugin</artifactId>
22-
<version>3.7.1</version>
21+
<artifactId>maven-shade-plugin</artifactId>
22+
<version>3.5.3</version>
2323
<executions>
2424
<execution>
2525
<phase>package</phase>
2626
<goals>
27-
<goal>single</goal>
27+
<goal>shade</goal>
2828
</goals>
29+
<configuration>
30+
31+
<createDependencyReducedPom>false</createDependencyReducedPom>
32+
<finalName>cmdline</finalName>
33+
<transformers>
34+
<transformer
35+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
36+
<mainClass>io.opentdf.platform.TDF</mainClass>
37+
<manifestEntries>
38+
<Implementation-Version>${version}</Implementation-Version>
39+
<Main-Class>io.opentdf.platform.TDF</Main-Class>
40+
</manifestEntries>
41+
</transformer>
42+
<transformer
43+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
44+
</transformers>
45+
<filters>
46+
<filter>
47+
<artifact>*:*</artifact>
48+
<excludes>
49+
<exclude>META-INF/*.SF</exclude>
50+
<exclude>META-INF/*.DSA</exclude>
51+
<exclude>META-INF/*.RSA</exclude>
52+
</excludes>
53+
</filter>
54+
</filters>
55+
</configuration>
2956
</execution>
3057
</executions>
58+
</plugin>
59+
60+
<!-- Skip deployment for this child module -->
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-deploy-plugin</artifactId>
64+
<version>3.1.1</version>
3165
<configuration>
32-
<descriptorRefs>
33-
<descriptorRef>jar-with-dependencies</descriptorRef>
34-
</descriptorRefs>
35-
<finalName>cmdline</finalName>
36-
<appendAssemblyId>false</appendAssemblyId>
37-
<archive>
38-
<manifest>
39-
<mainClass>io.opentdf.platform.TDF</mainClass>
40-
</manifest>
41-
</archive>
66+
<skip>true</skip>
4267
</configuration>
4368
</plugin>
4469
</plugins>
@@ -52,7 +77,7 @@
5277
<dependency>
5378
<groupId>io.opentdf.platform</groupId>
5479
<artifactId>sdk</artifactId>
55-
<version>0.6.2-SNAPSHOT</version><!-- {x-version-update:java-sdk:current} -->
80+
<version>${project.version}</version>
5681
</dependency>
5782
</dependencies>
5883
</project>

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,89 +39,88 @@
3939
@CommandLine.Command(name = "tdf")
4040
class Command {
4141

42-
@Option(names = {"--client-secret"}, required = true)
42+
@Option(names = { "--client-secret" }, required = true)
4343
private String clientSecret;
4444

45-
@Option(names = {"-h", "--plaintext"}, defaultValue = "false")
45+
@Option(names = { "-h", "--plaintext" }, defaultValue = "false")
4646
private boolean plaintext;
4747

48-
@Option(names = {"-i", "--insecure"}, defaultValue = "false")
48+
@Option(names = { "-i", "--insecure" }, defaultValue = "false")
4949
private boolean insecure;
5050

51-
@Option(names = {"--client-id"}, required = true)
51+
@Option(names = { "--client-id" }, required = true)
5252
private String clientId;
5353

54-
@Option(names = {"-p", "--platform-endpoint"}, required = true)
54+
@Option(names = { "-p", "--platform-endpoint" }, required = true)
5555
private String platformEndpoint;
5656

5757
@CommandLine.Command(name = "encrypt")
5858
void encrypt(
59-
@Option(names = {"-f", "--file"}, defaultValue = Option.NULL_VALUE) Optional<File> file,
60-
@Option(names = {"-k", "--kas-url"}, required = true, split = ",") List<String> kas,
61-
@Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
59+
@Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional<File> file,
60+
@Option(names = { "-k", "--kas-url" }, required = true, split = ",") List<String> kas,
61+
@Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
6262
// cant split on optional parameters
63-
@Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
64-
@Option(names = {"-c", "--autoconfigure"}, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
65-
@Option(names = {"--mime-type"}, defaultValue = Option.NULL_VALUE) Optional<String> mimeType) throws
66-
IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
63+
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
64+
@Option(names = { "-c",
65+
"--autoconfigure" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
66+
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType)
67+
throws IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
6768

6869
var sdk = buildSDK();
6970
var kasInfos = kas.stream().map(k -> {
7071
var ki = new Config.KASInfo();
7172
ki.URL = k;
7273
return ki;
7374
}).toArray(Config.KASInfo[]::new);
74-
7575

7676
List<Consumer<Config.TDFConfig>> configs = new ArrayList<>();
7777
configs.add(Config.withKasInformation(kasInfos));
7878
metadata.map(Config::withMetaData).ifPresent(configs::add);
7979
autoconfigure.map(Config::withAutoconfigure).ifPresent(configs::add);
8080
mimeType.map(Config::withMimeType).ifPresent(configs::add);
81-
if (attributes.isPresent()){
81+
if (attributes.isPresent()) {
8282
configs.add(Config.withDataAttributes(attributes.get().split(",")));
8383
}
8484
var tdfConfig = Config.newTDFConfig(configs.toArray(Consumer[]::new));
8585
try (var in = file.isEmpty() ? new BufferedInputStream(System.in) : new FileInputStream(file.get())) {
8686
try (var out = new BufferedOutputStream(System.out)) {
87-
new TDF().createTDF(in, out, tdfConfig,
88-
sdk.getServices().kas(),
89-
sdk.getServices().attributes()
90-
);
87+
new TDF().createTDF(in, out, tdfConfig,
88+
sdk.getServices().kas(),
89+
sdk.getServices().attributes());
9190
}
9291
}
9392
}
9493

9594
private SDK buildSDK() {
9695
SDKBuilder builder = new SDKBuilder();
97-
if (insecure){
96+
if (insecure) {
9897
SSLFactory sslFactory = SSLFactory.builder()
99-
.withUnsafeTrustMaterial() // Trust all certificates
100-
.build();
98+
.withUnsafeTrustMaterial() // Trust all certificates
99+
.build();
101100
builder.sslFactory(sslFactory);
102101
}
103-
104-
return builder.platformEndpoint(platformEndpoint)
105-
.clientSecret(clientId, clientSecret)
106-
.useInsecurePlaintextConnection(plaintext)
102+
103+
return builder.platformEndpoint(platformEndpoint)
104+
.clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(plaintext)
107105
.build();
108106
}
109107

110108
@CommandLine.Command(name = "decrypt")
111-
void decrypt(@Option(names = {"-f", "--file"}, required = true) Path tdfPath) throws IOException,
109+
void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath) throws IOException,
112110
InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException,
113111
BadPaddingException, InvalidKeyException, TDF.FailedToCreateGMAC,
114112
JOSEException, ParseException, NoSuchAlgorithmException, DecoderException {
115113
var sdk = buildSDK();
116114
try (var in = FileChannel.open(tdfPath, StandardOpenOption.READ)) {
117115
try (var stdout = new BufferedOutputStream(System.out)) {
118-
var reader = new TDF().loadTDF(in, sdk.getServices().kas());
119-
reader.readPayload(stdout);
120-
}
116+
var reader = new TDF().loadTDF(in, sdk.getServices().kas());
117+
reader.readPayload(stdout);
118+
}
121119
}
122120
}
121+
123122
@CommandLine.Command(name = "metadata")
124-
void readMetadata(@Option(names = {"-f", "--file"}, required = true) Path tdfPath) throws IOException,
123+
void readMetadata(@Option(names = { "-f", "--file" }, required = true) Path tdfPath) throws IOException,
125124
TDF.FailedToCreateGMAC, JOSEException, NoSuchAlgorithmException, ParseException, DecoderException {
126125
var sdk = buildSDK();
127126

@@ -135,10 +134,11 @@ void readMetadata(@Option(names = {"-f", "--file"}, required = true) Path tdfPat
135134

136135
@CommandLine.Command(name = "encryptnano")
137136
void createNanoTDF(
138-
@Option(names = {"-f", "--file"}, defaultValue = Option.NULL_VALUE) Optional<File> file,
139-
@Option(names = {"-k", "--kas-url"}, required = true) List<String> kas,
140-
@Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
141-
@Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional<String> attributes) throws Exception {
137+
@Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional<File> file,
138+
@Option(names = { "-k", "--kas-url" }, required = true) List<String> kas,
139+
@Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
140+
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes)
141+
throws Exception {
142142

143143
var sdk = buildSDK();
144144
var kasInfos = kas.stream().map(k -> {
@@ -163,7 +163,7 @@ void createNanoTDF(
163163
}
164164

165165
@CommandLine.Command(name = "decryptnano")
166-
void readNanoTDF(@Option(names = {"-f", "--file"}, required = true) Path nanoTDFPath) throws Exception {
166+
void readNanoTDF(@Option(names = { "-f", "--file" }, required = true) Path nanoTDFPath) throws Exception {
167167
var sdk = buildSDK();
168168
try (var in = FileChannel.open(nanoTDFPath, StandardOpenOption.READ)) {
169169
try (var stdout = new BufferedOutputStream(System.out)) {

0 commit comments

Comments
 (0)