From b6349776cc3efa7fa6b1bee5b4c783a3f7df5bf3 Mon Sep 17 00:00:00 2001 From: Dave Paroulek Date: Tue, 30 Apr 2024 13:51:29 -0400 Subject: [PATCH] zbctl java implementation --- zbctl-java/README.md | 9 ++ zbctl-java/dependency-reduced-pom.xml | 51 +++++++ zbctl-java/pom.xml | 83 +++++++++++ .../src/main/java/io/camunda/zbctl/Main.java | 129 ++++++++++++++++++ .../src/main/resources/application.yaml | 0 5 files changed, 272 insertions(+) create mode 100644 zbctl-java/README.md create mode 100644 zbctl-java/dependency-reduced-pom.xml create mode 100644 zbctl-java/pom.xml create mode 100644 zbctl-java/src/main/java/io/camunda/zbctl/Main.java create mode 100644 zbctl-java/src/main/resources/application.yaml diff --git a/zbctl-java/README.md b/zbctl-java/README.md new file mode 100644 index 0000000..b46b67a --- /dev/null +++ b/zbctl-java/README.md @@ -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 + + diff --git a/zbctl-java/dependency-reduced-pom.xml b/zbctl-java/dependency-reduced-pom.xml new file mode 100644 index 0000000..d31b3f2 --- /dev/null +++ b/zbctl-java/dependency-reduced-pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + io.camunda + zbctl-java + Java Zeebe Client + 1.0.0-SNAPSHOT + A Java Zeebe Client that can be run from the command line + + + + maven-shade-plugin + + + + shade + + + true + + + io.camunda.zbctl.Main + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.spotify.fmt + fmt-maven-plugin + 2.21.1 + + + + format + + + + + + + + 17 + 8.4.2 + + diff --git a/zbctl-java/pom.xml b/zbctl-java/pom.xml new file mode 100644 index 0000000..1c8208c --- /dev/null +++ b/zbctl-java/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + Java Zeebe Client + A Java Zeebe Client that can be run from the command line + io.camunda + zbctl-java + 1.0.0-SNAPSHOT + + + 17 + 8.4.2 + + + + + + io.camunda + zeebe-client-java + ${zeebe.version} + + + + commons-cli + commons-cli + 1.7.0 + + + + org.slf4j + slf4j-simple + 2.0.13 + runtime + + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + + true + + + io.camunda.zbctl.Main + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.spotify.fmt + fmt-maven-plugin + 2.21.1 + + + + format + + + + + + + + diff --git a/zbctl-java/src/main/java/io/camunda/zbctl/Main.java b/zbctl-java/src/main/java/io/camunda/zbctl/Main.java new file mode 100644 index 0000000..056abb4 --- /dev/null +++ b/zbctl-java/src/main/java/io/camunda/zbctl/Main.java @@ -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); + } + } +} diff --git a/zbctl-java/src/main/resources/application.yaml b/zbctl-java/src/main/resources/application.yaml new file mode 100644 index 0000000..e69de29