Merge branch 'dev' into es_integration

Original commit: elastic/x-pack-elasticsearch@46b230d58e
This commit is contained in:
Areek Zillur 2014-10-16 15:50:16 -04:00
commit 5fc3e264f0
2 changed files with 23 additions and 35 deletions

View File

@ -1,14 +1 @@
{ {"licenses":[{"type":"internal","subscription_type":"none","issued_to":"issuedTo","issuer":"issuer","issue_date":"2014-09-29","expiry_date":"2015-08-29","feature":"shield","max_nodes":1}]}
"licenses": [
{
"type": "internal",
"subscription_type": "none",
"issued_to": "issuedTo",
"issuer": "issuer",
"issue_date": "2014-09-29",
"expiry_date": "2015-08-29",
"feature": "shield",
"max_nodes": 1
}
]
}

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.license.licensor.tools; package org.elasticsearch.license.licensor.tools;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.license.core.ESLicenses; import org.elasticsearch.license.core.ESLicenses;
import org.elasticsearch.license.core.LicenseUtils; import org.elasticsearch.license.core.LicenseUtils;
import org.elasticsearch.license.licensor.ESLicenseSigner; import org.elasticsearch.license.licensor.ESLicenseSigner;
@ -13,25 +12,23 @@ import org.elasticsearch.license.licensor.ESLicenseSigner;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset;
public class LicenseGeneratorTool { public class LicenseGeneratorTool {
static class Options { static class Options {
private final String licensesInput; private final ESLicenses licenses;
private final String publicKeyFilePath; private final String publicKeyFilePath;
private final String privateKeyFilePath; private final String privateKeyFilePath;
Options(String licensesInput, String publicKeyFilePath, String privateKeyFilePath) { Options(ESLicenses licenses, String publicKeyFilePath, String privateKeyFilePath) {
this.licensesInput = licensesInput; this.licenses = licenses;
this.publicKeyFilePath = publicKeyFilePath; this.publicKeyFilePath = publicKeyFilePath;
this.privateKeyFilePath = privateKeyFilePath; this.privateKeyFilePath = privateKeyFilePath;
} }
} }
private static Options parse(String[] args) throws IOException { private static Options parse(String[] args) throws IOException {
String licenseInput = null; ESLicenses licenses = null;
String licenseFilePath = null;
String privateKeyPath = null; String privateKeyPath = null;
String publicKeyPath = null; String publicKeyPath = null;
@ -39,10 +36,22 @@ public class LicenseGeneratorTool {
String command = args[i].trim(); String command = args[i].trim();
switch (command) { switch (command) {
case "--license": case "--license":
licenseInput = args[++i]; if (licenses != null) {
throw new IllegalArgumentException("only one of --licenses' or '--licenseFile' can be specified");
}
String licenseInput = args[++i];
licenses = LicenseUtils.readLicensesFromString(licenseInput);
break; break;
case "--licenseFile": case "--licenseFile":
licenseFilePath = args[++i]; if (licenses != null) {
throw new IllegalArgumentException("only one of --licenses' or '--licenseFile' can be specified");
}
File licenseFile = new File(args[++i]);
if (licenseFile.exists()) {
licenses = LicenseUtils.readLicenseFile(licenseFile);
} else {
throw new IllegalArgumentException(licenseFile.getAbsolutePath() + " does not exist!");
}
break; break;
case "--publicKeyPath": case "--publicKeyPath":
publicKeyPath = args[++i]; publicKeyPath = args[++i];
@ -53,15 +62,8 @@ public class LicenseGeneratorTool {
} }
} }
if ((licenseInput == null && licenseFilePath == null) || (licenseInput != null && licenseFilePath != null)) { if (licenses == null) {
throw new IllegalArgumentException("only one of '--license' or '--licenseFile' option should be set"); throw new IllegalArgumentException("at least one of '--licenses' or '--licenseFile' has to be provided");
} else if (licenseFilePath != null) {
File licenseFile = new File(licenseFilePath);
if (licenseFile.exists()) {
licenseInput = FileUtils.readFileToString(licenseFile, Charset.forName("UTF-8"));
} else {
throw new IllegalArgumentException("provided --licenseFile " + licenseFile.getAbsolutePath() + " does not exist!");
}
} }
if (publicKeyPath == null) { if (publicKeyPath == null) {
throw new IllegalArgumentException("mandatory option '--publicKeyPath' is missing"); throw new IllegalArgumentException("mandatory option '--publicKeyPath' is missing");
@ -70,7 +72,7 @@ public class LicenseGeneratorTool {
throw new IllegalArgumentException("mandatory option '--privateKeyPath' is missing"); throw new IllegalArgumentException("mandatory option '--privateKeyPath' is missing");
} }
return new Options(licenseInput, publicKeyPath, privateKeyPath); return new Options(licenses, publicKeyPath, privateKeyPath);
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
@ -80,10 +82,9 @@ public class LicenseGeneratorTool {
public static void run(String[] args, OutputStream out) throws IOException { public static void run(String[] args, OutputStream out) throws IOException {
Options options = parse(args); Options options = parse(args);
ESLicenses esLicenses = LicenseUtils.readLicensesFromString(options.licensesInput);
ESLicenseSigner signer = new ESLicenseSigner(options.privateKeyFilePath, options.publicKeyFilePath); ESLicenseSigner signer = new ESLicenseSigner(options.privateKeyFilePath, options.publicKeyFilePath);
ESLicenses signedLicences = signer.sign(esLicenses); ESLicenses signedLicences = signer.sign(options.licenses);
LicenseUtils.dumpLicenseAsJson(signedLicences, out); LicenseUtils.dumpLicenseAsJson(signedLicences, out);
} }