Search in sources :

Example 1 with SecretCredentialInfo

use of org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo in project alien4cloud by alien4cloud.

the class SecretProviderService method getSecretCredentialInfo.

public SecretCredentialInfo getSecretCredentialInfo(String pluginName, Object rawSecretConfiguration) {
    SecretCredentialInfo info = new SecretCredentialInfo();
    Object secretConfiguration = getPluginConfiguration(pluginName, rawSecretConfiguration);
    Class<?> pluginAuthenticationConfigurationDescriptor = getPluginAuthenticationConfigurationDescriptor(pluginName, secretConfiguration);
    info.setCredentialDescriptor(pojoFormDescriptorGenerator.generateDescriptor(pluginAuthenticationConfigurationDescriptor));
    info.setPluginName(pluginName);
    return info;
}
Also used : SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo)

Example 2 with SecretCredentialInfo

use of org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method build.

/**
 * Create a deployment topology dto from the context of the execution of a deployment flow.
 *
 * @param executionContext The deployment flow execution context.
 * @return The deployment topology.
 */
private DeploymentTopologyDTO build(FlowExecutionContext executionContext) {
    // re-create the deployment topology object for api compatibility purpose
    DeploymentTopology deploymentTopology = new DeploymentTopology();
    ReflectionUtil.mergeObject(executionContext.getTopology(), deploymentTopology);
    deploymentTopology.setInitialTopologyId(executionContext.getTopology().getId());
    deploymentTopology.setEnvironmentId(executionContext.getEnvironmentContext().get().getEnvironment().getId());
    deploymentTopology.setVersionId(executionContext.getEnvironmentContext().get().getEnvironment().getTopologyVersion());
    DeploymentTopologyDTO deploymentTopologyDTO = new DeploymentTopologyDTO();
    topologyDTOBuilder.initTopologyDTO(deploymentTopology, deploymentTopologyDTO);
    // Convert log result to validation result.
    TopologyValidationResult validationResult = new TopologyValidationResult();
    for (AbstractTask task : executionContext.getLog().getInfos()) {
        validationResult.addInfo(task);
    }
    for (AbstractTask task : executionContext.getLog().getWarnings()) {
        validationResult.addWarning(task);
    }
    for (AbstractTask task : executionContext.getLog().getErrors()) {
        validationResult.addTask(task);
    }
    validationResult.setValid(validationResult.getTaskList() == null || validationResult.getTaskList().isEmpty());
    deploymentTopologyDTO.setValidation(validationResult);
    Optional<PreconfiguredInputsConfiguration> preconfiguredInputsConfiguration = executionContext.getConfiguration(PreconfiguredInputsConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!preconfiguredInputsConfiguration.isPresent()) {
        deploymentTopology.setPreconfiguredInputProperties(Maps.newHashMap());
    } else {
        deploymentTopology.setPreconfiguredInputProperties(preconfiguredInputsConfiguration.get().getInputs());
    }
    Optional<DeploymentInputs> inputsOptional = executionContext.getConfiguration(DeploymentInputs.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!inputsOptional.isPresent()) {
        deploymentTopology.setDeployerInputProperties(Maps.newHashMap());
        deploymentTopology.setUploadedInputArtifacts(Maps.newHashMap());
    } else {
        deploymentTopology.setDeployerInputProperties(inputsOptional.get().getInputs());
        deploymentTopology.setUploadedInputArtifacts(inputsOptional.get().getInputArtifacts());
    }
    Optional<DeploymentMatchingConfiguration> matchingConfigurationOptional = executionContext.getConfiguration(DeploymentMatchingConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
    if (!matchingConfigurationOptional.isPresent()) {
        return deploymentTopologyDTO;
    }
    DeploymentMatchingConfiguration matchingConfiguration = matchingConfigurationOptional.get();
    deploymentTopology.setOrchestratorId(matchingConfiguration.getOrchestratorId());
    deploymentTopology.setLocationGroups(matchingConfiguration.getLocationGroups());
    deploymentTopologyDTO.setLocationPolicies(matchingConfiguration.getLocationIds());
    // Good enough approximation as it doesn't contains just the location dependencies.
    deploymentTopology.setLocationDependencies(executionContext.getTopology().getDependencies());
    DeploymentSubstitutionConfiguration substitutionConfiguration = new DeploymentSubstitutionConfiguration();
    substitutionConfiguration.setSubstitutionTypes(new LocationResourceTypes());
    // fill DTO with policies substitution stuffs
    fillDTOWithPoliciesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    // fill DTO with nodes substitution stuffs
    fillDTOWithNodesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
    deploymentTopologyDTO.setAvailableSubstitutions(substitutionConfiguration);
    ApplicationEnvironment environment = executionContext.getEnvironmentContext().get().getEnvironment();
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = executionContext.getConfiguration(OrchestratorDeploymentProperties.class, this.getClass().getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), matchingConfiguration.getOrchestratorId()));
    deploymentTopology.setProviderDeploymentProperties(orchestratorDeploymentProperties.getProviderDeploymentProperties());
    deploymentTopologyDTO.setSecretCredentialInfos((List<SecretCredentialInfo>) executionContext.getExecutionCache().get(FlowExecutionContext.SECRET_CREDENTIAL));
    return deploymentTopologyDTO;
}
Also used : AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) DeploymentSubstitutionConfiguration(alien4cloud.deployment.model.DeploymentSubstitutionConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) LocationResourceTypes(alien4cloud.orchestrators.locations.services.LocationResourceTypes) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)

Example 3 with SecretCredentialInfo

use of org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo in project alien4cloud by alien4cloud.

the class LocationMatchingModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    // first process
    processLocationMatching(topology, context);
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
    // perform validation
    locationPolicyValidationService.validateLocationPolicies(configurationOptional.orElse(new DeploymentMatchingConfiguration())).forEach(locationPolicyTask -> context.log().error(locationPolicyTask));
    // No errors from validation let's inject location topology modifiers if any.
    if (context.log().isValid()) {
        Map<String, Location> selectedLocations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
        List<Location> locationsWithVault = selectedLocations.values().stream().filter(location -> location.getSecretProviderConfiguration() != null && location.getSecretProviderConfiguration().getConfiguration() != null).collect(Collectors.toList());
        boolean needVaultCredential = locationsWithVault.size() > 0;
        if (needVaultCredential) {
            List<SecretCredentialInfo> secretCredentialInfos = new LinkedList<>();
            for (Location location : locationsWithVault) {
                try {
                    SecretCredentialInfo info = new SecretCredentialInfo();
                    String pluginName = location.getSecretProviderConfiguration().getPluginName();
                    Object rawSecretConfiguration = location.getSecretProviderConfiguration().getConfiguration();
                    secretCredentialInfos.add(secretProviderService.getSecretCredentialInfo(pluginName, rawSecretConfiguration));
                } catch (Exception e) {
                    log.error("Cannot process secret provider configuration", e);
                }
            }
            context.getExecutionCache().put(FlowExecutionContext.SECRET_CREDENTIAL, secretCredentialInfos);
        } else {
            context.getExecutionCache().remove(FlowExecutionContext.SECRET_CREDENTIAL);
        }
        for (LocationModifierReference modifierReference : safe(selectedLocations.values().iterator().next().getModifiers())) {
            if (pluginManager.getPluginOrFail(modifierReference.getPluginId()).isEnabled()) {
                injectLocationTopologyModfier(context, selectedLocations.values().iterator().next().getName(), modifierReference);
            } else {
                log.info("The plugin " + modifierReference.getPluginId() + " is not activated. Ignoring " + modifierReference.getBeanName() + ".");
            }
        }
    }
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) LocationService(alien4cloud.orchestrators.locations.services.LocationService) PluginManager(alien4cloud.plugin.PluginManager) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) LocationPolicyValidationService(alien4cloud.topology.validation.LocationPolicyValidationService) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LocationMatchingService(alien4cloud.deployment.matching.services.location.LocationMatchingService) Lists(com.google.common.collect.Lists) Map(java.util.Map) SecretProviderService(org.alien4cloud.secret.services.SecretProviderService) LinkedList(java.util.LinkedList) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ToscaContext(alien4cloud.tosca.context.ToscaContext) MapUtils(org.apache.commons.collections4.MapUtils) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) List(java.util.List) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Optional(java.util.Optional) Topology(org.alien4cloud.tosca.model.templates.Topology) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LinkedList(java.util.LinkedList) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Map(java.util.Map) Location(alien4cloud.model.orchestrators.locations.Location)

Example 4 with SecretCredentialInfo

use of org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo 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)

Aggregations

SecretCredentialInfo (org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 Location (alien4cloud.model.orchestrators.locations.Location)2 List (java.util.List)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 MetaPropertiesService (alien4cloud.common.MetaPropertiesService)1 LocationMatchingService (alien4cloud.deployment.matching.services.location.LocationMatchingService)1 DeploymentSubstitutionConfiguration (alien4cloud.deployment.model.DeploymentSubstitutionConfiguration)1 Application (alien4cloud.model.application.Application)1 Deployment (alien4cloud.model.deployment.Deployment)1 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)1 LocationModifierReference (alien4cloud.model.orchestrators.locations.LocationModifierReference)1 LocationResourceTypes (alien4cloud.orchestrators.locations.services.LocationResourceTypes)1 LocationService (alien4cloud.orchestrators.locations.services.LocationService)1 PluginManager (alien4cloud.plugin.PluginManager)1 MissingPluginException (alien4cloud.plugin.exception.MissingPluginException)1 TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)1 AbstractTask (alien4cloud.topology.task.AbstractTask)1 LocationPolicyValidationService (alien4cloud.topology.validation.LocationPolicyValidationService)1