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;
}
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;
}
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() + ".");
}
}
}
}
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();
}
Aggregations