List of usage examples for org.eclipse.jgit.transport UploadPack UploadPack
public UploadPack(Repository copyFrom)
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepositorySSHAccess.java
License:Open Source License
@Override public UploadPack createUploadPack(String fullRepositoryName) throws IOException, InterruptedException { if (isMine(fullRepositoryName)) return new UploadPack(repo.openRepository()); return null;//from ww w .j av a 2 s . c o m }
From source file:com.gitblit.git.GitblitUploadPackFactory.java
License:Apache License
@Override public UploadPack create(X req, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { int timeout = 0; if (req instanceof GitDaemonClient) { // git daemon request is always anonymous GitDaemonClient client = (GitDaemonClient) req; // set timeout from Git daemon timeout = client.getDaemon().getTimeout(); }//from w w w . ja v a 2 s . c o m UploadPack up = new UploadPack(db); up.setTimeout(timeout); return up; }
From source file:com.google.gerrit.sshd.commands.Upload.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { if (!projectControl.canRunUploadPack()) { throw new Failure(1, "fatal: upload-pack not permitted on this server"); }//from ww w . j av a 2s . com final UploadPack up = new UploadPack(repo); if (!projectControl.allRefsAreVisible()) { up.setAdvertiseRefsHook( new VisibleRefFilter(tagCache, changeCache, repo, projectControl, db.get(), true)); } up.setPackConfig(config.getPackConfig()); up.setTimeout(config.getTimeout()); List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks); allPreUploadHooks.add(uploadValidatorsFactory.create(project, repo, session.getRemoteAddressAsString())); up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks)); try { up.upload(in, out, err); } catch (UploadValidationException e) { // UploadValidationException is used by the UploadValidators to // stop the uploadPack. We do not want this exception to go beyond this // point otherwise it would print a stacktrace in the logs and return an // internal server error to the client. if (!e.isOutput()) { up.sendMessage(e.getMessage()); } } }
From source file:com.sonatype.sshjgit.core.gitcommand.Upload.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { SecurityUtils.getSubject().checkPermission("gitrepo:fetch:" + getRepoNameAsPermissionParts(repo)); UploadPack up = new UploadPack(repo); up.upload(in, out, err);/*from ww w . j av a 2 s . c om*/ }
From source file:com.tasktop.c2c.server.scm.web.GitHandler.java
License:Open Source License
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final boolean containerSupportsChunkedIO = computeContainerSupportsChunkedIO(); String pathInfo = request.getPathInfo(); log.info("Git request: " + request.getMethod() + " " + request.getRequestURI() + " " + pathInfo); Repository repository = null;//from w w w . j ava 2 s.c om try { // only work on Git requests Matcher matcher = pathInfo == null ? null : GIT_COMMAND_PATTERN.matcher(pathInfo); if (matcher == null || !matcher.matches()) { log.info("Unexpected path: " + pathInfo); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } String requestCommand = matcher.group(1); String requestPath = matcher.group(2); // sanity check on path, disallow path separator components if (requestPath == null || requestPath.contains("/") || requestPath.contains("..")) { badPathResponse(); } repository = repositoryResolver.open(request, requestPath); InputStream requestInput = request.getInputStream(); if (!containerSupportsChunkedIO) { requestInput = new ChunkedInputStream(requestInput); } MultiplexingOutputStream mox = createMultiplexingOutputStream(response, containerSupportsChunkedIO); // indicate that we're ok to handle the request // note that following this there will be a two-way communication with the process // that might still encounter errors. That's ok. startOkResponse(response, containerSupportsChunkedIO); // identify the git command GitCommand command = GitCommand.fromCommandName(requestCommand); if (command != null) { // permissions check if (!Security.hasOneOfRoles(command.getRoles())) { log.info("Access denied to " + Security.getCurrentUser() + " for " + command.getCommandName() + " on " + TenancyUtil.getCurrentTenantProjectIdentifer() + " " + requestPath); response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } switch (command) { case RECEIVE_PACK: ReceivePack rp = new ReceivePack(repository); rp.setPostReceiveHook(postReceiveHook); rp.receive(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; case UPLOAD_PACK: UploadPack up = new UploadPack(repository); up.upload(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR)); break; default: response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } // at this stage we're done with IO // send the exit value and closing chunk try { int exitValue = 0; if (exitValue != 0) { log.info("Exit value: " + exitValue); } mox.writeExitCode(exitValue); mox.close(); } catch (IOException e) { // ignore log.debug("Cannot complete writing exit state", e); } // clear interrupt status Thread.interrupted(); } catch (ErrorResponseException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotAuthorizedException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } catch (ServiceNotEnabledException e) { createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage()); } finally { log.info("Git request complete"); if (repository != null) { repository.close(); } } }
From source file:net.antoniy.gidder.beta.ssh.Upload.java
License:Apache License
@Override protected void runImpl() throws IOException { if (!hasPermission()) { err.write(MSG_REPOSITORY_PERMISSIONS.getBytes()); err.flush();//w w w . j a v a 2 s . c om onExit(CODE_OK, MSG_REPOSITORY_PERMISSIONS); return; } Config config = new Config(); // int timeout = Integer.parseInt(config.getString("transfer", null, // "timeout")); int timeout = 10; PackConfig packConfig = new PackConfig(); packConfig.setDeltaCompress(false); packConfig.setThreads(1); packConfig.fromConfig(config); final UploadPack up = new UploadPack(repo); up.setPackConfig(packConfig); up.setTimeout(timeout); up.upload(in, out, err); }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendUploadPackFactory.java
License:Apache License
@Override public UploadPack create(final C request, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { final File dir = db.getDirectory(); final String logPrefix; if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) request; logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"; } else {/* w ww. j a v a 2 s . co m*/ logPrefix = "create(" + dir.getAbsolutePath() + ")"; } if (logger.isDebugEnabled()) { logger.debug(logPrefix + ": " + dir.getAbsolutePath()); } UploadPack up = new UploadPack(db) { @Override @SuppressWarnings("synthetic-access") public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException { InputStream effIn = input; OutputStream effOut = output, effMessages = messages; if (logger.isTraceEnabled()) { LineLevelAppender inputAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(C): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true); LineLevelAppender outputAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(S): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender)); if (effMessages != null) { LineLevelAppender messagesAppender = new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " upload(M): " + lineData); } @Override public boolean isWriteEnabled() { return true; } }; // TODO review the decision to use an AsciiLineOutputStream here effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender)); } } super.upload(effIn, effOut, effMessages); } @Override @SuppressWarnings("synthetic-access") public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException { RefAdvertiser effAdv = adv; if (logger.isTraceEnabled() && (adv instanceof PacketLineOutRefAdvertiser)) { PacketLineOut pckOut = (PacketLineOut) ReflectionUtils.getField(pckOutField, adv); effAdv = new PacketLineOutRefAdvertiser(pckOut) { private final PacketLineOut pckLog = new PacketLineOut( // TODO review the decision to use an AsciiLineOutputStream here new AsciiLineOutputStream(new LineLevelAppender() { @Override public void writeLineData(CharSequence lineData) throws IOException { logger.trace(logPrefix + " S: " + lineData); } @Override public boolean isWriteEnabled() { return true; } })); @Override protected void writeOne(CharSequence line) throws IOException { String s = line.toString(); super.writeOne(s); pckLog.writeString(s); } @Override protected void end() throws IOException { super.end(); pckLog.end(); } }; } super.sendAdvertisedRefs(effAdv); } }; up.setTimeout(uploadTimeoutValue); return up; }
From source file:org.apache.sshd.git.pack.GitPackCommand.java
License:Apache License
@Override public void run() { try {//w ww .ja va2 s . c om List<String> strs = parseDelimitedString(command, " ", true); String[] args = strs.toArray(new String[strs.size()]); for (int i = 0; i < args.length; i++) { if (args[i].startsWith("'") && args[i].endsWith("'")) { args[i] = args[i].substring(1, args[i].length() - 1); } if (args[i].startsWith("\"") && args[i].endsWith("\"")) { args[i] = args[i].substring(1, args[i].length() - 1); } } if (args.length != 2) { throw new IllegalArgumentException("Invalid git command line: " + command); } File srcGitdir = new File(rootDir, args[1]); RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(srcGitdir, FS.DETECTED); Repository db = key.open(true /* must exist */); if ("git-upload-pack".equals(args[0])) { new UploadPack(db).upload(in, out, err); } else if ("git-receive-pack".equals(args[0])) { new ReceivePack(db).receive(in, out, err); } else { throw new IllegalArgumentException("Unknown git command: " + command); } } catch (Throwable t) { t.printStackTrace(); } if (callback != null) { callback.onExit(0); } }
From source file:org.webcat.core.git.http.UploadPackRequestHandler.java
License:Open Source License
/** * Handles the request and generates the UploadPack response. * * @param request the request//from ww w .j a v a2s. c om * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE); if (UPLOAD_PACK_REQUEST_TYPE.equals(contentType)) { Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); UploadPack up = new UploadPack(repo); up.setBiDirectionalPipe(false); response.setHeader(UPLOAD_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE); InputStream input = RequestUtils.inputStreamForRequest(request); SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response); up.upload(input, output, null); output.close(); } else { response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE); } }
From source file:playRepository.RepositoryService.java
License:Apache License
/** * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/git-upload-pack.html">git-upload-pack</a> * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/git-receive-pack.html">git-receive-pack</a> *///from w w w . j a v a 2s . c om public static byte[] gitAdvertise(Project project, String service, Response response) throws IOException { response.setContentType("application/x-" + service + "-advertisement"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PacketLineOut packetLineOut = new PacketLineOut(byteArrayOutputStream); packetLineOut.writeString("# service=" + service + "\n"); packetLineOut.end(); PacketLineOutRefAdvertiser packetLineOutRefAdvertiser = new PacketLineOutRefAdvertiser(packetLineOut); if (service.equals("git-upload-pack")) { Repository repository = GitRepository.buildGitRepository(project); UploadPack uploadPack = new UploadPack(repository); uploadPack.setBiDirectionalPipe(false); uploadPack.sendAdvertisedRefs(packetLineOutRefAdvertiser); } else if (service.equals("git-receive-pack")) { Repository repository = GitRepository.buildGitRepository(project, false); ReceivePack receivePack = new ReceivePack(repository); receivePack.sendAdvertisedRefs(packetLineOutRefAdvertiser); } byteArrayOutputStream.close(); return byteArrayOutputStream.toByteArray(); }