Merge branch 'stable-3.1' * stable-3.1: Upgrade JGit to 5.1.13.202002110435-r Upgrade JGit to 5.3.7.202002110540-r Change-Id: Ib3a4d9b19ae5f4088cc7ad34ff1a159139357d36
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java index 772a536..59d4e97 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java +++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
@@ -31,6 +31,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.googlesource.gerrit.plugins.lfs.auth.LfsAuthUserProvider; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.jgit.lfs.errors.LfsException; @@ -82,13 +83,14 @@ } String projName = matcher.group(1); Project.NameKey project = Project.nameKey(ProjectUtil.stripGitSuffix(projName)); - ProjectState state = projectCache.get(project); - if (state == null || state.getProject().getState() == HIDDEN) { + Optional<ProjectState> state = projectCache.get(project); + if (!state.isPresent() || state.get().getProject().getState() == HIDDEN) { throw new LfsRepositoryNotFound(project.get()); } - authorizeUser(userProvider.getUser(auth, projName, request.getOperation()), state, request); + authorizeUser( + userProvider.getUser(auth, projName, request.getOperation()), state.get(), request); - if (request.isUpload() && state.getProject().getState() == READ_ONLY) { + if (request.isUpload() && state.get().getProject().getState() == READ_ONLY) { throw new LfsRepositoryReadOnly(project.get()); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java index b8a6f14..e8d46c2 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java +++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java
@@ -35,6 +35,7 @@ import com.googlesource.gerrit.plugins.lfs.auth.LfsAuthUserProvider; import com.googlesource.gerrit.plugins.lfs.locks.LfsLocksHandler.LfsLockExistsException; import java.io.IOException; +import java.util.Optional; import org.eclipse.jgit.lfs.errors.LfsException; import org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound; import org.eclipse.jgit.lfs.errors.LfsUnauthorized; @@ -72,12 +73,12 @@ String name = getProjectName(); ProjectState project = getProject(name); CurrentUser user = getUser(name); - ProjectState state = projectCache.get(project.getNameKey()); - if (state == null) { + Optional<ProjectState> state = projectCache.get(project.getNameKey()); + if (!state.isPresent()) { throw new LfsRepositoryNotFound(project.getNameKey().get()); } try { - authorizeUser(permissionBackend.user(user).project(state.getNameKey())); + authorizeUser(permissionBackend.user(user).project(state.get().getNameKey())); } catch (AuthException | PermissionBackendException e) { throwUnauthorizedOp(getAction(), project, user); } @@ -105,11 +106,11 @@ protected ProjectState getProject(String name) throws LfsRepositoryNotFound { Project.NameKey project = Project.nameKey(ProjectUtil.stripGitSuffix(name)); - ProjectState state = projectCache.get(project); - if (state == null || state.getProject().getState() == HIDDEN) { + Optional<ProjectState> state = projectCache.get(project); + if (!state.isPresent() || state.get().getProject().getState() == HIDDEN) { throw new LfsRepositoryNotFound(project.get()); } - return state; + return state.get(); } protected CurrentUser getUser(String project) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java index a10242a..e10450c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java +++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java
@@ -15,6 +15,7 @@ package com.googlesource.gerrit.plugins.lfs.s3; import com.google.common.base.MoreObjects; +import com.google.common.base.Strings; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.googlesource.gerrit.plugins.lfs.LfsBackend; @@ -35,6 +36,7 @@ private static S3Config getS3Config(LfsGlobalConfig config, LfsBackend backendConfig) { String section = backendConfig.type.name(); + String hostname = config.getString(section, backendConfig.name, "hostname"); String region = config.getString(section, backendConfig.name, "region"); String bucket = config.getString(section, backendConfig.name, "bucket"); String storageClass = @@ -47,6 +49,12 @@ String accessKey = config.getString(section, backendConfig.name, "accessKey"); String secretKey = config.getString(section, backendConfig.name, "secretKey"); + if (!Strings.isNullOrEmpty(hostname)) { + return new S3Config( + hostname, region, bucket, storageClass, accessKey, secretKey, expirationSeconds, + disableSslVerify); + } + return new S3Config( region, bucket, storageClass, accessKey, secretKey, expirationSeconds, disableSslVerify); }
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md index 630b0d6..eaa2a5c 100644 --- a/src/main/resources/Documentation/build.md +++ b/src/main/resources/Documentation/build.md
@@ -22,13 +22,26 @@ bazel test plugins/@PLUGIN@:@PLUGIN@_tests ``` -This project can be imported into the Eclipse IDE. -Add the plugin name to the `CUSTOM_PLUGINS` set in -Gerrit core in `tools/bzl/plugins.bzl`, and execute: +This project can be imported into the Eclipse IDE in the following steps: -``` - ./tools/eclipse/project.py -``` +1. Add the plugin name to the `CUSTOM_PLUGINS` set in Gerrit core in +`tools/bzl/plugins.bzl`. + +1. Add sources for LFS related JGit libraries set in `import_jgit_sources` +method of Gerrit core `tools/eclipse/project.py`: + ``` + classpathentry('src', 'modules/jgit/org.eclipse.jgit.http.apache/src') + classpathentry('src', 'modules/jgit/org.eclipse.jgit.http.apache/resources') + classpathentry('src', 'modules/jgit/org.eclipse.jgit.lfs/src') + classpathentry('src', 'modules/jgit/org.eclipse.jgit.lfs/resources') + classpathentry('src', 'modules/jgit/org.eclipse.jgit.lfs.server/src') + classpathentry('src', 'modules/jgit/org.eclipse.jgit.lfs.server/resources') + ``` + +1. Finally execute: + ``` + ./tools/eclipse/project.py + ``` How to build the Gerrit Plugin API is described in the [Gerrit documentation](../../../Documentation/dev-bazel.html#_extension_and_plugin_api_jar_files).
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 3013f5c..383cb9b 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -154,6 +154,11 @@ The following configuration options are only used when the backend is `s3`. +s3.hostname +: Custom hostname for the S3 API server. This will allow for easier local testing +of gerrit instances with lfs storage and for the utilization of custom storage +solutions. If not specified, lfs will use AWS as the backend. + s3.region : [Amazon region](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) the S3 storage bucket is residing in.