You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by ak...@apache.org on 2017/01/24 23:03:34 UTC
[12/12] sentry git commit: Get host from environment or cmdline
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 <ak...@cloudera.com>
Authored: Tue Dec 13 20:03:25 2016 -0800
Committer: Alexander Kolbasov <ak...@cloudera.com>
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<String, String> 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();