use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class SecretProviderRegistry method usage.
@Override
public List<PluginUsage> usage(String pluginId) {
GetMultipleDataResult<Location> locationData = alienDAO.buildQuery(Location.class).prepareSearch().search(0, Integer.MAX_VALUE);
List<PluginUsage> usages = Lists.newArrayList();
for (Location location : locationData.getData()) {
SecretProviderConfiguration locationSecretProviderConfiguration = location.getSecretProviderConfiguration();
if (locationSecretProviderConfiguration != null && locationSecretProviderConfiguration.getPluginName().equals(pluginId)) {
usages.add(new PluginUsage(location.getId(), location.getName(), Location.class.getSimpleName()));
}
}
return usages;
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationResourceServiceTest method initLocation.
private void initLocation(String locationId) {
Location location = new Location();
location.setId(LOCATION_ID);
alienDAO.save(location);
location.setId(UNCONFIGURED_LOCATION_ID);
alienDAO.save(location);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < TYPE_CONFIGURED_ELEMENTS; j++) {
String type = i == 0 ? CONFIGURED_TYPE : CONFIGURED_TYPE + "." + i;
NodeTemplate template = new NodeTemplate();
template.setType(type);
template.setName("template_" + i + "_" + j);
LocationResourceTemplate lrt = new LocationResourceTemplate();
lrt.setId(UUID.randomUUID().toString());
lrt.setLocationId(locationId);
lrt.setGenerated(false);
lrt.setEnabled(true);
lrt.setService(false);
lrt.setTemplate(template);
lrt.setTypes(Lists.newArrayList(template.getType()));
alienDAO.save(lrt);
}
}
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class MockLocationMatcher method match.
@Override
public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
log.info("Mock location matcher <" + this.getClass().getName() + "> called!");
List<ILocationMatch> matched = Lists.newArrayList();
// get all enabled orchestrators
try {
List<Orchestrator> enabledOrchestrators = orchestratorService.getAllEnabledOrchestrators();
if (CollectionUtils.isEmpty(enabledOrchestrators)) {
return matched;
}
Map<String, Orchestrator> orchestratorMap = AlienUtils.fromListToMap(enabledOrchestrators, "id", true);
List<Location> locations = locationService.getOrchestratorsLocations(orchestratorMap.keySet());
for (Location location : locations) {
matched.add(new LocationMatch(location, orchestratorMap.get(location.getOrchestratorId()), null));
}
new MockLocationMatchOrchestratorFilter(selfContext).filter(matched, topology);
return matched;
} catch (Exception e) {
throw new LocationMatchingException("Failed to match topology <" + topology.getId() + "> against locations. ", e);
}
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method getSecretProviderConfigurationsForCurrentDeployment.
@ApiOperation(value = "Get current secret provider configuration for the given application on the given cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/current-secret-provider-configurations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<List<SecretCredentialInfo>> getSecretProviderConfigurationsForCurrentDeployment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
Application application = applicationService.checkAndGetApplication(applicationId);
// get the topology from the version and the cloud from the environment
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.APPLICATION_USER);
Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
List<SecretCredentialInfo> secretProviderConfigurations = Lists.newArrayList();
for (int i = 0; i < deployment.getLocationIds().length; i++) {
Location location = locationService.getOrFail(deployment.getLocationIds()[i]);
if (location.getSecretProviderConfiguration() != null) {
secretProviderConfigurations.add(secretProviderService.getSecretCredentialInfo(location.getSecretProviderConfiguration().getPluginName(), location.getSecretProviderConfiguration().getConfiguration()));
}
}
return RestResponseBuilder.<List<SecretCredentialInfo>>builder().data(secretProviderConfigurations).build();
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationSecurityController method revokeUserAccess.
/**
* Revoke the user's authorisation to access the location
*
* @param locationId The id of the location.
* @param username The authorized user.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Revoke the user's authorisation to access the location, send back the new authorised users list", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/users/{username}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<UserDTO>> revokeUserAccess(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String username) {
Location location = locationService.getLocation(orchestratorId, locationId);
resourcePermissionService.revokePermission(location, Subject.USER, username);
List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(location));
return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Aggregations