Line data Source code
1 : // Copyright (C) 2014 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.git.validators; 16 : 17 : import com.google.gerrit.entities.Project; 18 : import com.google.gerrit.extensions.annotations.ExtensionPoint; 19 : import com.google.gerrit.server.validators.ValidationException; 20 : import java.util.Collection; 21 : import org.eclipse.jgit.lib.ObjectId; 22 : import org.eclipse.jgit.lib.Repository; 23 : import org.eclipse.jgit.transport.UploadPack; 24 : 25 : /** 26 : * Listener to provide validation for upload operations. 27 : * 28 : * <p>Invoked by Gerrit before it begins to send a pack to the client. 29 : * 30 : * <p>Implementors can block the upload operation by throwing a ValidationException. The exception's 31 : * message text will be reported to the end-user over the client's protocol connection. 32 : */ 33 : @ExtensionPoint 34 : public interface UploadValidationListener { 35 : 36 : /** 37 : * Validate an upload before it begins. 38 : * 39 : * @param repository The repository 40 : * @param project The project 41 : * @param remoteHost Remote address/hostname of the user 42 : * @param up the UploadPack instance being processed. 43 : * @param wants The list of wanted objects. These may be RevObject or RevCommit if the processor 44 : * parsed them. Implementors should not rely on the values being parsed. 45 : * @param haves The list of common objects. Empty on an initial clone request. These may be 46 : * RevObject or RevCommit if the processor parsed them. Implementors should not rely on the 47 : * values being parsed. 48 : * @throws ValidationException to block the upload and send a message back to the end-user over 49 : * the client's protocol connection. 50 : */ 51 : default void onPreUpload( 52 : Repository repository, 53 : Project project, 54 : String remoteHost, 55 : UploadPack up, 56 : Collection<? extends ObjectId> wants, 57 : Collection<? extends ObjectId> haves) 58 0 : throws ValidationException {} 59 : 60 : /** 61 : * Invoked before negotiation round is started. 62 : * 63 : * @param repository The repository 64 : * @param project The project 65 : * @param remoteHost Remote address/hostname of the user 66 : * @param up the UploadPack instance being processed 67 : * @param wants The list of wanted objects. These may be RevObject or RevCommit if the processor 68 : * parsed them. Implementors should not rely on the values being parsed. 69 : * @param cntOffered number of objects the client has offered. 70 : * @throws ValidationException to block the upload and send a message back to the end-user over 71 : * the client's protocol connection. 72 : */ 73 : default void onBeginNegotiate( 74 : Repository repository, 75 : Project project, 76 : String remoteHost, 77 : UploadPack up, 78 : Collection<? extends ObjectId> wants, 79 : int cntOffered) 80 0 : throws ValidationException {} 81 : }