Skip to content

Commit

Permalink
Merge branch 'master' into sheet-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
khyatimahendru committed Jan 27, 2025
2 parents bc5126d + 0c8962b commit a411ed5
Show file tree
Hide file tree
Showing 55 changed files with 2,712 additions and 2,385 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
container: [ "udmis", "validator", "pubber", "misc" ]
env:
PUSH_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CONTAINER: ${{ matrix.container }}
REF_NAME: ${{ github.ref_name }}
steps:
Expand All @@ -40,11 +39,13 @@ jobs:
registry: ${{ env.PUSH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Container build and push
run: |
revhash=$(git log -n 1 --pretty=format:"%h")
IMAGE_HASH=g${revhash:0:8}
PUSH_REPO=$PUSH_REGISTRY/${IMAGE_NAME,,}
PUSH_REPO=$PUSH_REGISTRY/$IMAGE_NAME
TAG_BASE=$PUSH_REPO:$CONTAINER
PUSH_TAG=${TAG_BASE}-$IMAGE_HASH
Expand All @@ -66,6 +67,28 @@ jobs:
echo
docker history $PUSH_TAG
maven:
name: Publish maven package (pubber)
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 5
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Publish maven package
run: pubber/bin/publish

simple:
name: Simple sequence test
runs-on: ubuntu-latest
Expand All @@ -76,7 +99,6 @@ jobs:
matrix:
device_id: [ "AHU-1", "AHU-22", "GAT-123" ]
env:
IMAGE_NAME: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
DEVICE_ID: ${{ matrix.device_id }}
steps:
Expand All @@ -89,6 +111,8 @@ jobs:
jq ".device_id = \"$DEVICE_ID\"" site_model/cloud_iot_config.json | sponge site_model/cloud_iot_config.json
jq . site_model/cloud_iot_config.json
docker network create udminet --subnet 192.168.99.0/24
- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Start UDMIS container
run: |
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:udmis-$REF_NAME
Expand Down Expand Up @@ -148,7 +172,6 @@ jobs:
timeout-minutes: 5
needs: images
env:
IMAGE_NAME: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
DEVICE_ID: ${{'AHU-1'}}
steps:
Expand All @@ -161,6 +184,8 @@ jobs:
jq ".device_id = \"$DEVICE_ID\"" site_model/cloud_iot_config.json | sponge site_model/cloud_iot_config.json
jq . site_model/cloud_iot_config.json
docker network create udminet --subnet 192.168.99.0/24
- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Start UDMIS container
run: |
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:udmis-$REF_NAME
Expand Down
40 changes: 36 additions & 4 deletions common/src/main/java/com/google/udmi/util/CertManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import static java.lang.String.format;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Security;
Expand Down Expand Up @@ -49,6 +53,9 @@ public class CertManager {
private final File crtFile;
private final char[] password;
private final Transport transport;
private final String caCertificate;
private final String clientCertificate;
private final String clientPrivateKey;

{
Security.addProvider(new BouncyCastleProvider());
Expand All @@ -61,6 +68,9 @@ public CertManager(File caCrtFile, File clientDir, Transport transport,
String passString, Consumer<String> logging) {
this.caCrtFile = caCrtFile;
this.transport = transport;
this.caCertificate = null;
this.clientCertificate = null;
this.clientPrivateKey = null;

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

public CertManager(String caCertificate, String clientCertificate, String clientPrivateKey,
Transport transport, String passString) {
caCrtFile = null;
crtFile = null;
keyFile = null;
this.transport = transport;
this.password = passString.toCharArray();
this.caCertificate = caCertificate;
this.clientCertificate = clientCertificate;
this.clientPrivateKey = clientPrivateKey;
}

private String keyPrefix(File clientDir) {
File rsaCrtFile = new File(clientDir, "rsa_private.crt");
File ecCrtFile = new File(clientDir, "ec_private.crt");
Expand All @@ -92,18 +114,27 @@ private String keyPrefix(File clientDir) {
public SSLSocketFactory getCertSocketFactory() throws Exception {
CertificateFactory certFactory = CertificateFactory.getInstance(X509_FACTORY);

InputStream caCertStream = caCrtFile != null
? new FileInputStream(caCrtFile)
: new ByteArrayInputStream(caCertificate.getBytes());
final X509Certificate caCert;
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(caCrtFile))) {
try (BufferedInputStream bis = new BufferedInputStream(caCertStream)) {
caCert = (X509Certificate) certFactory.generateCertificate(bis);
}

InputStream clientCertStream = crtFile != null
? new FileInputStream(crtFile)
: new ByteArrayInputStream(clientCertificate.getBytes());
final X509Certificate clientCert;
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(crtFile))) {
try (BufferedInputStream bis = new BufferedInputStream(clientCertStream)) {
clientCert = (X509Certificate) certFactory.generateCertificate(bis);
}

Reader keyReader = keyFile != null
? new FileReader(keyFile)
: new StringReader(clientPrivateKey);
final PrivateKey privateKey;
try (PEMParser pemParser = new PEMParser(new FileReader(keyFile))) {
try (PEMParser pemParser = new PEMParser(keyReader)) {
Object pemObject = pemParser.readObject();
if (pemObject instanceof PEMEncryptedKeyPair keyPair) {
PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder().build(password);
Expand All @@ -114,7 +145,8 @@ public SSLSocketFactory getCertSocketFactory() throws Exception {
privateKey = converter.getPrivateKey(keyPair);
} else {
throw new RuntimeException(format("Unknown pem file type %s from %s",
pemObject.getClass().getSimpleName(), keyFile.getAbsolutePath()));
pemObject.getClass().getSimpleName(),
keyFile == null ? "" : keyFile.getAbsolutePath()));
}
}

Expand Down
30 changes: 15 additions & 15 deletions etc/validator.out
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ sites/udmi_site_model/out/devices/AHU-22/state.out
"sub_folder" : "update",
"sub_type" : "state",
"status" : {
"message" : "1 schema violations found",
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"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\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
},
"errors" : [ {
"message" : "1 schema violations found",
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"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\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down Expand Up @@ -382,15 +382,15 @@ sites/udmi_site_model/out/devices/AHU-22/state_system.out
"sub_folder" : "system",
"sub_type" : "state",
"status" : {
"message" : "1 schema violations found",
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
},
"errors" : [ {
"message" : "1 schema violations found",
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down Expand Up @@ -795,14 +795,14 @@ sites/udmi_site_model/out/devices/SNS-4/state.out
"sub_type" : "state",
"status" : {
"message" : "Multiple validation errors",
"detail" : "1 schema violations found; Device has missing points: split_threshold, triangulating_axis",
"detail" : "2 schema violations found; Device has missing points: split_threshold, triangulating_axis",
"category" : "validation.device.multiple",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
},
"errors" : [ {
"message" : "1 schema violations found",
"detail" : "state_update: 1 schema violations found; /system: object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"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\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down Expand Up @@ -850,15 +850,15 @@ sites/udmi_site_model/out/devices/SNS-4/state_system.out
"sub_folder" : "system",
"sub_type" : "state",
"status" : {
"message" : "1 schema violations found",
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
},
"errors" : [ {
"message" : "1 schema violations found",
"detail" : "state_system: 1 schema violations found; object has missing required properties ([\"serial_no\"])",
"message" : "2 schema violations found",
"detail" : "state_system: 2 schema violations found; object has missing required properties ([\"serial_no\",\"software\"]); /hardware: object has missing required properties ([\"make\",\"model\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down
17 changes: 0 additions & 17 deletions pubber/.idea/runConfigurations/Swarm.xml

This file was deleted.

24 changes: 24 additions & 0 deletions pubber/bin/publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -e

UDMI_ROOT=$(realpath $(dirname $0)/../..)
cd $UDMI_ROOT

DEFAULT_TASK="publish"
task=${1:-$DEFAULT_TASK}

# Validate the task
VALID_TASKS=("publish" "publishToMavenLocal")
if [[ ! " ${VALID_TASKS[@]} " =~ " $task " ]]; then
echo "Usage: $0 [publishTask]"
echo " publishTask: Task to execute. Default is '$DEFAULT_TASK'."
echo " Valid tasks are: ${VALID_TASKS[*]}"
echo
echo "Error: Invalid task '$task'"
exit 1
fi

source $UDMI_ROOT/etc/shell_common.sh

echo pubber/gradlew -p pubber $task
echo $UDMI_VERSION
$UDMI_ROOT/pubber/gradlew -p pubber $task
22 changes: 22 additions & 0 deletions pubber/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ plugins {
id 'java'
id 'jacoco'
id 'checkstyle'
id 'maven-publish'
}

group 'daq-pubber'
Expand Down Expand Up @@ -76,6 +77,27 @@ repositories {
maven { url 'https://jitpack.io' }
}

publishing {
repositories {
maven {
url = "https://maven.pkg.github.com/${System.getenv("GITHUB_REPOSITORY")}"
name = "GitHubPackages"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
mavenJava(MavenPublication) {
groupId = 'com.google.udmi'
artifactId = 'lib'
version = System.getenv("UDMI_VERSION")
from components.java
}
}
}

dependencies {
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
Expand Down
Loading

0 comments on commit a411ed5

Please sign in to comment.