summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2017-04-25 14:45:44 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2017-05-16 12:03:56 +0200
commit3ffecce534373e6f8b1e0f06dfa034ad544230ef (patch)
tree932788eb403d1240dcdca5bbdb9180096ef322b9
parentb38e18ed3b1178d6622c18b6c146692f8600b804 (diff)
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>
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidationListener.java19
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidators.java8
m---------plugins/cookbook-plugin0
3 files changed, 27 insertions, 0 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidationListener.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidationListener.java
index e6923c145d..c86e87a10c 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidationListener.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidationListener.java
@@ -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;
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidators.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidators.java
index eb2e136924..66cc0e52a4 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidators.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/UploadValidators.java
@@ -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
diff --git a/plugins/cookbook-plugin b/plugins/cookbook-plugin
-Subproject 536beda3ab4f6f8d8d8c5be1e3cf0e6b4e9b10d
+Subproject e291425ca82cf8cb4bcd53b5f65e881fc04961c