Merge branch 'stable-3.1' * stable-3.1: Bump Bazel version to 3.4.1 Upgrade bazlets to latest stable-2.16 Change-Id: I0a0e57c90b81c97f7a497d18157954a0e8b85c68
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/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.