From 68eb791965b289606786a4ff891a249521587e33 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 7 Oct 2014 13:54:55 -0400 Subject: [PATCH 1/2] added setup section to README Original commit: elastic/x-pack-elasticsearch@dbf593ef16ff1737a1b79ded54128d45ff204f93 --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f3ac2dadeda..b1ce505a100 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,29 @@ Internal Elasticsearch Licensing Plugin ## Command Line tools (Interface with Internal License Server) -**Note:** Initially run `mvn clean compile package` to use the scripts +### Setup +```bash +# clone elasticsearch if not already cloned; go to elasticsearch project directory +git clone git@github.com:elasticsearch/elasticsearch.git +cd elasticsearch + +# checkout 1.4 branch +git checkout 1.4 + +# install elasticsearch 1.4 +mvn clean install -DskipTests=true + +# clone elasticsearch-license; go to elasticsearch-license project directory +git clone git@github.com:elasticsearch/elasticsearch-license.git +cd elasticsearch-license + +# TEMPORARY (switch to dev branch) +git checkout dev + +# build +mvn clean package + +``` ### bin/key-pair-generator From 68b5d71f37f4217f0362235fee18cc1973de9d6a Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Thu, 16 Oct 2014 15:46:57 -0400 Subject: [PATCH 2/2] minor: better CLT handling Original commit: elastic/x-pack-elasticsearch@62a37bbbf117f12fa99cd36cbd2aa218293c6da0 --- sample/license_spec.json | 15 +------ .../licensor/tools/LicenseGeneratorTool.java | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/sample/license_spec.json b/sample/license_spec.json index 92997a9f242..a4aef47283f 100644 --- a/sample/license_spec.json +++ b/sample/license_spec.json @@ -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}]} diff --git a/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java b/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java index 4c49c00e4dc..92857cacc63 100644 --- a/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java +++ b/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license.licensor.tools; -import org.apache.commons.io.FileUtils; import org.elasticsearch.license.core.ESLicenses; import org.elasticsearch.license.core.LicenseUtils; import org.elasticsearch.license.licensor.ESLicenseSigner; @@ -13,25 +12,23 @@ import org.elasticsearch.license.licensor.ESLicenseSigner; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.nio.charset.Charset; public class LicenseGeneratorTool { static class Options { - private final String licensesInput; + private final ESLicenses licenses; private final String publicKeyFilePath; private final String privateKeyFilePath; - Options(String licensesInput, String publicKeyFilePath, String privateKeyFilePath) { - this.licensesInput = licensesInput; + Options(ESLicenses licenses, String publicKeyFilePath, String privateKeyFilePath) { + this.licenses = licenses; this.publicKeyFilePath = publicKeyFilePath; this.privateKeyFilePath = privateKeyFilePath; } } private static Options parse(String[] args) throws IOException { - String licenseInput = null; - String licenseFilePath = null; + ESLicenses licenses = null; String privateKeyPath = null; String publicKeyPath = null; @@ -39,10 +36,22 @@ public class LicenseGeneratorTool { String command = args[i].trim(); switch (command) { 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; 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; case "--publicKeyPath": publicKeyPath = args[++i]; @@ -53,15 +62,8 @@ public class LicenseGeneratorTool { } } - if ((licenseInput == null && licenseFilePath == null) || (licenseInput != null && licenseFilePath != null)) { - throw new IllegalArgumentException("only one of '--license' or '--licenseFile' option should be set"); - } 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 (licenses == null) { + throw new IllegalArgumentException("at least one of '--licenses' or '--licenseFile' has to be provided"); } if (publicKeyPath == null) { throw new IllegalArgumentException("mandatory option '--publicKeyPath' is missing"); @@ -70,7 +72,7 @@ public class LicenseGeneratorTool { 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 { @@ -80,10 +82,9 @@ public class LicenseGeneratorTool { public static void run(String[] args, OutputStream out) throws IOException { Options options = parse(args); - ESLicenses esLicenses = LicenseUtils.readLicensesFromString(options.licensesInput); ESLicenseSigner signer = new ESLicenseSigner(options.privateKeyFilePath, options.publicKeyFilePath); - ESLicenses signedLicences = signer.sign(esLicenses); + ESLicenses signedLicences = signer.sign(options.licenses); LicenseUtils.dumpLicenseAsJson(signedLicences, out); }