Esempio n. 1
0
 /**
  * Executes remote command.
  *
  * <p>Note: <i>'need for authorization'</i> check based on command execution fail message, so this
  * check can fail when i.e. git version updated, for more information see {@link
  * #isOperationNeedAuth(String)}
  *
  * @param command remote command which should be executed
  * @throws GitException when error occurs while {@code command} execution is going except of
  *     unauthorized error
  * @throws UnauthorizedException when it is not possible to execute {@code command} with existing
  *     credentials
  */
 private void executeRemoteCommand(RemoteOperationCommand<?> command)
     throws GitException, UnauthorizedException {
   try {
     command.execute();
   } catch (GitException gitEx) {
     if (!isOperationNeedAuth(gitEx.getMessage())) {
       throw gitEx;
     }
     ProviderInfo info = credentialsLoader.getProviderInfo(command.getRemoteUri());
     if (info != null) {
       boolean isAuthenticated =
           credentialsLoader.getUserCredential(command.getRemoteUri()) != null;
       throw new UnauthorizedException(
           gitEx.getMessage(),
           ErrorCodes.UNAUTHORIZED_GIT_OPERATION,
           ImmutableMap.of(
               PROVIDER_NAME,
               info.getProviderName(),
               AUTHENTICATE_URL,
               info.getAuthenticateUrl(),
               "authenticated",
               Boolean.toString(isAuthenticated)));
     }
     throw new UnauthorizedException(gitEx.getMessage(), ErrorCodes.UNAUTHORIZED_GIT_OPERATION);
   }
 }
  private GitUser getLocalCommitter() throws GitException {
    String credentialsProvider = "che";
    try {
      credentialsProvider = getConfig().get("codenvy.credentialsProvider");
    } catch (GitException e) {
      // ignore property not found.
    }

    return credentialsLoader.getUser(credentialsProvider);
  }
Esempio n. 3
0
  @Override
  public void clone(CloneRequest request)
      throws URISyntaxException, UnauthorizedException, GitException {
    final String remoteUri = request.getRemoteUri();
    CloneCommand clone = nativeGit.createCloneCommand();
    clone.setRemoteUri(remoteUri);
    clone.setRemoteName(request.getRemoteName());
    if (clone.getTimeout() > 0) {
      clone.setTimeout(request.getTimeout());
    }

    executeRemoteCommand(clone);

    UserCredential credentials = credentialsLoader.getUserCredential(remoteUri);
    if (credentials != null) {
      getConfig().set("codenvy.credentialsProvider", credentials.getProviderId());
    }
    nativeGit
        .createRemoteUpdateCommand()
        .setRemoteName(request.getRemoteName() == null ? "origin" : request.getRemoteName())
        .setNewUrl(remoteUri)
        .execute();
  }