Merge "Enhance UploadValidators to allow listening to negotation start"

This commit is contained in:
David Pursehouse 2017-04-27 09:26:47 +00:00 committed by Gerrit Code Review
commit ad1dbf4ba4
2 changed files with 34 additions and 3 deletions

View File

@ -39,6 +39,7 @@ public interface UploadValidationListener {
* @param repository The repository
* @param project The project
* @param remoteHost Remote address/hostname of the user
* @param up the UploadPack instance being processed
* @param wants The list of wanted objects. These may be RevObject or RevCommit if the processor
* parsed them. Implementors should not rely on the values being parsed.
* @param haves The list of common objects. Empty on an initial clone request. These may be
@ -47,12 +48,34 @@ public interface UploadValidationListener {
* @throws ValidationException to block the upload and send a message back to the end-user over
* the client's protocol connection.
*/
void onPreUpload(
default void onPreUpload(
Repository repository,
Project project,
String remoteHost,
UploadPack up,
Collection<? extends ObjectId> wants,
Collection<? extends ObjectId> haves)
throws ValidationException;
throws ValidationException {}
/**
* Invoked before negotiation round is started.
*
* @param repository The repository
* @param project The project
* @param remoteHost Remote address/hostname of the user
* @param up the UploadPack instance being processed
* @param wants The list of wanted objects. These may be RevObject or RevCommit if the processor
* parsed them. Implementors should not rely on the values being parsed.
* @param cntOffered number of objects the client has offered.
* @throws ValidationException to block the upload and send a message back to the end-user over
* the client's protocol connection.
*/
default void onBeginNegotiate(
Repository repository,
Project project,
String remoteHost,
UploadPack up,
Collection<? extends ObjectId> wants,
int cntOffered)
throws ValidationException {}
}

View File

@ -65,7 +65,15 @@ public class UploadValidators implements PreUploadHook {
@Override
public void onBeginNegotiateRound(
UploadPack up, Collection<? extends ObjectId> wants, int cntOffered)
throws ServiceMayNotContinueException {}
throws ServiceMayNotContinueException {
for (UploadValidationListener validator : uploadValidationListeners) {
try {
validator.onBeginNegotiate(repository, project, remoteHost, up, wants, cntOffered);
} catch (ValidationException e) {
throw new UploadValidationException(e.getMessage());
}
}
}
@Override
public void onEndNegotiateRound(