Package org.eclipse.orion.server.git

Examples of org.eclipse.orion.server.git.GitCredentialsProvider


    String srcRef = requestObject.optString(GitConstants.KEY_PUSH_SRC_REF, null);
    boolean tags = requestObject.optBoolean(GitConstants.KEY_PUSH_TAGS, false);
    boolean force = requestObject.optBoolean(GitConstants.KEY_FORCE, false);

    // prepare creds
    GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(requestObject);

    // if all went well, continue with fetch or push
    if (fetch) {
      return fetch(request, response, cp, path, force);
    } else if (srcRef != null) {
View Full Code Here


    String knownHosts = json.optString(GitConstants.KEY_KNOWN_HOSTS, null);
    byte[] privateKey = json.optString(GitConstants.KEY_PRIVATE_KEY, "").getBytes(); //$NON-NLS-1$
    byte[] publicKey = json.optString(GitConstants.KEY_PUBLIC_KEY, "").getBytes(); //$NON-NLS-1$
    byte[] passphrase = json.optString(GitConstants.KEY_PASSPHRASE, "").getBytes(); //$NON-NLS-1$

    GitCredentialsProvider cp = new GitCredentialsProvider(null /* set by caller */, username, password, knownHosts);
    cp.setPrivateKey(privateKey);
    cp.setPublicKey(publicKey);
    cp.setPassphrase(passphrase);
    return cp;
  }
View Full Code Here

      WrongRepositoryStateException {
    // make sure required fields are set
    JSONObject toAdd = OrionServlet.readJSONRequest(request);
    if (toAdd.optBoolean(GitConstants.KEY_PULL, false)) {
      GitUtils.createGitCredentialsProvider(toAdd);
      GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
      boolean force = toAdd.optBoolean(GitConstants.KEY_FORCE, false);
      return pull(request, response, cp, pathString, force);
    }

    Clone clone = new Clone();
    String url = toAdd.optString(GitConstants.KEY_URL, null);
    // method handles repository clone or just repository init
    // decision is based on existence of GitUrl argument
    boolean initOnly;
    if (url == null || url.isEmpty())
      initOnly = true;
    else {
      initOnly = false;
      if (!validateCloneUrl(url, request, response))
        return true;
      clone.setUrl(new URIish(url));
    }
    String cloneName = toAdd.optString(ProtocolConstants.KEY_NAME, null);
    if (cloneName == null)
      cloneName = request.getHeader(ProtocolConstants.HEADER_SLUG);
    // expected path /workspace/{workspaceId}
    String workspacePath = ServletResourceHandler.toOrionLocation(request, toAdd.optString(ProtocolConstants.KEY_LOCATION, null));
    // expected path /file/{workspaceId}/{projectName}[/{path}]
    String filePathString = ServletResourceHandler.toOrionLocation(request, toAdd.optString(ProtocolConstants.KEY_PATH, null));
    IPath filePath = filePathString == null ? null : new Path(filePathString);
    if (filePath != null && filePath.segmentCount() < 3)
      filePath = null;
    if (filePath == null && workspacePath == null) {
      String msg = NLS.bind("Either {0} or {1} should be provided: {2}",
          new Object[] { ProtocolConstants.KEY_PATH, ProtocolConstants.KEY_LOCATION, toAdd });
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    // only during init operation filePath or cloneName must be provided
    // during clone operation, name can be obtained from URL
    if (initOnly && filePath == null && cloneName == null) {
      String msg = NLS.bind("Either {0} or {1} should be provided: {2}", new Object[] { ProtocolConstants.KEY_PATH, GitConstants.KEY_NAME, toAdd });
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    if (!validateCloneName(cloneName, request, response))
      return true;

    // prepare the WebClone object, create a new project if necessary
    ProjectInfo project = null;
    boolean webProjectExists = false;
    if (filePath != null) {
      // path format is /file/{workspaceId}/{projectName}/[filePath]
      clone.setId(filePath.toString());
      project = GitUtils.projectFromPath(filePath);
      // workspace path format needs to be used if project does not exist
      if (project == null) {
        String msg = NLS.bind("Specified project does not exist: {0}", filePath.segment(2));
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
      }
      webProjectExists = true;
      clone.setContentLocation(project.getProjectStore().getFileStore(filePath.removeFirstSegments(3)).toURI());
      if (cloneName == null)
        cloneName = filePath.segmentCount() > 2 ? filePath.lastSegment() : project.getFullName();
    } else if (workspacePath != null) {
      IPath path = new Path(workspacePath);
      // TODO: move this to CloneJob
      // if so, modify init part to create a new project if necessary
      final IMetaStore metaStore = OrionConfiguration.getMetaStore();
      WorkspaceInfo workspace = metaStore.readWorkspace(path.segment(1));
      if (cloneName == null)
        cloneName = new URIish(url).getHumanishName();
      cloneName = getUniqueProjectName(workspace, cloneName);
      webProjectExists = false;
      project = new ProjectInfo();
      project.setFullName(cloneName);
      project.setWorkspaceId(workspace.getUniqueId());

      try {
        // creating project in the backing store will assign a project id
        metaStore.createProject(project);
      } catch (CoreException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Error persisting project state", e));
      }
      try {
        WorkspaceResourceHandler.computeProjectLocation(request, project, null, false);
        metaStore.updateProject(project);
      } catch (CoreException e) {
        // delete the project so we don't end up with a project in a bad location
        try {
          metaStore.deleteProject(workspace.getUniqueId(), project.getFullName());
        } catch (CoreException e1) {
          // swallow secondary error
          LogHelper.log(e1);
        }
        // we are unable to write in the platform location!
        String msg = NLS.bind("Failed to create project: {0}", project.getFullName());
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
      }

      URI baseLocation = getURI(request);
      baseLocation = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), workspacePath,
          baseLocation.getQuery(), baseLocation.getFragment());
      clone.setId(GitUtils.pathFromProject(workspace, project).toString());
      clone.setContentLocation(project.getProjectStore().toURI());
    }
    clone.setName(cloneName);
    clone.setBaseLocation(getURI(request));
    JSONObject cloneObject = clone.toJSON();
    String cloneLocation = cloneObject.getString(ProtocolConstants.KEY_LOCATION);

    String gitUserName = toAdd.optString(GitConstants.KEY_NAME, null);
    String gitUserMail = toAdd.optString(GitConstants.KEY_MAIL, null);
    Boolean initProject = toAdd.optBoolean(GitConstants.KEY_INIT_PROJECT, false);
    if (initOnly) {
      // git init
      InitJob job = new InitJob(clone, TaskJobHandler.getUserId(request), request.getRemoteUser(), cloneLocation, gitUserName, gitUserMail);
      return TaskJobHandler.handleTaskJob(request, response, job, statusHandler, JsonURIUnqualificationStrategy.ALL_NO_GIT);
    }
    // git clone
    // prepare creds
    GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
    cp.setUri(new URIish(clone.getUrl()));

    // if all went well, clone
    // check for SSO token
    Object cookie = request.getAttribute(GitConstants.KEY_SSO_TOKEN);
    CloneJob job = new CloneJob(clone, TaskJobHandler.getUserId(request), cp, request.getRemoteUser(), cloneLocation,
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.git.GitCredentialsProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.