Search in sources :

Example 6 with GitLocation

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

the class GitLocationService method updateGitLocation.

@SneakyThrows(IOException.class)
private void updateGitLocation(GitLocation newGitLocation) {
    Path tempPath = tempDirPath.resolve(UUID.randomUUID().toString());
    GitLocation previousLocation = gitLocationDao.findById(newGitLocation.getId());
    if (previousLocation != null) {
        // move data for copy to a temporary location
        FileUtil.copy(localGitManager.getLocalGitPath(previousLocation), tempPath);
        // delte the repository
        localGitManager.deleteLocalGit(previousLocation);
    }
    // create the new one
    localGitManager.checkout(newGitLocation);
    gitLocationDao.save(newGitLocation);
    // copy all files that where defined and does not exist in the new repository.
    if (Files.exists(tempPath)) {
        User currentUser = AuthorizationUtil.getCurrentUser();
        FileUtil.copy(tempPath, localGitManager.getLocalGitPath(newGitLocation), true);
        localGitManager.commitAndPush(newGitLocation, currentUser.getUsername(), currentUser.getEmail(), "a4c: Copy existing deployment configuration to associated repository.");
        FileUtil.delete(tempPath);
    }
}
Also used : Path(java.nio.file.Path) User(alien4cloud.security.model.User) GitLocation(org.alien4cloud.git.model.GitLocation) SneakyThrows(lombok.SneakyThrows)

Example 7 with GitLocation

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

the class ApplicationVariableGitController method getByEnvironmentId.

@ApiOperation(value = "Retrieve information about a git repository using environment Id.")
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("isAuthenticated()")
public RestResponse<GitLocation> getByEnvironmentId(@ApiParam(value = "Application id", required = true) @PathVariable String applicationId) {
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    GitLocation gitLocation = gitLocationDao.findApplicationVariablesLocation(applicationId);
    if (gitLocation.isLocal()) {
        gitLocation.setUrl(GitLocation.LOCAL_PREFIX);
    }
    gitLocation.setCredential(new GitHardcodedCredential());
    return RestResponseBuilder.<GitLocation>builder().data(gitLocation).build();
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation) GitHardcodedCredential(org.alien4cloud.git.model.GitHardcodedCredential) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with GitLocation

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

the class ApplicationVariableGitController method updateToCustomGit.

@ApiOperation(value = "Update the remote git repository parameters for storing application variables.")
@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, @Valid @RequestBody UpdateGitLocationRequest request) {
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    String id = GitLocation.IdBuilder.forApplicationVariables(applicationId);
    GitLocation gitLocation = GitLocation.builder().id(id).gitType(GitType.ApplicationVariables).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)

Example 9 with GitLocation

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

the class ApplicationVariableController method getContent.

@PreAuthorize("isAuthenticated()")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<String> getContent(@PathVariable String applicationId) {
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    GitLocation gitLocation = gitLocationDao.findApplicationVariablesLocation(applicationId);
    localGitManager.checkout(gitLocation);
    return RestResponseBuilder.<String>builder().data(quickFileStorageService.getApplicationVariables(applicationId)).build();
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with GitLocation

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

the class ApplicationVariableController method upload.

@PreAuthorize("isAuthenticated()")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<Void> upload(@PathVariable String applicationId, @RequestBody UpdateVariableFileContentRequest request) {
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    GitLocation gitLocation = gitLocationDao.findApplicationVariablesLocation(applicationId);
    localGitManager.checkout(gitLocation);
    quickFileStorageService.saveApplicationVariables(applicationId, new ByteArrayInputStream(request.getContent().getBytes(StandardCharsets.UTF_8)));
    User user = AuthorizationUtil.getCurrentUser();
    localGitManager.commitAndPush(gitLocation, user.getUsername(), user.getEmail(), "Update application variables.");
    return new RestResponse<>();
}
Also used : User(alien4cloud.security.model.User) ByteArrayInputStream(java.io.ByteArrayInputStream) RestResponse(alien4cloud.rest.model.RestResponse) GitLocation(org.alien4cloud.git.model.GitLocation) 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