Expose implicit dependency with the multi-site plugin The multi-site pugin needs to know what are the API endpoints exposed by the pull-replication, therefore expose the suffixes as constants and annotate the implicit dependency. Bug: Issue 16934 Change-Id: I8ebec4eedebbc316804db36962cd425c647188b7
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationEndpoints.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationEndpoints.java new file mode 100644 index 0000000..fc97945 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationEndpoints.java
@@ -0,0 +1,39 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.googlesource.gerrit.plugins.replication.pull.api; + +import static com.google.gerrit.common.UsedAt.Project.PLUGIN_MULTI_SITE; + +import com.google.gerrit.common.UsedAt; + +/** + * Temporary solution for stable branches for allowing the multi-site plugin to understand his + * caller identity. + * + * <p>TODO: To be removed from v3.9/master, where this problem does not exist anymore because of a + * clearer definition of responsibilities between the multi-site and the pull-replication plugins. + */ +public interface PullReplicationEndpoints { + + @UsedAt(PLUGIN_MULTI_SITE) + public static final String APPLY_OBJECT_API_ENDPOINT = "apply-object"; + + @UsedAt(PLUGIN_MULTI_SITE) + public static final String APPLY_OBJECTS_API_ENDPOINT = "apply-objects"; + + public static final String FETCH_ENDPOINT = "fetch"; + public static final String INIT_PROJECT_ENDPOINT = "init-project"; + public static final String DELETE_PROJECT_ENDPOINT = "delete-project"; +}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java index 20122a7..d18ebc0 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
@@ -69,7 +69,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -public class PullReplicationFilter extends AllRequestFilter { +public class PullReplicationFilter extends AllRequestFilter implements PullReplicationEndpoints { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final Pattern projectNameInGerritUrl = Pattern.compile(".*/projects/([^/]+)/.*"); @@ -299,19 +299,25 @@ } private boolean isApplyObjectAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().endsWith(String.format("/%s~apply-object", pluginName)); + return httpRequest + .getRequestURI() + .endsWith(String.format("/%s~" + APPLY_OBJECT_API_ENDPOINT, pluginName)); } private boolean isApplyObjectsAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().endsWith(String.format("/%s~apply-objects", pluginName)); + return httpRequest + .getRequestURI() + .endsWith(String.format("/%s~" + APPLY_OBJECTS_API_ENDPOINT, pluginName)); } private boolean isFetchAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().endsWith(String.format("/%s~fetch", pluginName)); + return httpRequest.getRequestURI().endsWith(String.format("/%s~" + FETCH_ENDPOINT, pluginName)); } private boolean isInitProjectAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().contains(String.format("/%s/init-project/", pluginName)); + return httpRequest + .getRequestURI() + .contains(String.format("/%s/" + INIT_PROJECT_ENDPOINT + "/", pluginName)); } private boolean isUpdateHEADAction(HttpServletRequest httpRequest) { @@ -320,7 +326,9 @@ } private boolean isDeleteProjectAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().endsWith(String.format("/%s~delete-project", pluginName)) + return httpRequest + .getRequestURI() + .endsWith(String.format("/%s~" + DELETE_PROJECT_ENDPOINT, pluginName)) && "DELETE".equals(httpRequest.getMethod()); } }