From 241eff7424777aba43decab7166fd8eef6fe72f8 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 22 May 2018 00:46:09 -0400 Subject: [PATCH 1/4] Reduce CLI scripts to one-liners on Windows This commit reduces the Windows CLI scripts to one-liners by moving all of the redundant logic to an elasticsearch-cli script. This commit is only the Windows side, a previous commit covered the Linux side. --- distribution/src/bin/elasticsearch-cli.bat | 22 +++++++++++++++++++ .../src/bin/elasticsearch-keystore.bat | 15 ++++--------- distribution/src/bin/elasticsearch-plugin.bat | 13 +++-------- .../src/bin/elasticsearch-translog.bat | 13 +++-------- .../src/main/bin/elasticsearch-certgen.bat | 16 ++++---------- .../src/main/bin/elasticsearch-certutil.bat | 18 +++++---------- .../src/main/bin/elasticsearch-migrate.bat | 16 ++++---------- .../main/bin/elasticsearch-saml-metadata.bat | 21 +++++++++++------- .../bin/elasticsearch-setup-passwords.bat | 16 ++++---------- .../src/main/bin/elasticsearch-syskeygen.bat | 16 ++++---------- .../src/main/bin/elasticsearch-users.bat | 16 ++++---------- .../src/main/bin/x-pack-security-env.bat | 2 -- .../src/main/bin/elasticsearch-croneval.bat | 16 ++++---------- .../src/main/bin/x-pack-watcher-env.bat | 2 -- 14 files changed, 74 insertions(+), 128 deletions(-) create mode 100644 distribution/src/bin/elasticsearch-cli.bat diff --git a/distribution/src/bin/elasticsearch-cli.bat b/distribution/src/bin/elasticsearch-cli.bat new file mode 100644 index 0000000000000..6bc32dd474145 --- /dev/null +++ b/distribution/src/bin/elasticsearch-cli.bat @@ -0,0 +1,22 @@ +call "%~dp0elasticsearch-env.bat" || exit /b 1 + +if defined ES_ADDITIONAL_SOURCES ( + for %%a in ("%ES_ADDITIONAL_SOURCES:;=","%") do ( + call %~dp0%%a + ) +) + +for /f "tokens=1*" %%a in ("%*") do ( + set main_class=%%a + set arguments=%%b +) + +%JAVA% ^ + %ES_JAVA_OPTS% ^ + -Des.path.home="%ES_HOME%" ^ + -Des.path.conf="%ES_PATH_CONF%" ^ + -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ + -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ + -cp "%ES_CLASSPATH%" ^ + %main_class% ^ + %arguments% diff --git a/distribution/src/bin/elasticsearch-keystore.bat b/distribution/src/bin/elasticsearch-keystore.bat index 1d6616983d8cc..9bd72a65745a9 100644 --- a/distribution/src/bin/elasticsearch-keystore.bat +++ b/distribution/src/bin/elasticsearch-keystore.bat @@ -3,17 +3,10 @@ setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ - org.elasticsearch.common.settings.KeyStoreCli ^ - %* +call "%~dp0elasticsearch-cli.bat" ^ + org.elasticsearch.common.settings.KeyStoreCli ^ + %* ^ + || exit /b 1 endlocal endlocal diff --git a/distribution/src/bin/elasticsearch-plugin.bat b/distribution/src/bin/elasticsearch-plugin.bat index b3b94a31863f1..d46ef295d085b 100644 --- a/distribution/src/bin/elasticsearch-plugin.bat +++ b/distribution/src/bin/elasticsearch-plugin.bat @@ -3,17 +3,10 @@ setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.plugins.PluginCli ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/distribution/src/bin/elasticsearch-translog.bat b/distribution/src/bin/elasticsearch-translog.bat index 492c1f0831263..37d96bbed6c4e 100644 --- a/distribution/src/bin/elasticsearch-translog.bat +++ b/distribution/src/bin/elasticsearch-translog.bat @@ -3,17 +3,10 @@ setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.index.translog.TranslogToolCli ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat index d44ca227c07fd..8c8a0c69f5626 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.core.ssl.CertificateGenerateTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat index 4426fb87d3ba6..c25f37f4d9051 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ - org.elasticsearch.xpack.core.ssl.CertificateTool ^ - %* +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ + org.elasticsearch.xpack.core.ssl.CertificateTool ^ + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat index 79090b6490790..f9486979e6bc3 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat index 9e5625d0b912e..c838185fa9d2b 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat @@ -11,15 +11,20 @@ call "%~dp0elasticsearch-env.bat" || exit /b 1 call "%~dp0x-pack-security-env.bat" || exit /b 1 -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +@echo off + +rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +rem or more contributor license agreements. Licensed under the Elastic License; +rem you may not use this file except in compliance with the Elastic License. + +setlocal enabledelayedexpansion +setlocal enableextensions + +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.authc.saml.SamlMetadataCommand ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat index b449ca09a6c30..f380e5f55271f 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat index 3ee9dcb3ba9cb..1eff4aad8251e 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.crypto.tool.SystemKeyTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat index b32b9398f9971..7f7347d706ff5 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.authc.file.tool.UsersTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/security/src/main/bin/x-pack-security-env.bat b/x-pack/plugin/security/src/main/bin/x-pack-security-env.bat index 035f1c965ffb6..d003412fc08d9 100644 --- a/x-pack/plugin/security/src/main/bin/x-pack-security-env.bat +++ b/x-pack/plugin/security/src/main/bin/x-pack-security-env.bat @@ -2,6 +2,4 @@ rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one rem or more contributor license agreements. Licensed under the Elastic License; rem you may not use this file except in compliance with the Elastic License. -call "%~dp0x-pack-env.bat" || exit /b 1 - set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/modules/x-pack-security/* diff --git a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat index 7fd983c9ba5fe..37ca14dd094cc 100644 --- a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat +++ b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-watcher-env.bat" || exit /b 1 - -%JAVA% ^ - %ES_JAVA_OPTS% ^ - -Des.path.home="%ES_HOME%" ^ - -Des.path.conf="%ES_PATH_CONF%" ^ - -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^ - -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^ - -cp "%ES_CLASSPATH%" ^ +set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-watcher-env +call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.watcher.trigger.schedule.tool.CronEvalTool ^ - %* + %* ^ + || exit /b 1 endlocal endlocal diff --git a/x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env.bat b/x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env.bat index 010c154eb5a39..4c7f762dca26c 100644 --- a/x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env.bat +++ b/x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env.bat @@ -2,6 +2,4 @@ rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one rem or more contributor license agreements. Licensed under the Elastic License; rem you may not use this file except in compliance with the Elastic License. -call "%~dp0x-pack-env.bat" || exit /b 1 - set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/modules/x-pack-watcher/* From 09efe6f1ee528cdcd61811ffa3fe0ec2827399a6 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 22 May 2018 00:50:25 -0400 Subject: [PATCH 2/4] Fix indentation --- distribution/src/bin/elasticsearch-cli.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/src/bin/elasticsearch-cli.bat b/distribution/src/bin/elasticsearch-cli.bat index 6bc32dd474145..efda5f653ef31 100644 --- a/distribution/src/bin/elasticsearch-cli.bat +++ b/distribution/src/bin/elasticsearch-cli.bat @@ -7,8 +7,8 @@ if defined ES_ADDITIONAL_SOURCES ( ) for /f "tokens=1*" %%a in ("%*") do ( - set main_class=%%a - set arguments=%%b + set main_class=%%a + set arguments=%%b ) %JAVA% ^ From 74dcd98ff3a0b76bb1af24aaf38f0e26b5bba8c7 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 22 May 2018 00:51:06 -0400 Subject: [PATCH 3/4] Fix indentation again --- x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat index c25f37f4d9051..f898f885ce0a3 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat @@ -9,7 +9,7 @@ setlocal enableextensions set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ - org.elasticsearch.xpack.core.ssl.CertificateTool ^ + org.elasticsearch.xpack.core.ssl.CertificateTool ^ %* ^ || exit /b 1 From b9d9fa68e9bcf75cea8a24c0ff047d6d11af82ce Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 22 May 2018 00:54:42 -0400 Subject: [PATCH 4/4] Fix saml-metadata script --- .../src/main/bin/elasticsearch-saml-metadata.bat | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat index c838185fa9d2b..4ddb8da3ff143 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat @@ -7,19 +7,6 @@ rem you may not use this file except in compliance with the Elastic License. setlocal enabledelayedexpansion setlocal enableextensions -call "%~dp0elasticsearch-env.bat" || exit /b 1 - -call "%~dp0x-pack-security-env.bat" || exit /b 1 - -@echo off - -rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -rem or more contributor license agreements. Licensed under the Elastic License; -rem you may not use this file except in compliance with the Elastic License. - -setlocal enabledelayedexpansion -setlocal enableextensions - set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.security.authc.saml.SamlMetadataCommand ^