@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); } } }
private Response handlePost(HttpExchange exchange, String path) throws IOException { String requestBody = decodeContent(exchange.getRequestHeaders(), exchange.getRequestBody()); if (!path.contains(":")) { return create(jsonFactory.fromString(requestBody, Project.class)); } else { switch (path.split(":", 2)[1]) { case "undelete": return undelete(projectIdFromUri(path)); case "getIamPolicy": return getPolicy(projectIdFromUri(path)); case "setIamPolicy": return replacePolicy( projectIdFromUri(path), jsonFactory.fromString(requestBody, SetIamPolicyRequest.class).getPolicy()); case "testIamPermissions": return testPermissions( projectIdFromUri(path), jsonFactory .fromString(requestBody, TestIamPermissionsRequest.class) .getPermissions()); default: return Error.BAD_REQUEST.response( "The server could not understand the following request URI: POST " + path); } } }
@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); } } }
private Response handlePost(HttpExchange exchange, String path) throws IOException { String requestBody = decodeContent(exchange.getRequestHeaders(), exchange.getRequestBody()); if (!path.contains(":")) { return create(jsonFactory.fromString(requestBody, Project.class)); } else { switch (path.split(":", 2)[1]) { case "undelete": return undelete(projectIdFromUri(path)); case "getIamPolicy": return getPolicy(projectIdFromUri(path)); case "setIamPolicy": return replacePolicy(projectIdFromUri(path), jsonFactory.fromString(requestBody, SetIamPolicyRequest.class).getPolicy()); case "testIamPermissions": return testPermissions(projectIdFromUri(path), jsonFactory.fromString(requestBody, TestIamPermissionsRequest.class) .getPermissions()); default: return Error.BAD_REQUEST.response( "The server could not understand the following request URI: POST " + path); } } }
@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); } } }
private Response handlePost(HttpExchange exchange, String path) throws IOException { String requestBody = decodeContent(exchange.getRequestHeaders(), exchange.getRequestBody()); if (!path.contains(":")) { return create(jsonFactory.fromString(requestBody, Project.class)); } else { switch (path.split(":", 2)[1]) { case "undelete": return undelete(projectIdFromUri(path)); case "getIamPolicy": return getPolicy(projectIdFromUri(path)); case "setIamPolicy": return replacePolicy(projectIdFromUri(path), jsonFactory.fromString(requestBody, SetIamPolicyRequest.class).getPolicy()); case "testIamPermissions": return testPermissions(projectIdFromUri(path), jsonFactory.fromString(requestBody, TestIamPermissionsRequest.class) .getPermissions()); default: return Error.BAD_REQUEST.response( "The server could not understand the following request URI: POST " + path); } } }