Search in sources :

Example 1 with TestIamPermissionsResponse

use of com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse in project google-cloud-java by GoogleCloudPlatform.

the class HttpResourceManagerRpc method testPermissions.

@Override
public List<Boolean> testPermissions(String projectId, List<String> permissions) throws ResourceManagerException {
    try {
        TestIamPermissionsResponse response = resourceManager.projects().testIamPermissions(projectId, new TestIamPermissionsRequest().setPermissions(permissions)).execute();
        Set<String> permissionsOwned = ImmutableSet.copyOf(firstNonNull(response.getPermissions(), ImmutableList.<String>of()));
        ImmutableList.Builder<Boolean> answer = ImmutableList.builder();
        for (String p : permissions) {
            answer.add(permissionsOwned.contains(p));
        }
        return answer.build();
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : TestIamPermissionsResponse(com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse) TestIamPermissionsRequest(com.google.api.services.cloudresourcemanager.model.TestIamPermissionsRequest) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException)

Aggregations

TestIamPermissionsRequest (com.google.api.services.cloudresourcemanager.model.TestIamPermissionsRequest)1 TestIamPermissionsResponse (com.google.api.services.cloudresourcemanager.model.TestIamPermissionsResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1