Search in sources :

Example 1 with GitOpException

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);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) GitOpException(io.hops.hopsworks.exceptions.GitOpException) IOException(java.io.IOException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with GitOpException

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);
    }
}
Also used : DuplicateSigningKeyException(io.hops.hopsworks.jwt.exception.DuplicateSigningKeyException) HashMap(java.util.HashMap) SigningKeyNotFoundException(io.hops.hopsworks.jwt.exception.SigningKeyNotFoundException) GitOpException(io.hops.hopsworks.exceptions.GitOpException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with GitOpException

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);
}
Also used : GitRepositoryRemote(io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Example 4 with GitOpException

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);
    }
}
Also used : GitOpException(io.hops.hopsworks.exceptions.GitOpException) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with GitOpException

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;
}
Also used : GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Aggregations

GitOpException (io.hops.hopsworks.exceptions.GitOpException)10 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)3 IOException (java.io.IOException)3 TransactionAttribute (javax.ejb.TransactionAttribute)2 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 GitCommitsFacade (io.hops.hopsworks.common.dao.git.GitCommitsFacade)1 GitPaths (io.hops.hopsworks.common.dao.git.GitPaths)1 GitCommitDTO (io.hops.hopsworks.common.git.GitCommitDTO)1 GitController (io.hops.hopsworks.common.git.GitController)1 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)1 DuplicateSigningKeyException (io.hops.hopsworks.jwt.exception.DuplicateSigningKeyException)1 SigningKeyNotFoundException (io.hops.hopsworks.jwt.exception.SigningKeyNotFoundException)1 GitCommit (io.hops.hopsworks.persistence.entity.git.GitCommit)1 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)1 GitRepositoryRemote (io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote)1 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)1 GitCommandType (io.hops.hopsworks.persistence.entity.git.config.GitCommandType)1 GitProvider (io.hops.hopsworks.persistence.entity.git.config.GitProvider)1