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. Cherry picked from commit fe9218f3218f19fa0c01cc271a736e8546c69943 In 2.13 we use Java 7 and cannot use default methods to ensure we don't break any implementers. Though the fix for implementers is trivial, they just have to add an empty implementation of the new method. Change-Id: Iaafc0f844c07d823b8a7ef6377f2ede1c5805a08 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
b38e18ed3b
commit
3ffecce534
@ -42,6 +42,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.
|
||||
@ -55,4 +56,22 @@ public interface UploadValidationListener {
|
||||
String remoteHost, UploadPack up, Collection<? extends ObjectId> wants,
|
||||
Collection<? extends ObjectId> haves)
|
||||
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.
|
||||
*/
|
||||
void onBeginNegotiate(Repository repository, Project project,
|
||||
String remoteHost, UploadPack up, Collection<? extends ObjectId> wants,
|
||||
int cntOffered) throws ValidationException;
|
||||
}
|
||||
|
@ -69,6 +69,14 @@ public class UploadValidators implements PreUploadHook {
|
||||
public void onBeginNegotiateRound(UploadPack up,
|
||||
Collection<? extends ObjectId> wants, int cntOffered)
|
||||
throws ServiceMayNotContinueException {
|
||||
for (UploadValidationListener validator : uploadValidationListeners) {
|
||||
try {
|
||||
validator.onBeginNegotiate(repository, project, remoteHost, up, wants,
|
||||
cntOffered);
|
||||
} catch (ValidationException e) {
|
||||
throw new UploadValidationException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 536beda3ab4f6f8d8d8c5be1e3cf0e6b4e9b10d5
|
||||
Subproject commit e291425ca82cf8cb4bcd53b5f65e881fc04961c5
|
Loading…
x
Reference in New Issue
Block a user