Skip to content

Commit

Permalink
zbctl java implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
upgradingdave committed Apr 30, 2024
1 parent 4a402a6 commit b634977
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zbctl-java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[![Community Extension](https://img.shields.io/badge/Community%20Extension-An%20open%20source%20community%20maintained%20project-FF4700)](https://github.com/camunda-community-hub/community)
![Compatible with: Camunda Platform 8](https://img.shields.io/badge/Compatible%20with-Camunda%20Platform%208-0072Ce)
[![](https://img.shields.io/badge/Lifecycle-Incubating-blue)](https://github.com/Camunda-Community-Hub/community/blob/main/extension-lifecycle.md#incubating-)

# A Java Zeebe Client

A very simple command line tool written in java for testing connections to zeebe


51 changes: 51 additions & 0 deletions zbctl-java/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.camunda</groupId>
<artifactId>zbctl-java</artifactId>
<name>Java Zeebe Client</name>
<version>1.0.0-SNAPSHOT</version>
<description>A Java Zeebe Client that can be run from the command line</description>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer>
<mainClass>io.camunda.zbctl.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<java.version>17</java.version>
<zeebe.version>8.4.2</zeebe.version>
</properties>
</project>
83 changes: 83 additions & 0 deletions zbctl-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Java Zeebe Client</name>
<description>A Java Zeebe Client that can be run from the command line</description>
<groupId>io.camunda</groupId>
<artifactId>zbctl-java</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<java.version>17</java.version>
<zeebe.version>8.4.2</zeebe.version>
</properties>

<dependencies>

<dependency>
<groupId>io.camunda</groupId>
<artifactId>zeebe-client-java</artifactId>
<version>${zeebe.version}</version>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.7.0</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.camunda.zbctl.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Google code format plugin -->
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
129 changes: 129 additions & 0 deletions zbctl-java/src/main/java/io/camunda/zbctl/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package io.camunda.zbctl;

import io.camunda.zeebe.client.CredentialsProvider;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.ZeebeClientBuilder;
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder;
import org.apache.commons.cli.*;

public class Main {

public static void main(String[] args) {

Option gatewayAddressOption =
Option.builder()
.longOpt("address")
.desc("Specify a contact point address.")
.hasArg()
.build();

Option audienceOption =
Option.builder()
.longOpt("audience")
.desc("Specify the resource that the access token should be valid for.")
.hasArg()
.build();

Option scopeOption =
Option.builder().longOpt("scope").desc("Specify Zeebe Token Scope").hasArg().build();

Option authzUrlOption =
Option.builder()
.longOpt("authzUrl")
.desc("Specify an authorization server URL from which to request an access token.")
.hasArg()
.build();

Option certPathOption =
Option.builder()
.longOpt("certPath")
.desc("Specify a path to a certificate with which to validate gateway requests.")
.hasArg()
.build();

Option clientIdOption =
Option.builder()
.longOpt("clientId")
.desc("Specify a client identifier to request an access token.")
.hasArg()
.build();

Option clientSecretOption =
Option.builder()
.longOpt("clientSecret")
.desc("Specify a client secret to request an access token.")
.hasArg()
.build();

Option helpOption = Option.builder().longOpt("help").desc("display this help message").build();

Options options = new Options();
options.addOption(gatewayAddressOption);
options.addOption(audienceOption);
options.addOption(scopeOption);
options.addOption(authzUrlOption);
options.addOption(certPathOption);
options.addOption(clientIdOption);
options.addOption(clientSecretOption);
options.addOption(helpOption);

CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("zbctl", options);
} else {

String address = "http://localhost:26500";
if (cmd.hasOption("address")) {
address = cmd.getOptionValue("address");
}

String audience = "zeebe-api";
if (cmd.hasOption("audience")) {
audience = cmd.getOptionValue("audience");
}

String scope = "camunda-identity";
if (cmd.hasOption("scope")) {
scope = cmd.getOptionValue("scope");
}

String authzUrl =
"http://locahost:18080/auth/realms/camunda-platform/protocol/openid-connect/token";
if (cmd.hasOption("authzUrl")) {
authzUrl = cmd.getOptionValue("authzUrl");
}

String clientId = cmd.getOptionValue("clientId");
String clientSecret = cmd.getOptionValue("clientSecret");

CredentialsProvider credentialsProvider =
new OAuthCredentialsProviderBuilder()
.authorizationServerUrl(authzUrl)
.audience(clientId)
.scope(scope)
.clientId(clientId)
.clientSecret(clientSecret)
.build();

ZeebeClientBuilder zeebeClientBuilder =
io.camunda.zeebe.client.ZeebeClient.newClientBuilder()
.gatewayAddress(address)
.credentialsProvider(credentialsProvider);

if (cmd.hasOption("certPath")) {
String certPath = cmd.getOptionValue("certPath");
zeebeClientBuilder.caCertificatePath(certPath);
}

ZeebeClient zeebeClient = zeebeClientBuilder.build();
System.out.println(zeebeClient.newTopologyRequest().send().join().toString());
}

} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
Empty file.

0 comments on commit b634977

Please sign in to comment.