Some minor refactoring
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/d9dbe56c Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/d9dbe56c Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/d9dbe56c Branch: refs/heads/master Commit: d9dbe56ca257f89652ffa430bfc4c594f35e3557 Parents: 6000ca9 Author: Colm O hEigeartaigh <[email protected]> Authored: Thu Oct 19 11:43:48 2017 +0100 Committer: Colm O hEigeartaigh <[email protected]> Committed: Thu Oct 19 11:43:48 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/sentry/shell/GroupShell.java | 16 ++++++++-------- .../java/org/apache/sentry/shell/PrivsShell.java | 8 ++++---- .../java/org/apache/sentry/shell/RolesShell.java | 15 +++++++-------- .../java/org/apache/sentry/shell/SentryCli.java | 1 - .../java/org/apache/sentry/shell/ShellUtil.java | 17 ++++++++--------- 5 files changed, 27 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/d9dbe56c/sentry-tools/src/main/java/org/apache/sentry/shell/GroupShell.java ---------------------------------------------------------------------- diff --git a/sentry-tools/src/main/java/org/apache/sentry/shell/GroupShell.java b/sentry-tools/src/main/java/org/apache/sentry/shell/GroupShell.java index 3fc7a31..7510114 100644 --- a/sentry-tools/src/main/java/org/apache/sentry/shell/GroupShell.java +++ b/sentry-tools/src/main/java/org/apache/sentry/shell/GroupShell.java @@ -29,6 +29,14 @@ import java.util.List; * Sentry group manipulation for CLI */ public class GroupShell implements ShellDependent { + + private final ShellUtil tools; + Shell shell; + + public GroupShell(SentryPolicyServiceClient sentryClient, String authUser) { + this.tools = new ShellUtil(sentryClient, authUser); + } + @Command public List<String> list() { return tools.listGroups(); @@ -50,14 +58,6 @@ public class GroupShell implements ShellDependent { tools.revokeGroupsFromRole(roleName, groups); } - private final ShellUtil tools; - Shell shell; - - - public GroupShell(SentryPolicyServiceClient sentryClient, String authUser) { - this.tools = new ShellUtil(sentryClient, authUser); - } - @Override public void cliSetShell(Shell theShell) { this.shell = theShell; http://git-wip-us.apache.org/repos/asf/sentry/blob/d9dbe56c/sentry-tools/src/main/java/org/apache/sentry/shell/PrivsShell.java ---------------------------------------------------------------------- diff --git a/sentry-tools/src/main/java/org/apache/sentry/shell/PrivsShell.java b/sentry-tools/src/main/java/org/apache/sentry/shell/PrivsShell.java index 9d8b9d9..b7db42e 100644 --- a/sentry-tools/src/main/java/org/apache/sentry/shell/PrivsShell.java +++ b/sentry-tools/src/main/java/org/apache/sentry/shell/PrivsShell.java @@ -30,6 +30,10 @@ public class PrivsShell implements ShellDependent { private final ShellUtil tools; Shell shell; + public PrivsShell(SentryPolicyServiceClient sentryClient, String authUser) { + this.tools = new ShellUtil(sentryClient, authUser); + } + @Command(description = "Grant privilege to role") public void grant( @Param(name = "roleName") @@ -62,10 +66,6 @@ public class PrivsShell implements ShellDependent { tools.revokePrivilegeFromRole(roleName, privilege); } - public PrivsShell(SentryPolicyServiceClient sentryClient, String authUser) { - this.tools = new ShellUtil(sentryClient, authUser); - } - @Override public void cliSetShell(Shell theShell) { this.shell = theShell; http://git-wip-us.apache.org/repos/asf/sentry/blob/d9dbe56c/sentry-tools/src/main/java/org/apache/sentry/shell/RolesShell.java ---------------------------------------------------------------------- diff --git a/sentry-tools/src/main/java/org/apache/sentry/shell/RolesShell.java b/sentry-tools/src/main/java/org/apache/sentry/shell/RolesShell.java index 9ac6637..856f422 100644 --- a/sentry-tools/src/main/java/org/apache/sentry/shell/RolesShell.java +++ b/sentry-tools/src/main/java/org/apache/sentry/shell/RolesShell.java @@ -30,6 +30,13 @@ import java.util.List; * Sentry roles manipulation for CLI. */ public class RolesShell implements ShellDependent { + private final ShellUtil tools; + Shell shell; + + public RolesShell(SentryPolicyServiceClient sentryClient, String authUser) { + this.tools = new ShellUtil(sentryClient, authUser); + } + @Command(description = "List sentry roles. shows all available roles.") public List<String> list() { return tools.listRoles(); @@ -56,17 +63,9 @@ public class RolesShell implements ShellDependent { tools.removeRoles(roles); } - @Override public void cliSetShell(Shell theShell) { this.shell = theShell; } - private final ShellUtil tools; - Shell shell; - - public RolesShell(SentryPolicyServiceClient sentryClient, String authUser) { - this.tools = new ShellUtil(sentryClient, authUser); - } - } http://git-wip-us.apache.org/repos/asf/sentry/blob/d9dbe56c/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 180d240..823d80c 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 @@ -51,7 +51,6 @@ public class SentryCli { 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"; http://git-wip-us.apache.org/repos/asf/sentry/blob/d9dbe56c/sentry-tools/src/main/java/org/apache/sentry/shell/ShellUtil.java ---------------------------------------------------------------------- diff --git a/sentry-tools/src/main/java/org/apache/sentry/shell/ShellUtil.java b/sentry-tools/src/main/java/org/apache/sentry/shell/ShellUtil.java index 007975c..5df21ae 100644 --- a/sentry-tools/src/main/java/org/apache/sentry/shell/ShellUtil.java +++ b/sentry-tools/src/main/java/org/apache/sentry/shell/ShellUtil.java @@ -34,8 +34,15 @@ import static org.apache.sentry.service.thrift.SentryServiceUtil.convertToTSentr */ class ShellUtil { + private final SentryPolicyServiceClient sentryClient; + private final String authUser; + + ShellUtil(SentryPolicyServiceClient sentryClient, String authUser) { + this.sentryClient = sentryClient; + this.authUser = authUser; + } + List<String> listRoles() { - List<String> roles = null; try { return getRoles(); } catch (SentryUserException e) { @@ -324,12 +331,4 @@ class ShellUtil { return roleNames; } - ShellUtil(SentryPolicyServiceClient sentryClient, String authUser) { - this.sentryClient = sentryClient; - this.authUser = authUser; - } - - private final SentryPolicyServiceClient sentryClient; - private final String authUser; - }
