Skip to content

Commit 0c8962b

Browse files
authored
Cleanup Client Implementation and Java Library (#1074)
1 parent 3c73593 commit 0c8962b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2712
-2385
lines changed

.github/workflows/integration.yaml

+29-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
container: [ "udmis", "validator", "pubber", "misc" ]
2323
env:
2424
PUSH_REGISTRY: ghcr.io
25-
IMAGE_NAME: ${{ github.repository }}
2625
CONTAINER: ${{ matrix.container }}
2726
REF_NAME: ${{ github.ref_name }}
2827
steps:
@@ -40,11 +39,13 @@ jobs:
4039
registry: ${{ env.PUSH_REGISTRY }}
4140
username: ${{ github.actor }}
4241
password: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Convert repository name to lowercase
43+
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
4344
- name: Container build and push
4445
run: |
4546
revhash=$(git log -n 1 --pretty=format:"%h")
4647
IMAGE_HASH=g${revhash:0:8}
47-
PUSH_REPO=$PUSH_REGISTRY/${IMAGE_NAME,,}
48+
PUSH_REPO=$PUSH_REGISTRY/$IMAGE_NAME
4849
4950
TAG_BASE=$PUSH_REPO:$CONTAINER
5051
PUSH_TAG=${TAG_BASE}-$IMAGE_HASH
@@ -66,6 +67,28 @@ jobs:
6667
echo
6768
docker history $PUSH_TAG
6869
70+
maven:
71+
name: Publish maven package (pubber)
72+
runs-on: ubuntu-latest
73+
permissions:
74+
contents: read
75+
packages: write
76+
timeout-minutes: 5
77+
env:
78+
GITHUB_ACTOR: ${{ github.actor }}
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
steps:
81+
- uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0
84+
fetch-tags: true
85+
- uses: actions/setup-java@v4
86+
with:
87+
distribution: 'temurin'
88+
java-version: '17'
89+
- name: Publish maven package
90+
run: pubber/bin/publish
91+
6992
simple:
7093
name: Simple sequence test
7194
runs-on: ubuntu-latest
@@ -76,7 +99,6 @@ jobs:
7699
matrix:
77100
device_id: [ "AHU-1", "AHU-22", "GAT-123" ]
78101
env:
79-
IMAGE_NAME: ${{ github.repository }}
80102
REF_NAME: ${{ github.ref_name }}
81103
DEVICE_ID: ${{ matrix.device_id }}
82104
steps:
@@ -89,6 +111,8 @@ jobs:
89111
jq ".device_id = \"$DEVICE_ID\"" site_model/cloud_iot_config.json | sponge site_model/cloud_iot_config.json
90112
jq . site_model/cloud_iot_config.json
91113
docker network create udminet --subnet 192.168.99.0/24
114+
- name: Convert repository name to lowercase
115+
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
92116
- name: Start UDMIS container
93117
run: |
94118
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:udmis-$REF_NAME
@@ -148,7 +172,6 @@ jobs:
148172
timeout-minutes: 5
149173
needs: images
150174
env:
151-
IMAGE_NAME: ${{ github.repository }}
152175
REF_NAME: ${{ github.ref_name }}
153176
DEVICE_ID: ${{'AHU-1'}}
154177
steps:
@@ -161,6 +184,8 @@ jobs:
161184
jq ".device_id = \"$DEVICE_ID\"" site_model/cloud_iot_config.json | sponge site_model/cloud_iot_config.json
162185
jq . site_model/cloud_iot_config.json
163186
docker network create udminet --subnet 192.168.99.0/24
187+
- name: Convert repository name to lowercase
188+
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
164189
- name: Start UDMIS container
165190
run: |
166191
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:udmis-$REF_NAME

common/src/main/java/com/google/udmi/util/CertManager.java

+36-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
import static java.lang.String.format;
66

77
import java.io.BufferedInputStream;
8+
import java.io.ByteArrayInputStream;
89
import java.io.File;
910
import java.io.FileInputStream;
1011
import java.io.FileReader;
12+
import java.io.InputStream;
13+
import java.io.Reader;
14+
import java.io.StringReader;
1115
import java.security.KeyStore;
1216
import java.security.PrivateKey;
1317
import java.security.Security;
@@ -49,6 +53,9 @@ public class CertManager {
4953
private final File crtFile;
5054
private final char[] password;
5155
private final Transport transport;
56+
private final String caCertificate;
57+
private final String clientCertificate;
58+
private final String clientPrivateKey;
5259

5360
{
5461
Security.addProvider(new BouncyCastleProvider());
@@ -61,6 +68,9 @@ public CertManager(File caCrtFile, File clientDir, Transport transport,
6168
String passString, Consumer<String> logging) {
6269
this.caCrtFile = caCrtFile;
6370
this.transport = transport;
71+
this.caCertificate = null;
72+
this.clientCertificate = null;
73+
this.clientPrivateKey = null;
6474

6575
if (Transport.SSL.equals(transport)) {
6676
String prefix = keyPrefix(clientDir);
@@ -78,6 +88,18 @@ public CertManager(File caCrtFile, File clientDir, Transport transport,
7888
}
7989
}
8090

91+
public CertManager(String caCertificate, String clientCertificate, String clientPrivateKey,
92+
Transport transport, String passString) {
93+
caCrtFile = null;
94+
crtFile = null;
95+
keyFile = null;
96+
this.transport = transport;
97+
this.password = passString.toCharArray();
98+
this.caCertificate = caCertificate;
99+
this.clientCertificate = clientCertificate;
100+
this.clientPrivateKey = clientPrivateKey;
101+
}
102+
81103
private String keyPrefix(File clientDir) {
82104
File rsaCrtFile = new File(clientDir, "rsa_private.crt");
83105
File ecCrtFile = new File(clientDir, "ec_private.crt");
@@ -92,18 +114,27 @@ private String keyPrefix(File clientDir) {
92114
public SSLSocketFactory getCertSocketFactory() throws Exception {
93115
CertificateFactory certFactory = CertificateFactory.getInstance(X509_FACTORY);
94116

117+
InputStream caCertStream = caCrtFile != null
118+
? new FileInputStream(caCrtFile)
119+
: new ByteArrayInputStream(caCertificate.getBytes());
95120
final X509Certificate caCert;
96-
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(caCrtFile))) {
121+
try (BufferedInputStream bis = new BufferedInputStream(caCertStream)) {
97122
caCert = (X509Certificate) certFactory.generateCertificate(bis);
98123
}
99124

125+
InputStream clientCertStream = crtFile != null
126+
? new FileInputStream(crtFile)
127+
: new ByteArrayInputStream(clientCertificate.getBytes());
100128
final X509Certificate clientCert;
101-
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(crtFile))) {
129+
try (BufferedInputStream bis = new BufferedInputStream(clientCertStream)) {
102130
clientCert = (X509Certificate) certFactory.generateCertificate(bis);
103131
}
104132

133+
Reader keyReader = keyFile != null
134+
? new FileReader(keyFile)
135+
: new StringReader(clientPrivateKey);
105136
final PrivateKey privateKey;
106-
try (PEMParser pemParser = new PEMParser(new FileReader(keyFile))) {
137+
try (PEMParser pemParser = new PEMParser(keyReader)) {
107138
Object pemObject = pemParser.readObject();
108139
if (pemObject instanceof PEMEncryptedKeyPair keyPair) {
109140
PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder().build(password);
@@ -114,7 +145,8 @@ public SSLSocketFactory getCertSocketFactory() throws Exception {
114145
privateKey = converter.getPrivateKey(keyPair);
115146
} else {
116147
throw new RuntimeException(format("Unknown pem file type %s from %s",
117-
pemObject.getClass().getSimpleName(), keyFile.getAbsolutePath()));
148+
pemObject.getClass().getSimpleName(),
149+
keyFile == null ? "" : keyFile.getAbsolutePath()));
118150
}
119151
}
120152

etc/validator.out

+15-15
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ sites/udmi_site_model/out/devices/AHU-22/state.out
339339
"sub_folder" : "update",
340340
"sub_type" : "state",
341341
"status" : {
342-
"message" : "1 schema violations found",
343-
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
342+
"message" : "2 schema violations found",
343+
"detail" : "state_update: 2 schema violations found; /system: object has missing required properties ([\"serial_no\",\"software\"]); /system/hardware: object has missing required properties ([\"make\",\"model\"])",
344344
"category" : "validation.device.schema",
345345
"timestamp" : "REDACTED_TIMESTAMP",
346346
"level" : 500
347347
},
348348
"errors" : [ {
349-
"message" : "1 schema violations found",
350-
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
349+
"message" : "2 schema violations found",
350+
"detail" : "state_update: 2 schema violations found; /system: object has missing required properties ([\"serial_no\",\"software\"]); /system/hardware: object has missing required properties ([\"make\",\"model\"])",
351351
"category" : "validation.device.schema",
352352
"timestamp" : "REDACTED_TIMESTAMP",
353353
"level" : 500
@@ -382,15 +382,15 @@ sites/udmi_site_model/out/devices/AHU-22/state_system.out
382382
"sub_folder" : "system",
383383
"sub_type" : "state",
384384
"status" : {
385-
"message" : "1 schema violations found",
386-
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
385+
"message" : "2 schema violations found",
386+
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
387387
"category" : "validation.device.schema",
388388
"timestamp" : "REDACTED_TIMESTAMP",
389389
"level" : 500
390390
},
391391
"errors" : [ {
392-
"message" : "1 schema violations found",
393-
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
392+
"message" : "2 schema violations found",
393+
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
394394
"category" : "validation.device.schema",
395395
"timestamp" : "REDACTED_TIMESTAMP",
396396
"level" : 500
@@ -795,14 +795,14 @@ sites/udmi_site_model/out/devices/SNS-4/state.out
795795
"sub_type" : "state",
796796
"status" : {
797797
"message" : "Multiple validation errors",
798-
"detail" : "1 schema violations found; Device has missing points: split_threshold, triangulating_axis",
798+
"detail" : "2 schema violations found; Device has missing points: split_threshold, triangulating_axis",
799799
"category" : "validation.device.multiple",
800800
"timestamp" : "REDACTED_TIMESTAMP",
801801
"level" : 500
802802
},
803803
"errors" : [ {
804-
"message" : "1 schema violations found",
805-
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
804+
"message" : "2 schema violations found",
805+
"detail" : "state_update: 2 schema violations found; /system: object has missing required properties ([\"serial_no\",\"software\"]); /system/hardware: object has missing required properties ([\"make\",\"model\"])",
806806
"category" : "validation.device.schema",
807807
"timestamp" : "REDACTED_TIMESTAMP",
808808
"level" : 500
@@ -850,15 +850,15 @@ sites/udmi_site_model/out/devices/SNS-4/state_system.out
850850
"sub_folder" : "system",
851851
"sub_type" : "state",
852852
"status" : {
853-
"message" : "1 schema violations found",
854-
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
853+
"message" : "2 schema violations found",
854+
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
855855
"category" : "validation.device.schema",
856856
"timestamp" : "REDACTED_TIMESTAMP",
857857
"level" : 500
858858
},
859859
"errors" : [ {
860-
"message" : "1 schema violations found",
861-
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
860+
"message" : "2 schema violations found",
861+
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
862862
"category" : "validation.device.schema",
863863
"timestamp" : "REDACTED_TIMESTAMP",
864864
"level" : 500

pubber/.idea/runConfigurations/Swarm.xml

-17
This file was deleted.

pubber/bin/publish

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash -e
2+
3+
UDMI_ROOT=$(realpath $(dirname $0)/../..)
4+
cd $UDMI_ROOT
5+
6+
DEFAULT_TASK="publish"
7+
task=${1:-$DEFAULT_TASK}
8+
9+
# Validate the task
10+
VALID_TASKS=("publish" "publishToMavenLocal")
11+
if [[ ! " ${VALID_TASKS[@]} " =~ " $task " ]]; then
12+
echo "Usage: $0 [publishTask]"
13+
echo " publishTask: Task to execute. Default is '$DEFAULT_TASK'."
14+
echo " Valid tasks are: ${VALID_TASKS[*]}"
15+
echo
16+
echo "Error: Invalid task '$task'"
17+
exit 1
18+
fi
19+
20+
source $UDMI_ROOT/etc/shell_common.sh
21+
22+
echo pubber/gradlew -p pubber $task
23+
echo $UDMI_VERSION
24+
$UDMI_ROOT/pubber/gradlew -p pubber $task

pubber/build.gradle

+22
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ plugins {
1616
id 'java'
1717
id 'jacoco'
1818
id 'checkstyle'
19+
id 'maven-publish'
1920
}
2021

2122
group 'daq-pubber'
@@ -76,6 +77,27 @@ repositories {
7677
maven { url 'https://jitpack.io' }
7778
}
7879

80+
publishing {
81+
repositories {
82+
maven {
83+
url = "https://maven.pkg.github.com/${System.getenv("GITHUB_REPOSITORY")}"
84+
name = "GitHubPackages"
85+
credentials {
86+
username = System.getenv("GITHUB_ACTOR")
87+
password = System.getenv("GITHUB_TOKEN")
88+
}
89+
}
90+
}
91+
publications {
92+
mavenJava(MavenPublication) {
93+
groupId = 'com.google.udmi'
94+
artifactId = 'lib'
95+
version = System.getenv("UDMI_VERSION")
96+
from components.java
97+
}
98+
}
99+
}
100+
79101
dependencies {
80102
implementation 'io.jsonwebtoken:jjwt:0.9.1'
81103
implementation 'javax.xml.bind:jaxb-api:2.3.1'

0 commit comments

Comments
 (0)