Search in sources :

Example 11 with GitLocation

use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method doDeploy.

private RestResponse<?> doDeploy(DeployApplicationRequest deployApplicationRequest, Application application, ApplicationEnvironment environment, Topology topology) {
    DeploymentTopologyDTO deploymentTopologyDTO = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
    TopologyValidationResult validation = deploymentTopologyDTO.getValidation();
    // if not valid, then return validation errors
    if (!validation.isValid()) {
        return RestResponseBuilder.<TopologyValidationResult>builder().error(new RestError(RestErrorCode.INVALID_DEPLOYMENT_TOPOLOGY.getCode(), "The deployment topology for the application <" + application.getName() + "> on the environment <" + environment.getName() + "> is not valid.")).data(validation).build();
    }
    User deployer = AuthorizationUtil.getCurrentUser();
    // commit and push the deployment configuration data
    GitLocation location = gitLocationDao.findDeploymentSetupLocation(application.getId(), environment.getId());
    localGitManager.commitAndPush(location, deployer.getUsername(), deployer.getEmail(), "Deployment " + DateTime.now(DateTimeZone.UTC));
    // the request contains secret provider credentials?
    SecretProviderCredentials secretProviderCredentials = null;
    if (deployApplicationRequest.getSecretProviderCredentials() != null && deployApplicationRequest.getSecretProviderPluginName() != null) {
        secretProviderCredentials = new SecretProviderCredentials();
        secretProviderCredentials.setCredentials(deployApplicationRequest.getSecretProviderCredentials());
        secretProviderCredentials.setPluginName(deployApplicationRequest.getSecretProviderPluginName());
    }
    // process with the deployment
    deployService.deploy(deployer, secretProviderCredentials, deploymentTopologyDTO.getTopology(), application);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) SecretProviderCredentials(alien4cloud.deployment.model.SecretProviderCredentials) User(alien4cloud.security.model.User) RestError(alien4cloud.rest.model.RestError) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) GitLocation(org.alien4cloud.git.model.GitLocation)

Example 12 with GitLocation

use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentGitController method updateToCustomGit.

@ApiOperation(value = "Update the remote git repository parameters for storing environment deployment config")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> updateToCustomGit(@ApiParam(value = "Application id", required = true) @PathVariable String applicationId, @ApiParam(value = "Environment id", required = true) @PathVariable String environmentId, @Valid @RequestBody UpdateGitLocationRequest request) {
    checkEnvironmentAuthorization(applicationId, environmentId);
    String id = GitLocation.IdBuilder.forDeploymentSetup(applicationId, environmentId);
    GitLocation gitLocation = GitLocation.builder().id(id).gitType(GitLocation.GitType.DeploymentConfig).branch(request.getBranch()).credential(new GitHardcodedCredential(request.getUsername(), request.getPassword())).path(request.getPath()).url(request.getUrl()).build();
    gitLocationService.updateToRemoteGit(gitLocation);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation) GitHardcodedCredential(org.alien4cloud.git.model.GitHardcodedCredential) 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

GitLocation (org.alien4cloud.git.model.GitLocation)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ApiOperation (io.swagger.annotations.ApiOperation)4 GitHardcodedCredential (org.alien4cloud.git.model.GitHardcodedCredential)4 User (alien4cloud.security.model.User)3 Audit (alien4cloud.audit.annotation.Audit)2 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)1 SecretProviderCredentials (alien4cloud.deployment.model.SecretProviderCredentials)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 RestError (alien4cloud.rest.model.RestError)1 RestResponse (alien4cloud.rest.model.RestResponse)1 TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Path (java.nio.file.Path)1 PostConstruct (javax.annotation.PostConstruct)1 SneakyThrows (lombok.SneakyThrows)1