sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2378: Sqoop2: Revoke all privileges command
Date Thu, 04 Jun 2015 11:27:51 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 06e9cdca4 -> 519693643


SQOOP-2378: Sqoop2: Revoke all privileges command

(Dian Fu via Abraham Elmahrek)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/51969364
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/51969364
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/51969364

Branch: refs/heads/sqoop2
Commit: 519693643affebb1c95de64388a0615fbf8e2043
Parents: 06e9cdc
Author: Abraham Elmahrek <abe@apache.org>
Authored: Thu Jun 4 14:26:45 2015 +0300
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Thu Jun 4 14:26:45 2015 +0300

----------------------------------------------------------------------
 .../org/apache/sqoop/client/SqoopClient.java    |  3 +-
 .../sqoop/shell/RevokePrivilegeFunction.java    | 43 +++++++++++++++-----
 .../org/apache/sqoop/shell/core/Constants.java  |  2 +
 .../main/resources/shell-resource.properties    |  2 +
 4 files changed, 39 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/51969364/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
index d5c4a8a..3102951 100644
--- a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
+++ b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
@@ -634,7 +634,8 @@ public class SqoopClient {
   }
 
   /**
-   * Revoke privileges on principals.
+   * Revoke privileges on principals and will revoke all privileges on principals
+   * if privileges is null.
    *
    * @param principals MPrincipal List
    * @param privileges MPrivilege List

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51969364/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java b/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
index 802d206..d32f6dd 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
@@ -32,27 +32,26 @@ import static org.apache.sqoop.shell.ShellEnvironment.client;
 import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
 import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
 
+import static org.apache.sqoop.shell.utils.ConfigFiller.errorMessage;
+
 public class RevokePrivilegeFunction extends SqoopFunction {
   @SuppressWarnings("static-access")
   public RevokePrivilegeFunction() {
     this.addOption(OptionBuilder
         .withLongOpt(Constants.OPT_RESOURCE_TYPE)
         .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE_TYPE))
-        .isRequired()
         .hasArg()
         .create()
     );
     this.addOption(OptionBuilder
         .withLongOpt(Constants.OPT_RESOURCE)
         .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE))
-        .isRequired()
         .hasArg()
         .create()
     );
     this.addOption(OptionBuilder
         .withLongOpt(Constants.OPT_ACTION)
         .withDescription(resourceString(Constants.RES_PROMPT_ACTION))
-        .isRequired()
         .hasArg()
         .create(Constants.OPT_ACTION_CHAR)
     );
@@ -92,20 +91,44 @@ public class RevokePrivilegeFunction extends SqoopFunction {
   private Status revokePrivilege(String action, String resourceType, String resource,
                                  String principalType, String principal, boolean withGrant)
     throws IOException {
-    MResource resourceObject = new MResource(resource, resourceType);
-    MPrivilege privilegeObject = new MPrivilege(resourceObject, action, withGrant);
+    MPrivilege privilegeObject = null;
+    if (resource != null && !resource.isEmpty()
+        && resourceType != null && !resourceType.isEmpty()
+        && action != null && !action.isEmpty()) {
+      MResource resourceObject = new MResource(resource, resourceType);
+      privilegeObject = new MPrivilege(resourceObject, action, withGrant);
+    } else if ((resource == null || resource.isEmpty())
+        && (resourceType == null || resourceType.isEmpty())
+        && (action == null || action.isEmpty())) {
+      // revoke all privileges on the principal
+      privilegeObject = null;
+    } else if (resource == null || resource.isEmpty()) {
+      errorMessage("--resource isn't specified.");
+      return Status.ERROR;
+    } else if (resourceType == null || resourceType.isEmpty()) {
+      errorMessage("--resource-type isn't specified.");
+      return Status.ERROR;
+    } else if (action == null || action.isEmpty()) {
+      errorMessage("--action isn't specified.");
+      return Status.ERROR;
+    }
     MPrincipal principalObject = new MPrincipal(principal, principalType);
 
     client.revokePrivilege(
       Arrays.asList(principalObject),
-      Arrays.asList(privilegeObject));
+      privilegeObject == null ? null : Arrays.asList(privilegeObject));
 
     client.clearCache();
 
-    printlnResource(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL,
-      action, resourceType + " " + resource,
-      ((withGrant) ? " " + resourceString(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL_WITH_GRANT)
: ""),
-      principalType + " " + principal);
+    if (privilegeObject != null) {
+      printlnResource(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL,
+        action, resourceType + " " + resource,
+        ((withGrant) ? " " + resourceString(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL_WITH_GRANT)
: ""),
+        principalType + " " + principal);
+    } else {
+      printlnResource(Constants.RES_REVOKE_ALL_PRIVILEGES_SUCCESSFUL,
+        principalType + " " + principal);
+    }
 
     return Status.OK;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51969364/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
index 40ed9fc..c385434 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
@@ -469,6 +469,8 @@ public class Constants {
     "revoke.role_successful";
   public static final String RES_REVOKE_PRIVILEGE_SUCCESSFUL =
     "revoke.privilege_successful";
+  public static final String RES_REVOKE_ALL_PRIVILEGES_SUCCESSFUL =
+    "revoke.all_privileges_successful";
   public static final String RES_REVOKE_PRIVILEGE_SUCCESSFUL_WITH_GRANT =
     "revoke.privilege_successful_with_grant";
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51969364/shell/src/main/resources/shell-resource.properties
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/shell-resource.properties b/shell/src/main/resources/shell-resource.properties
index 62bbbeb..50c32b6 100644
--- a/shell/src/main/resources/shell-resource.properties
+++ b/shell/src/main/resources/shell-resource.properties
@@ -202,6 +202,8 @@ grant.role_successful = Granted role {0} to principal {1} successfully
 revoke.description = Revoke access from roles and remove privileges
 revoke.privilege_successful = Revoked action {0} on resource {1}{2} to \
   principal {3} successfully
+revoke.all_privileges_successful = Revoked all privileges from \
+  principal {0} successfully
 revoke.privilege_successful_with_grant = with grant
 revoke.role_successful = Revoked role {0} from principal {1} successfully
 


Mime
View raw message