Enhance UploadValidators to allow listening to negotation start
This will be used to check rate limits for fetch requests. Rate limits should be checked before git transport negotation starts to avoid unnecessary work in case the limit is already reached. Change-Id: Ida81c6b3cec86fe86440497817937cf5533e7a19 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
@@ -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 {}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user