diff --git a/x-pack/license-tools/bin/key-pair-generator b/x-pack/license-tools/bin/key-pair-generator index 07df91c63822f..94a76a5576162 100755 --- a/x-pack/license-tools/bin/key-pair-generator +++ b/x-pack/license-tools/bin/key-pair-generator @@ -1,39 +1,3 @@ #!/bin/bash -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License -# 2.0; you may not use this file except in compliance with the Elastic License -# 2.0. - -CDPATH="" -SCRIPT="$0" - -# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - # Drop everything prior to -> - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -# determine license home -LICENSE_HOME=`dirname "$SCRIPT"`/.. - -# make LICENSE_HOME absolute -LICENSE_HOME=`cd "$LICENSE_HOME"; pwd` - -# setup classpath -LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/* - -if [ -x "$JAVA_HOME/bin/java" ]; then - JAVA=$JAVA_HOME/bin/java -else - JAVA=`which java` -fi - -exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.KeyPairGeneratorTool "$@" - +source "`dirname "$0"`"/license-cli diff --git a/x-pack/license-tools/bin/license-cli b/x-pack/license-tools/bin/license-cli new file mode 100644 index 0000000000000..b591172693c7f --- /dev/null +++ b/x-pack/license-tools/bin/license-cli @@ -0,0 +1,47 @@ +#!/bin/bash + +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License +# 2.0; you may not use this file except in compliance with the Elastic License +# 2.0. + +CDPATH="" +SCRIPT="$0" + +# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + # Drop everything prior to -> + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +# determine license home +LICENSE_HOME=`dirname "$SCRIPT"`/.. +# make LICENSE_HOME absolute +LICENSE_HOME=`cd "$LICENSE_HOME"; pwd` + +# setup classpath +LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/* + +if [ -x "$JAVA_HOME/bin/java" ]; then + JAVA=$JAVA_HOME/bin/java +else + JAVA=`which java` +fi + +JAVA_OPTS="$JAVA_OPTS -Xmx64m -Xms16m" +CLI_NAME=$(basename $0) + +exec \ + "$JAVA" \ + $JAVA_OPTS \ + -Dcli.name="$CLI_NAME" \ + -Des.path.home="`pwd`" \ + -cp "$LICENSE_CLASSPATH" \ + org.elasticsearch.launcher.CliToolLauncher \ + "$@" diff --git a/x-pack/license-tools/bin/license-generator b/x-pack/license-tools/bin/license-generator index 4c73e34a6d3ee..94a76a5576162 100755 --- a/x-pack/license-tools/bin/license-generator +++ b/x-pack/license-tools/bin/license-generator @@ -1,38 +1,3 @@ #!/bin/bash -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License -# 2.0; you may not use this file except in compliance with the Elastic License -# 2.0. - -CDPATH="" -SCRIPT="$0" - -# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - # Drop everything prior to -> - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -# determine license home -LICENSE_HOME=`dirname "$SCRIPT"`/.. - -# make LICENSE_HOME absolute -LICENSE_HOME=`cd "$LICENSE_HOME"; pwd` - -# setup classpath -LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/* - -if [ -x "$JAVA_HOME/bin/java" ]; then - JAVA=$JAVA_HOME/bin/java -else - JAVA=`which java` -fi - -exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.LicenseGeneratorTool "$@" +source "`dirname "$0"`"/license-cli diff --git a/x-pack/license-tools/bin/verify-license b/x-pack/license-tools/bin/verify-license index ee28e619ef82e..94a76a5576162 100755 --- a/x-pack/license-tools/bin/verify-license +++ b/x-pack/license-tools/bin/verify-license @@ -1,39 +1,3 @@ #!/bin/bash -# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -# or more contributor license agreements. Licensed under the Elastic License -# 2.0; you may not use this file except in compliance with the Elastic License -# 2.0. - -CDPATH="" -SCRIPT="$0" - -# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - # Drop everything prior to -> - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -# determine license home -LICENSE_HOME=`dirname "$SCRIPT"`/.. - -# make LICENSE_HOME absolute -LICENSE_HOME=`cd "$LICENSE_HOME"; pwd` - -# setup classpath -LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/* - -if [ -x "$JAVA_HOME/bin/java" ]; then - JAVA=$JAVA_HOME/bin/java -else - JAVA=`which java` -fi - -exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.LicenseVerificationTool "$@" - +source "`dirname "$0"`"/license-cli diff --git a/x-pack/license-tools/build.gradle b/x-pack/license-tools/build.gradle index fc9c4b517b94f..1e4ff45ac9c76 100644 --- a/x-pack/license-tools/build.gradle +++ b/x-pack/license-tools/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'elasticsearch.build' dependencies { api project(':x-pack:plugin:core') api project(':server') + api project(':distribution:tools:cli-launcher') testImplementation project(':test:framework') } diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorTool.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorTool.java index 6cfb3184e73be..9e20324355e3e 100644 --- a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorTool.java +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorTool.java @@ -36,10 +36,6 @@ public KeyPairGeneratorTool() { this.privateKeyPathOption = parser.accepts("privateKeyPath", "private key path").withRequiredArg().required(); } - public static void main(String[] args) throws Exception { - exit(new KeyPairGeneratorTool().main(args, Terminal.DEFAULT)); - } - @Override protected void printAdditionalHelp(Terminal terminal) { terminal.println("This tool generates and saves a key pair to the provided publicKeyPath"); diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorToolProvider.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorToolProvider.java new file mode 100644 index 0000000000000..d809c5cb6c8a7 --- /dev/null +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorToolProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.license.licensor.tools; + +import org.elasticsearch.cli.CliToolProvider; +import org.elasticsearch.cli.Command; + +public class KeyPairGeneratorToolProvider implements CliToolProvider { + @Override + public String name() { + return "key-pair-generator"; + } + + @Override + public Command create() { + return new KeyPairGeneratorTool(); + } +} diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java index 4dc1b17b2f9f6..d8a50be7600db 100644 --- a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java @@ -45,10 +45,6 @@ public LicenseGeneratorTool() { licenseFileOption = parser.accepts("licenseFile", "license json spec file").withRequiredArg(); } - public static void main(String[] args) throws Exception { - exit(new LicenseGeneratorTool().main(args, Terminal.DEFAULT)); - } - @Override protected void printAdditionalHelp(Terminal terminal) { terminal.println("This tool generate elasticsearch license(s) for the provided"); diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorToolProvider.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorToolProvider.java new file mode 100644 index 0000000000000..d0b2fac54d55b --- /dev/null +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorToolProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.license.licensor.tools; + +import org.elasticsearch.cli.CliToolProvider; +import org.elasticsearch.cli.Command; + +public class LicenseGeneratorToolProvider implements CliToolProvider { + @Override + public String name() { + return "license-generator"; + } + + @Override + public Command create() { + return new LicenseGeneratorTool(); + } +} diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationTool.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationTool.java index 1059b100fc396..f9b7f1bef3b52 100644 --- a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationTool.java +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationTool.java @@ -44,10 +44,6 @@ public LicenseVerificationTool() { licenseFileOption = parser.accepts("licenseFile", "license json spec file").withRequiredArg(); } - public static void main(String[] args) throws Exception { - exit(new LicenseVerificationTool().main(args, Terminal.DEFAULT)); - } - @Override protected void execute(Terminal terminal, OptionSet options) throws Exception { Path publicKeyPath = parsePath(publicKeyPathOption.value(options)); diff --git a/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationToolProvider.java b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationToolProvider.java new file mode 100644 index 0000000000000..d13733058c131 --- /dev/null +++ b/x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationToolProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.license.licensor.tools; + +import org.elasticsearch.cli.CliToolProvider; +import org.elasticsearch.cli.Command; + +public class LicenseVerificationToolProvider implements CliToolProvider { + @Override + public String name() { + return "verify-license"; + } + + @Override + public Command create() { + return new LicenseVerificationTool(); + } +} diff --git a/x-pack/license-tools/src/main/resources/META-INF/services/org.elasticsearch.cli.CliToolProvider b/x-pack/license-tools/src/main/resources/META-INF/services/org.elasticsearch.cli.CliToolProvider new file mode 100644 index 0000000000000..886dae2d4dd6a --- /dev/null +++ b/x-pack/license-tools/src/main/resources/META-INF/services/org.elasticsearch.cli.CliToolProvider @@ -0,0 +1,3 @@ +org.elasticsearch.license.licensor.tools.LicenseGeneratorToolProvider +org.elasticsearch.license.licensor.tools.LicenseVerificationToolProvider +org.elasticsearch.license.licensor.tools.KeyPairGeneratorToolProvider