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