use of com.sequenceiq.cloudbreak.cloud.azure.AzureRoleDefinitionListResponse in project cloudbreak by hortonworks.
the class AzureRoleManager method getRoleDefinitions.
private List<AzureRoleDefinition> getRoleDefinitions(String subscriptionId, String accessToken, String filter) throws InteractiveLoginException {
Client client = ClientBuilder.newClient();
WebTarget resource = client.target(AZURE_MANAGEMENT);
Builder request = resource.path("subscriptions/" + subscriptionId + "/providers/Microsoft.Authorization/roleDefinitions").queryParam("$filter", filter).queryParam("api-version", "2015-07-01").request();
request.accept(MediaType.APPLICATION_JSON);
request.header("Authorization", "Bearer " + accessToken);
Response response = request.get();
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
AzureRoleDefinitionListResponse azureRoleDefinitionListResponse = response.readEntity(AzureRoleDefinitionListResponse.class);
LOGGER.info("Role definitions retrieved:" + azureRoleDefinitionListResponse.getValue());
return azureRoleDefinitionListResponse.getValue();
} else {
String errorResponse = response.readEntity(String.class);
LOGGER.error("Get role definition request with filter: {}, failed: {}", filter, errorResponse);
if (Status.FORBIDDEN.getStatusCode() == response.getStatus()) {
throw new InteractiveLoginException("You have no permission to access Active Directory roles, please contact with your administrator");
} else {
try {
String errorMessage = new ObjectMapper().readTree(errorResponse).get("error").get("message").asText();
throw new InteractiveLoginException("Get role definition request with filter: " + filter + " failed: " + errorMessage);
} catch (IOException e) {
throw new InteractiveLoginException("Get role definition request with filter: " + filter + " failed:" + errorResponse);
}
}
}
}
Aggregations