use of io.hops.hopsworks.exceptions.GitOpException in project hopsworks by logicalclocks.
the class GitJWTManager method materializeJWT.
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void materializeJWT(Users user, String tokenPath) throws GitOpException {
LocalDateTime expirationDate = LocalDateTime.now().plus(settings.getGitJwtExpMs(), ChronoUnit.MILLIS);
String token = createTokenForGitContainer(user, expirationDate);
try {
FileUtils.writeStringToFile(getTokenFullPath(tokenPath).toFile(), token);
} catch (IOException e) {
throw new GitOpException(RESTCodes.GitOpErrorCode.JWT_MATERIALIZATION_ERROR, Level.SEVERE, "Failed to " + "materialize jwt", e.getMessage(), e);
}
}
use of io.hops.hopsworks.exceptions.GitOpException in project hopsworks by logicalclocks.
the class GitJWTManager method createTokenForGitContainer.
private String createTokenForGitContainer(String username, String[] userRoles, LocalDateTime expirationDate) throws GitOpException {
try {
Map<String, Object> claims = new HashMap<>();
claims.put(Constants.ROLES, userRoles);
claims.put(Constants.RENEWABLE, false);
return jwtController.createToken(settings.getJWTSigningKeyName(), false, settings.getJWTIssuer(), new String[] { "api", "git" }, DateUtils.localDateTime2Date(expirationDate), DateUtils.localDateTime2Date(DateUtils.getNow()), username, claims, SignatureAlgorithm.valueOf(settings.getJWTSignatureAlg()));
} catch (DuplicateSigningKeyException | NoSuchAlgorithmException | SigningKeyNotFoundException e) {
throw new GitOpException(RESTCodes.GitOpErrorCode.JWT_NOT_CREATED, Level.SEVERE, "Failed to create jwt token " + "for git", e.getMessage(), e);
}
}
use of io.hops.hopsworks.exceptions.GitOpException in project hopsworks by logicalclocks.
the class GitRepositoryRemoteBuilder method build.
public GitRepositoryRemoteDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, GitRepository repository, String remoteName) throws GitOpException {
Optional<GitRepositoryRemote> optional = gitRepositoryRemotesFacade.findByNameAndRepository(repository, remoteName);
GitRepositoryRemote remote = optional.orElseThrow(() -> new GitOpException(RESTCodes.GitOpErrorCode.REMOTE_NOT_FOUND, Level.FINE, "Remote with name [" + remoteName + "] not found"));
return build(uriInfo, resourceRequest, project, repository, remote);
}
use of io.hops.hopsworks.exceptions.GitOpException in project hopsworks by logicalclocks.
the class GitCommandOperationUtil method generatePaths.
public void generatePaths(GitPaths gitPaths) throws GitOpException {
try {
File baseDir = new File(gitPaths.getGitPath());
baseDir.mkdirs();
// Set owner persmissions
Set<PosixFilePermission> xOnly = new HashSet<>();
xOnly.add(PosixFilePermission.OWNER_WRITE);
xOnly.add(PosixFilePermission.OWNER_READ);
xOnly.add(PosixFilePermission.OWNER_EXECUTE);
xOnly.add(PosixFilePermission.GROUP_WRITE);
xOnly.add(PosixFilePermission.GROUP_EXECUTE);
Set<PosixFilePermission> perms = new HashSet<>();
// add owners permission
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
// add group permissions
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
// add others permissions
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(Paths.get(gitPaths.getGitPath()), perms);
new File(gitPaths.getLogDirPath()).mkdirs();
new File(gitPaths.getCertificatesDirPath()).mkdirs();
new File(gitPaths.getRunDirPath()).mkdirs();
new File(gitPaths.getTokenPath()).mkdirs();
new File(gitPaths.getConfDirPath()).mkdirs();
} catch (IOException ex) {
removeProjectUserDirRecursive(gitPaths);
throw new GitOpException(RESTCodes.GitOpErrorCode.GIT_PATHS_CREATION_ERROR, Level.SEVERE, "Failed to " + "create git paths", ex.getMessage(), ex);
}
}
use of io.hops.hopsworks.exceptions.GitOpException in project hopsworks by logicalclocks.
the class GitCommandConfigurationBuilder method build.
public GitCommandConfiguration build() throws GitOpException {
GitCommandConfiguration commandConfiguration = new GitCommandConfiguration();
commandConfiguration.setRemoteName(this.remoteName);
commandConfiguration.setRemoteUrl(this.remoteUrl);
commandConfiguration.setBranchName(this.branchName);
commandConfiguration.setForce(this.force);
commandConfiguration.setCommit(this.commit);
commandConfiguration.setUrl(this.url);
commandConfiguration.setProvider(this.provider);
commandConfiguration.setMessage(this.message);
commandConfiguration.setCommitter(this.committer);
commandConfiguration.setAll(this.all);
commandConfiguration.setFiles(this.files);
commandConfiguration.setCheckout(this.checkout);
commandConfiguration.setDeleteOnRemote(this.deleteOnRemote);
commandConfiguration.setCommandType(this.commandType);
commandConfiguration.setPath(this.path);
if (Strings.isNullOrEmpty(this.path) || this.commandType == null) {
throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_GIT_COMMAND_CONFIGURATION, Level.FINE, "Path and " + "command type in command configuration cannot be null");
}
return commandConfiguration;
}
Aggregations