Skip to content

Commit 7a99254

Browse files
authored
Convert license tools to use unified cli entrypoint (#85919)
The license tools exists separate from the normal cli tools since they are not part of the Elasticsearch distribution. However, they still utilize the Elasticsearch cli infrastructure. This commit adds a common cli base script that calls the cli launcher and converts each of the license tools to use it. relates #85758
1 parent a672936 commit 7a99254

File tree

12 files changed

+123
-122
lines changed

12 files changed

+123
-122
lines changed
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11
#!/bin/bash
22

3-
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4-
# or more contributor license agreements. Licensed under the Elastic License
5-
# 2.0; you may not use this file except in compliance with the Elastic License
6-
# 2.0.
7-
8-
CDPATH=""
9-
SCRIPT="$0"
10-
11-
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
12-
while [ -h "$SCRIPT" ] ; do
13-
ls=`ls -ld "$SCRIPT"`
14-
# Drop everything prior to ->
15-
link=`expr "$ls" : '.*-> \(.*\)$'`
16-
if expr "$link" : '/.*' > /dev/null; then
17-
SCRIPT="$link"
18-
else
19-
SCRIPT=`dirname "$SCRIPT"`/"$link"
20-
fi
21-
done
22-
23-
# determine license home
24-
LICENSE_HOME=`dirname "$SCRIPT"`/..
25-
26-
# make LICENSE_HOME absolute
27-
LICENSE_HOME=`cd "$LICENSE_HOME"; pwd`
28-
29-
# setup classpath
30-
LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/*
31-
32-
if [ -x "$JAVA_HOME/bin/java" ]; then
33-
JAVA=$JAVA_HOME/bin/java
34-
else
35-
JAVA=`which java`
36-
fi
37-
38-
exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.KeyPairGeneratorTool "$@"
39-
3+
source "`dirname "$0"`"/license-cli
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
# or more contributor license agreements. Licensed under the Elastic License
5+
# 2.0; you may not use this file except in compliance with the Elastic License
6+
# 2.0.
7+
8+
CDPATH=""
9+
SCRIPT="$0"
10+
11+
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
12+
while [ -h "$SCRIPT" ] ; do
13+
ls=`ls -ld "$SCRIPT"`
14+
# Drop everything prior to ->
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
SCRIPT="$link"
18+
else
19+
SCRIPT=`dirname "$SCRIPT"`/"$link"
20+
fi
21+
done
22+
23+
# determine license home
24+
LICENSE_HOME=`dirname "$SCRIPT"`/..
25+
# make LICENSE_HOME absolute
26+
LICENSE_HOME=`cd "$LICENSE_HOME"; pwd`
27+
28+
# setup classpath
29+
LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/*
30+
31+
if [ -x "$JAVA_HOME/bin/java" ]; then
32+
JAVA=$JAVA_HOME/bin/java
33+
else
34+
JAVA=`which java`
35+
fi
36+
37+
JAVA_OPTS="$JAVA_OPTS -Xmx64m -Xms16m"
38+
CLI_NAME=$(basename $0)
39+
40+
exec \
41+
"$JAVA" \
42+
$JAVA_OPTS \
43+
-Dcli.name="$CLI_NAME" \
44+
-Des.path.home="`pwd`" \
45+
-cp "$LICENSE_CLASSPATH" \
46+
org.elasticsearch.launcher.CliToolLauncher \
47+
"$@"
Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
11
#!/bin/bash
22

3-
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4-
# or more contributor license agreements. Licensed under the Elastic License
5-
# 2.0; you may not use this file except in compliance with the Elastic License
6-
# 2.0.
7-
8-
CDPATH=""
9-
SCRIPT="$0"
10-
11-
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
12-
while [ -h "$SCRIPT" ] ; do
13-
ls=`ls -ld "$SCRIPT"`
14-
# Drop everything prior to ->
15-
link=`expr "$ls" : '.*-> \(.*\)$'`
16-
if expr "$link" : '/.*' > /dev/null; then
17-
SCRIPT="$link"
18-
else
19-
SCRIPT=`dirname "$SCRIPT"`/"$link"
20-
fi
21-
done
22-
23-
# determine license home
24-
LICENSE_HOME=`dirname "$SCRIPT"`/..
25-
26-
# make LICENSE_HOME absolute
27-
LICENSE_HOME=`cd "$LICENSE_HOME"; pwd`
28-
29-
# setup classpath
30-
LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/*
31-
32-
if [ -x "$JAVA_HOME/bin/java" ]; then
33-
JAVA=$JAVA_HOME/bin/java
34-
else
35-
JAVA=`which java`
36-
fi
37-
38-
exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.LicenseGeneratorTool "$@"
3+
source "`dirname "$0"`"/license-cli
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11
#!/bin/bash
22

3-
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4-
# or more contributor license agreements. Licensed under the Elastic License
5-
# 2.0; you may not use this file except in compliance with the Elastic License
6-
# 2.0.
7-
8-
CDPATH=""
9-
SCRIPT="$0"
10-
11-
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
12-
while [ -h "$SCRIPT" ] ; do
13-
ls=`ls -ld "$SCRIPT"`
14-
# Drop everything prior to ->
15-
link=`expr "$ls" : '.*-> \(.*\)$'`
16-
if expr "$link" : '/.*' > /dev/null; then
17-
SCRIPT="$link"
18-
else
19-
SCRIPT=`dirname "$SCRIPT"`/"$link"
20-
fi
21-
done
22-
23-
# determine license home
24-
LICENSE_HOME=`dirname "$SCRIPT"`/..
25-
26-
# make LICENSE_HOME absolute
27-
LICENSE_HOME=`cd "$LICENSE_HOME"; pwd`
28-
29-
# setup classpath
30-
LICENSE_CLASSPATH=$LICENSE_CLASSPATH:$LICENSE_HOME/lib/*
31-
32-
if [ -x "$JAVA_HOME/bin/java" ]; then
33-
JAVA=$JAVA_HOME/bin/java
34-
else
35-
JAVA=`which java`
36-
fi
37-
38-
exec "$JAVA" $JAVA_OPTS -Xmx64m -Xms16m -cp "$LICENSE_CLASSPATH" -Des.path.home="`pwd`" org.elasticsearch.license.licensor.tools.LicenseVerificationTool "$@"
39-
3+
source "`dirname "$0"`"/license-cli

x-pack/license-tools/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'elasticsearch.build'
33
dependencies {
44
api project(':x-pack:plugin:core')
55
api project(':server')
6+
api project(':distribution:tools:cli-launcher')
67
testImplementation project(':test:framework')
78
}
89

x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/KeyPairGeneratorTool.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public KeyPairGeneratorTool() {
3636
this.privateKeyPathOption = parser.accepts("privateKeyPath", "private key path").withRequiredArg().required();
3737
}
3838

39-
public static void main(String[] args) throws Exception {
40-
exit(new KeyPairGeneratorTool().main(args, Terminal.DEFAULT));
41-
}
42-
4339
@Override
4440
protected void printAdditionalHelp(Terminal terminal) {
4541
terminal.println("This tool generates and saves a key pair to the provided publicKeyPath");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.license.licensor.tools;
9+
10+
import org.elasticsearch.cli.CliToolProvider;
11+
import org.elasticsearch.cli.Command;
12+
13+
public class KeyPairGeneratorToolProvider implements CliToolProvider {
14+
@Override
15+
public String name() {
16+
return "key-pair-generator";
17+
}
18+
19+
@Override
20+
public Command create() {
21+
return new KeyPairGeneratorTool();
22+
}
23+
}

x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public LicenseGeneratorTool() {
4545
licenseFileOption = parser.accepts("licenseFile", "license json spec file").withRequiredArg();
4646
}
4747

48-
public static void main(String[] args) throws Exception {
49-
exit(new LicenseGeneratorTool().main(args, Terminal.DEFAULT));
50-
}
51-
5248
@Override
5349
protected void printAdditionalHelp(Terminal terminal) {
5450
terminal.println("This tool generate elasticsearch license(s) for the provided");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.license.licensor.tools;
9+
10+
import org.elasticsearch.cli.CliToolProvider;
11+
import org.elasticsearch.cli.Command;
12+
13+
public class LicenseGeneratorToolProvider implements CliToolProvider {
14+
@Override
15+
public String name() {
16+
return "license-generator";
17+
}
18+
19+
@Override
20+
public Command create() {
21+
return new LicenseGeneratorTool();
22+
}
23+
}

x-pack/license-tools/src/main/java/org/elasticsearch/license/licensor/tools/LicenseVerificationTool.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ public LicenseVerificationTool() {
4444
licenseFileOption = parser.accepts("licenseFile", "license json spec file").withRequiredArg();
4545
}
4646

47-
public static void main(String[] args) throws Exception {
48-
exit(new LicenseVerificationTool().main(args, Terminal.DEFAULT));
49-
}
50-
5147
@Override
5248
protected void execute(Terminal terminal, OptionSet options) throws Exception {
5349
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));

0 commit comments

Comments
 (0)