Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B1B5A200C15 for ; Wed, 25 Jan 2017 00:03:25 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B0A6F160B5B; Tue, 24 Jan 2017 23:03:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D5A2B160B4B for ; Wed, 25 Jan 2017 00:03:24 +0100 (CET) Received: (qmail 61157 invoked by uid 500); 24 Jan 2017 23:03:24 -0000 Mailing-List: contact commits-help@sentry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sentry.apache.org Delivered-To: mailing list commits@sentry.apache.org Received: (qmail 60704 invoked by uid 99); 24 Jan 2017 23:03:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jan 2017 23:03:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 548F9F1719; Tue, 24 Jan 2017 23:03:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akolb@apache.org To: commits@sentry.apache.org Date: Tue, 24 Jan 2017 23:03:34 -0000 Message-Id: <1f5bac10247c4511a20275314a8de092@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [12/12] sentry git commit: Get host from environment or cmdline archived-at: Tue, 24 Jan 2017 23:03:25 -0000 Get host from environment or cmdline Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/250cf9fe Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/250cf9fe Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/250cf9fe Branch: refs/heads/akolb-ha-cli Commit: 250cf9fea775614069f4b542df4c76d943f96e7b Parents: f2ab8cb Author: Alexander Kolbasov Authored: Tue Dec 13 20:03:25 2016 -0800 Committer: Alexander Kolbasov Committed: Sun Jan 22 17:09:07 2017 -0800 ---------------------------------------------------------------------- .../java/org/apache/sentry/shell/SentryCli.java | 57 +++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/250cf9fe/sentry-tools/src/main/java/org/apache/sentry/shell/SentryCli.java ---------------------------------------------------------------------- diff --git a/sentry-tools/src/main/java/org/apache/sentry/shell/SentryCli.java b/sentry-tools/src/main/java/org/apache/sentry/shell/SentryCli.java index 61dcc04..180d240 100644 --- a/sentry-tools/src/main/java/org/apache/sentry/shell/SentryCli.java +++ b/sentry-tools/src/main/java/org/apache/sentry/shell/SentryCli.java @@ -34,6 +34,10 @@ import java.io.IOException; import java.util.Map; import java.util.Properties; +import static org.apache.sentry.service.thrift.ServiceConstants.ClientConfig.SERVER_RPC_ADDRESS; +import static org.apache.sentry.service.thrift.ServiceConstants.ServerConfig.SECURITY_MODE; +import static org.apache.sentry.service.thrift.ServiceConstants.ServerConfig.SECURITY_MODE_NONE; + /** * Sentry interactive tool */ @@ -44,8 +48,18 @@ public class SentryCli { private Options options = new Options(); private CommandLine cmd; + private static final String localhost = "localhost"; + private static final String defaultPort = "8038"; + + private static final String configOpt = "config"; private static final String userOpt = "user"; + private static final String hostOpt = "host"; + + private static final String configEnv = "SENTRY_CONFIG"; + private static final String hostEnv = "SENTRY_HOST"; + private static final String userEnv = "SENTRY_USER"; + private SentryPolicyServiceClient sentryClient; @@ -76,6 +90,7 @@ public class SentryCli { options.addOption("h", "help", false, "show help"); // file path of sentry-site options.addOption("U", userOpt, true, "auth user"); + options.addOption("H", hostOpt, true, "host address"); options.addOption("c", configOpt, true, "sentry configuration"); options.addOption("L", LOG4J_CONF, true, "Location of log4j properties file"); CommandLineParser parser = new GnuParser(); @@ -112,15 +127,6 @@ public class SentryCli { */ private void init() { Map env = System.getenv(); - String pathConf = cmd.getOptionValue(configOpt); - if (pathConf == null) { - pathConf = env.get("SENTRY_CONFIG"); - } - if (pathConf == null) { - System.out.println("Missing config file"); - System.exit(1); - } - String log4jconf = cmd.getOptionValue(LOG4J_CONF); if (log4jconf != null && log4jconf.length() > 0) { Properties log4jProperties = new Properties(); @@ -141,11 +147,38 @@ public class SentryCli { PropertyConfigurator.configure(log4jProperties); } + + String host = cmd.getOptionValue(hostOpt); + if (host == null) { + host = env.get(hostEnv); + } + + String pathConf = cmd.getOptionValue(configOpt); + if (pathConf == null) { + pathConf = env.get(configEnv); + } + if (host == null && pathConf == null) { + host = localhost + ":" + defaultPort; + } + Configuration conf = new Configuration(); - conf.addResource(new Path(pathConf)); - requestorName = cmd.getOptionValue(userOpt, ""); - if (requestorName.isEmpty()) { + if (pathConf != null) { + conf.addResource(new Path(pathConf)); + } else { + conf.set(SECURITY_MODE, SECURITY_MODE_NONE); + } + + if (host != null) { + conf.set(SERVER_RPC_ADDRESS, host); + } + + requestorName = cmd.getOptionValue(userOpt); + if (requestorName == null) { + requestorName = env.get(userEnv); + } + if (requestorName == null) { + UserGroupInformation ugi = null; try { ugi = UserGroupInformation.getLoginUser();