From 45c9a53222367d58a1e98e0aefa24b1c3ab60fdc Mon Sep 17 00:00:00 2001 From: Greg Schueler Date: Thu, 2 Feb 2017 09:46:56 -0800 Subject: [PATCH] Fix #66 don't prompt when token or user+pass set --- .../java/org/rundeck/client/tool/Main.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/rundeck/client/tool/Main.java b/src/main/java/org/rundeck/client/tool/Main.java index d925ff3a..1559feda 100644 --- a/src/main/java/org/rundeck/client/tool/Main.java +++ b/src/main/java/org/rundeck/client/tool/Main.java @@ -175,17 +175,13 @@ private static void setupColor(final ToolBelt belt, AppConfig config) { public static Client createClient(AppConfig config) throws InputError { Auth auth = new Auth() { }; - String baseUrl = null; auth = auth.chain(new ConfigAuth(config)); + String baseUrl = config.require( + ENV_URL, + "Please specify the Rundeck base URL, e.g. http://host:port or http://host:port/api/14" + ); - if (null == baseUrl) { - baseUrl = config.require( - ENV_URL, - "Please specify the Rundeck base URL, e.g. http://host:port or http://host:port/api/14" - ); - } - - if (config.getBool(ENV_AUTH_PROMPT, true) && null != System.console()) { + if (!auth.isConfigured() && config.getBool(ENV_AUTH_PROMPT, true) && null != System.console()) { auth = auth.chain(new ConsoleAuth(String.format("Credentials for URL: %s", baseUrl)).memoize()); } @@ -217,6 +213,12 @@ public static Client createClient(AppConfig config) throws InputErro } static interface Auth { + default boolean isConfigured() { + return null != getToken() || ( + null != getUsername() && null != getPassword() + ); + } + default String getUsername() { return null; }