use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method listPrograms.
/**
* Lists all programs belonging to an application.
*
* @param app the application
* @return List of all {@link ProgramRecord}s
* @throws ApplicationNotFoundException if the application with the given ID was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<ProgramRecord> listPrograms(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion());
URL url = config.resolveNamespacedURLV3(app.getParent(), path);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(app);
}
return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject().getPrograms();
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method removeRoleFromPrincipal.
@Override
public void removeRoleFromPrincipal(Role role, Principal principal) throws AccessException {
URL url = resolveURL(String.format(AUTHORIZATION_BASE + "%s/%s/roles/%s", principal.getType(), principal.getName(), role.getName()));
HttpRequest request = HttpRequest.delete(url).build();
executeExistingRolesRequest(role, request);
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method listRolesHelper.
private Set<Role> listRolesHelper(@Nullable Principal principal) throws AccessException {
URL url = principal == null ? resolveURL(AUTHORIZATION_BASE + "roles") : resolveURL(String.format(AUTHORIZATION_BASE + "%s/%s/roles", principal.getType(), principal.getName()));
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = doExecuteRequest(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, TYPE_OF_ROLE_SET).getResponseObject();
}
throw new AccessIOException(String.format("Cannot list roles. Reason: %s", response.getResponseBodyAsString()));
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method dropRole.
@Override
public void dropRole(Role role) throws AccessException {
URL url = resolveURL(String.format(AUTHORIZATION_BASE + "roles/%s", role.getName()));
HttpRequest request = HttpRequest.delete(url).build();
executeExistingRolesRequest(role, request);
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method revoke.
private void revoke(RevokeRequest revokeRequest) throws AccessException {
URL url = resolveURL(AUTHORIZATION_BASE + "/privileges/revoke");
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(revokeRequest)).build();
executePrivilegeRequest(request);
}
Aggregations