From a80889f947d6e190bfd80e8cf02586a38f235409 Mon Sep 17 00:00:00 2001
From: Ajit Thakor <49403056+athakor@users.noreply.github.com>
Date: Tue, 7 Apr 2020 17:57:08 +0530
Subject: [PATCH] feat: implement testPermission api of organizations (#125)
* feat: implement testPermission api of organization
* feat: modified java doc
* feat: modified java doc
* feat: fix review changes
* feat: fix javadoc
---
.../clirr-ignored-differences.xml | 14 +++++
java-resourcemanager/pom.xml | 7 +++
.../resourcemanager/ResourceManager.java | 17 ++++++
.../ResourceManagerException.java | 2 +-
.../resourcemanager/ResourceManagerImpl.java | 20 ++++++
.../spi/v1beta1/HttpResourceManagerRpc.java | 23 +++++++
.../spi/v1beta1/ResourceManagerRpc.java | 10 ++-
.../ResourceManagerImplTest.java | 61 +++++++++++++++++++
8 files changed, 152 insertions(+), 2 deletions(-)
create mode 100644 java-resourcemanager/clirr-ignored-differences.xml
diff --git a/java-resourcemanager/clirr-ignored-differences.xml b/java-resourcemanager/clirr-ignored-differences.xml
new file mode 100644
index 000000000000..da1f3c38fdb9
--- /dev/null
+++ b/java-resourcemanager/clirr-ignored-differences.xml
@@ -0,0 +1,14 @@
+
+
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ java.util.Map testOrgPermissions(java.lang.String, java.util.List)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ java.util.Map testOrgPermissions(java.lang.String, java.util.List)
+ 7012
+
+
diff --git a/java-resourcemanager/pom.xml b/java-resourcemanager/pom.xml
index ba556b4bd9de..7fa039a74922 100644
--- a/java-resourcemanager/pom.xml
+++ b/java-resourcemanager/pom.xml
@@ -72,6 +72,7 @@
1.93.3
1.30.9
3.6
+ 1.10.19
2.6
0.20.0
1.34.2
@@ -205,6 +206,12 @@
+
+ org.mockito
+ mockito-all
+ ${mockito.version}
+ test
+
org.objenesis
objenesis
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
index 9da158000ec4..b2a46edf09dd 100644
--- a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
@@ -24,6 +24,7 @@
import com.google.cloud.resourcemanager.spi.v1beta1.ResourceManagerRpc;
import com.google.common.collect.ImmutableList;
import java.util.List;
+import java.util.Map;
/**
* An interface for Google Cloud Resource Manager.
@@ -337,4 +338,20 @@ public static ProjectListOption fields(ProjectField... fields) {
* Platform Services
*/
List testPermissions(String projectId, List permissions);
+
+ /**
+ * Returns the permissions and their results representing whether the caller has the permissions
+ * on the specified Organization.
+ *
+ * @param resource the organization's resource name, e.g. "organizations/123"
+ * @param permissions the set of permissions to check for the resource. Permissions with wildcards
+ * (such as '*' or 'storage.*') are not allowed.
+ * @return the permissions and their results representing whether the caller has the permissions
+ * on the specified Organization.
+ * @throws ResourceManagerException upon failure
+ * @see
+ * Resource Manager testIamPermissions
+ */
+ Map testOrgPermissions(String resource, List permissions);
}
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerException.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerException.java
index e8c7f8d03e1c..cc820ee07d43 100644
--- a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerException.java
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerException.java
@@ -66,7 +66,7 @@ public ResourceManagerException(IOException exception) {
* @throws ResourceManagerException when {@code ex} was caused by a {@code
* ResourceManagerException}
*/
- static ResourceManagerException translateAndThrow(RetryHelperException ex) {
+ public static ResourceManagerException translateAndThrow(RetryHelperException ex) {
BaseServiceException.translate(ex);
throw new ResourceManagerException(UNKNOWN_CODE, ex.getMessage(), ex.getCause());
}
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java
index 7651e645b920..557567d95688 100644
--- a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java
@@ -32,6 +32,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -273,6 +274,25 @@ public List call() {
}
}
+ @Override
+ public Map testOrgPermissions(
+ final String resource, final List permissions) {
+ try {
+ return runWithRetries(
+ new Callable