Search in sources :

Example 61 with Location

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;
}
Also used : PluginUsage(alien4cloud.plugin.model.PluginUsage) Location(alien4cloud.model.orchestrators.locations.Location) SecretProviderConfiguration(alien4cloud.model.secret.SecretProviderConfiguration)

Example 62 with Location

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);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) Location(alien4cloud.model.orchestrators.locations.Location)

Example 63 with Location

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);
    }
}
Also used : LocationMatch(alien4cloud.model.deployment.matching.LocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Location(alien4cloud.model.orchestrators.locations.Location)

Example 64 with Location

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();
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) List(java.util.List) ArrayList(java.util.ArrayList) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) GitLocation(org.alien4cloud.git.model.GitLocation) Location(alien4cloud.model.orchestrators.locations.Location) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with Location

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();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Location (alien4cloud.model.orchestrators.locations.Location)80 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 ApiOperation (io.swagger.annotations.ApiOperation)30 List (java.util.List)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)28 Audit (alien4cloud.audit.annotation.Audit)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)15 LocationService (alien4cloud.orchestrators.locations.services.LocationService)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Application (alien4cloud.model.application.Application)12 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)12 RestResponse (alien4cloud.rest.model.RestResponse)12 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)12 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)12 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)12 Resource (javax.annotation.Resource)12 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11