Search in sources :

Example 1 with UploadPackInitializer

use of com.google.gerrit.server.git.UploadPackInitializer in project gerrit by GerritCodeReview.

the class Upload method runImpl.

@Override
protected void runImpl() throws IOException, Failure {
    PermissionBackend.ForProject perm = permissionBackend.user(user).project(projectState.getNameKey());
    try {
        perm.check(ProjectPermission.RUN_UPLOAD_PACK);
    } catch (AuthException e) {
        throw new Failure(1, "fatal: upload-pack not permitted on this server", e);
    } catch (PermissionBackendException e) {
        throw new Failure(1, "fatal: unable to check permissions ", e);
    }
    Repository permissionAwareRepo = PermissionAwareRepositoryManager.wrap(repo, perm);
    UploadPack up = new UploadPack(permissionAwareRepo);
    up.setPackConfig(config.getPackConfig());
    up.setTimeout(config.getTimeout());
    up.setPostUploadHook(PostUploadHookChain.newChain(Lists.newArrayList(postUploadHooks)));
    if (projectState.isAllUsers()) {
        up.setAdvertiseRefsHook(usersSelfAdvertiseRefsHook);
    }
    if (extraParameters != null) {
        up.setExtraParameters(ImmutableList.copyOf(extraParameters));
    }
    List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks);
    allPreUploadHooks.add(uploadValidatorsFactory.create(project, permissionAwareRepo, session.getRemoteAddressAsString()));
    up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks));
    for (UploadPackInitializer initializer : uploadPackInitializers) {
        initializer.init(projectState.getNameKey(), up);
    }
    try (TraceContext traceContext = TraceContext.open();
        TracingHook tracingHook = new TracingHook()) {
        RequestInfo requestInfo = RequestInfo.builder(RequestInfo.RequestType.GIT_UPLOAD, user, traceContext).project(projectState.getNameKey()).build();
        requestListeners.runEach(l -> l.onRequest(requestInfo));
        up.setProtocolV2Hook(tracingHook);
        up.upload(in, out, err);
        session.setPeerAgent(up.getPeerUserAgent());
        stats = up.getStatistics();
    } catch (UploadValidationException e) {
        // internal server error to the client.
        if (!e.isOutput()) {
            up.sendMessage(e.getMessage());
        }
    }
}
Also used : PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) UploadPackInitializer(com.google.gerrit.server.git.UploadPackInitializer) UploadPack(org.eclipse.jgit.transport.UploadPack) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RequestInfo(com.google.gerrit.server.RequestInfo) PreUploadHook(org.eclipse.jgit.transport.PreUploadHook) Repository(org.eclipse.jgit.lib.Repository) UploadValidationException(com.google.gerrit.server.git.validators.UploadValidationException) TracingHook(com.google.gerrit.server.git.TracingHook) TraceContext(com.google.gerrit.server.logging.TraceContext)

Aggregations

AuthException (com.google.gerrit.extensions.restapi.AuthException)1 RequestInfo (com.google.gerrit.server.RequestInfo)1 TracingHook (com.google.gerrit.server.git.TracingHook)1 UploadPackInitializer (com.google.gerrit.server.git.UploadPackInitializer)1 UploadValidationException (com.google.gerrit.server.git.validators.UploadValidationException)1 TraceContext (com.google.gerrit.server.logging.TraceContext)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 Repository (org.eclipse.jgit.lib.Repository)1 PreUploadHook (org.eclipse.jgit.transport.PreUploadHook)1 UploadPack (org.eclipse.jgit.transport.UploadPack)1