Format all Java files with google-java-format
Change-Id: Ib75f20d3098cf7f628af36ddfc7fbe4dfe8d9c42
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/ExpiringAction.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/ExpiringAction.java
index 48bf7d7..7d43d04 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/ExpiringAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/ExpiringAction.java
@@ -16,9 +16,8 @@
import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
-import org.eclipse.jgit.lfs.server.Response;
-
import java.util.Collections;
+import org.eclipse.jgit.lfs.server.Response;
public class ExpiringAction extends Response.Action {
public final String expiresAt;
@@ -28,4 +27,4 @@
this.header = Collections.singletonMap(HDR_AUTHORIZATION, info.authToken);
this.expiresAt = info.expiresAt;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/GetLfsGlobalConfig.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/GetLfsGlobalConfig.java
index c8e3d69..dcdcbac 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/GetLfsGlobalConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/GetLfsGlobalConfig.java
@@ -25,7 +25,6 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import java.util.HashMap;
import java.util.List;
@@ -36,7 +35,8 @@
private final Provider<CurrentUser> self;
@Inject
- GetLfsGlobalConfig(LfsConfigurationFactory lfsConfigFactory,
+ GetLfsGlobalConfig(
+ LfsConfigurationFactory lfsConfigFactory,
AllProjectsName allProjectsName,
Provider<CurrentUser> self) {
this.lfsConfigFactory = lfsConfigFactory;
@@ -55,8 +55,7 @@
LfsGlobalConfigInfo info = new LfsGlobalConfigInfo();
LfsGlobalConfig globalConfig = lfsConfigFactory.getGlobalConfig();
info.defaultBackendType = globalConfig.getDefaultBackend().type;
- info.backends = Maps.transformValues(globalConfig.getBackends(),
- b -> b.type);
+ info.backends = Maps.transformValues(globalConfig.getBackends(), b -> b.type);
List<LfsProjectConfigSection> configSections =
lfsConfigFactory.getProjectsConfig().getConfigSections();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
index 5309b4b..ee789f8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
@@ -21,11 +21,9 @@
import com.google.gerrit.extensions.webui.WebUiPlugin;
import com.google.gerrit.httpd.plugins.HttpPluginModule;
import com.google.inject.Inject;
-
import com.googlesource.gerrit.plugins.lfs.fs.LfsFsContentServlet;
import com.googlesource.gerrit.plugins.lfs.fs.LocalLargeFileRepository;
import com.googlesource.gerrit.plugins.lfs.s3.S3LargeFileRepository;
-
import java.util.Map;
public class HttpModule extends HttpPluginModule {
@@ -37,7 +35,8 @@
private final Map<String, LfsBackend> backends;
@Inject
- HttpModule(LocalLargeFileRepository.Factory fsRepoFactory,
+ HttpModule(
+ LocalLargeFileRepository.Factory fsRepoFactory,
S3LargeFileRepository.Factory s3RepoFactory,
LfsRepositoriesCache cache,
LfsFsContentServlet.Factory fsServletFactory,
@@ -61,7 +60,7 @@
}
DynamicSet.bind(binder(), WebUiPlugin.class)
- .toInstance(new JavaScriptPlugin("lfs-project-info.js"));
+ .toInstance(new JavaScriptPlugin("lfs-project-info.js"));
}
private void populateRepository(LfsBackend backend) {
@@ -81,16 +80,13 @@
}
private void populateS3Repository(LfsBackend backend) {
- S3LargeFileRepository repository =
- s3RepoFactory.create(backend);
+ S3LargeFileRepository repository = s3RepoFactory.create(backend);
cache.put(backend, repository);
}
private void populateAndServeFsRepository(LfsBackend backend) {
- LocalLargeFileRepository repository =
- fsRepoFactory.create(backend);
+ LocalLargeFileRepository repository = fsRepoFactory.create(backend);
cache.put(backend, repository);
- serve(repository.getServletUrlPattern())
- .with(fsServletFactory.create(repository));
+ serve(repository.getServletUrlPattern()).with(fsServletFactory.create(repository));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/InitLfs.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/InitLfs.java
index b6cddfa..89e6238 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/InitLfs.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/InitLfs.java
@@ -38,6 +38,5 @@
}
@Override
- public void postRun() throws Exception {
- }
+ public void postRun() throws Exception {}
}
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 96c4e32..d6b168c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
@@ -28,7 +28,8 @@
import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.jgit.lfs.errors.LfsException;
import org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound;
import org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly;
@@ -41,9 +42,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
@Singleton
public class LfsApiServlet extends LfsProtocolServlet {
private static final Logger log = LoggerFactory.getLogger(LfsApiServlet.class);
@@ -59,7 +57,8 @@
private final LfsAuthUserProvider userProvider;
@Inject
- LfsApiServlet(ProjectCache projectCache,
+ LfsApiServlet(
+ ProjectCache projectCache,
LfsConfigurationFactory lfsConfigFactory,
LfsRepositoryResolver repoResolver,
LfsAuthUserProvider userProvider) {
@@ -70,31 +69,29 @@
}
@Override
- protected LargeFileRepository getLargeFileRepository(
- LfsRequest request, String path, String auth)
- throws LfsException {
+ protected LargeFileRepository getLargeFileRepository(LfsRequest request, String path, String auth)
+ throws LfsException {
String pathInfo = path.startsWith("/") ? path : "/" + path;
Matcher matcher = URL_PATTERN.matcher(pathInfo);
if (!matcher.matches()) {
throw new LfsException("no repository at " + pathInfo);
}
String projName = matcher.group(1);
- Project.NameKey project = Project.NameKey.parse(
- ProjectUtil.stripGitSuffix(projName));
+ Project.NameKey project = Project.NameKey.parse(ProjectUtil.stripGitSuffix(projName));
ProjectState state = projectCache.get(project);
if (state == null || state.getProject().getState() == HIDDEN) {
throw new LfsRepositoryNotFound(project.get());
}
- authorizeUser(userProvider.getUser(auth, projName, request.getOperation()),
- state, request.getOperation());
+ authorizeUser(
+ userProvider.getUser(auth, projName, request.getOperation()),
+ state,
+ request.getOperation());
- if (request.getOperation().equals(UPLOAD)
- && state.getProject().getState() == READ_ONLY) {
+ if (request.getOperation().equals(UPLOAD) && state.getProject().getState() == READ_ONLY) {
throw new LfsRepositoryReadOnly(project.get());
}
- LfsProjectConfigSection config =
- lfsConfigFactory.getProjectsConfig().getForProject(project);
+ LfsProjectConfigSection config = lfsConfigFactory.getProjectsConfig().getForProject(project);
// Only accept requests for projects where LFS is enabled.
// No config means we default to "not enabled".
if (config != null && config.isEnabled()) {
@@ -108,9 +105,10 @@
if (maxObjectSize > 0) {
for (LfsObject object : request.getObjects()) {
if (object.getSize() > maxObjectSize) {
- throw new LfsValidationError(String.format(
- "size of object %s (%d bytes) exceeds limit (%d bytes)",
- object.getOid(), object.getSize(), maxObjectSize));
+ throw new LfsValidationError(
+ String.format(
+ "size of object %s (%d bytes) exceeds limit (%d bytes)",
+ object.getOid(), object.getSize(), maxObjectSize));
}
}
}
@@ -122,19 +120,18 @@
throw new LfsUnavailable(project.get());
}
- private void authorizeUser(CurrentUser user, ProjectState state,
- String operation) throws LfsUnauthorized {
+ private void authorizeUser(CurrentUser user, ProjectState state, String operation)
+ throws LfsUnauthorized {
ProjectControl control = state.controlFor(user);
- if ((operation.equals(DOWNLOAD) && !control.isReadable()) ||
- (operation.equals(UPLOAD) && Capable.OK != control.canPushToAtLeastOneRef())) {
+ if ((operation.equals(DOWNLOAD) && !control.isReadable())
+ || (operation.equals(UPLOAD) && Capable.OK != control.canPushToAtLeastOneRef())) {
String op = operation.toLowerCase();
String project = state.getProject().getName();
- String userName = Strings.isNullOrEmpty(user.getUserName())
- ? "anonymous"
- : user.getUserName();
- log.debug(String.format(
- "operation %s unauthorized for user %s on project %s",
- op, userName, project));
+ String userName =
+ Strings.isNullOrEmpty(user.getUserName()) ? "anonymous" : user.getUserName();
+ log.debug(
+ String.format(
+ "operation %s unauthorized for user %s on project %s", op, userName, project));
throw new LfsUnauthorized(op, project);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthToken.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthToken.java
index 1ab35c4..a51472d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthToken.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthToken.java
@@ -17,16 +17,14 @@
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
-
+import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
-import java.util.List;
-
public abstract class LfsAuthToken {
- public static abstract class Processor<T extends LfsAuthToken> {
+ public abstract static class Processor<T extends LfsAuthToken> {
private static final char DELIMETER = '~';
protected final LfsCipher cipher;
@@ -49,10 +47,11 @@
}
protected abstract List<String> getValues(T token);
+
protected abstract Optional<T> createToken(List<String> values);
}
- public static abstract class Verifier<T extends LfsAuthToken> {
+ public abstract static class Verifier<T extends LfsAuthToken> {
protected final T token;
protected Verifier(T token) {
@@ -60,8 +59,7 @@
}
public boolean verify() {
- return onTime(token.expiresAt)
- && verifyTokenValues();
+ return onTime(token.expiresAt) && verifyTokenValues();
}
protected abstract boolean verifyTokenValues();
@@ -90,4 +88,4 @@
static DateTime now() {
return DateTime.now().toDateTime(DateTimeZone.UTC);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthUserProvider.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthUserProvider.java
index efac3af..aa39abb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthUserProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsAuthUserProvider.java
@@ -38,7 +38,8 @@
private final IdentifiedUser.GenericFactory userFactory;
@Inject
- LfsAuthUserProvider(Provider<AnonymousUser> anonymous,
+ LfsAuthUserProvider(
+ Provider<AnonymousUser> anonymous,
Provider<CurrentUser> user,
LfsSshRequestAuthorizer sshAuth,
AccountCache accounts,
@@ -57,8 +58,9 @@
}
if (auth.startsWith(SSH_AUTH_PREFIX)) {
- Optional<String> user = sshAuth.getUserFromValidToken(
- auth.substring(SSH_AUTH_PREFIX.length()), project, operation);
+ Optional<String> user =
+ sshAuth.getUserFromValidToken(
+ auth.substring(SSH_AUTH_PREFIX.length()), project, operation);
if (user.isPresent()) {
AccountState acc = accounts.getByUsername(user.get());
if (acc != null) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsBackend.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsBackend.java
index 48a833e..a2fbfe2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsBackend.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsBackend.java
@@ -15,7 +15,6 @@
package com.googlesource.gerrit.plugins.lfs;
import com.google.common.base.Strings;
-
import java.util.Objects;
public class LfsBackend {
@@ -38,8 +37,7 @@
public boolean equals(Object obj) {
if (obj instanceof LfsBackend) {
LfsBackend other = (LfsBackend) obj;
- return Objects.equals(name, other.name)
- && type == other.type;
+ return Objects.equals(name, other.name) && type == other.type;
}
return false;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsCipher.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsCipher.java
index 25238da..94bf054 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsCipher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsCipher.java
@@ -20,26 +20,22 @@
import com.google.common.base.Strings;
import com.google.common.primitives.Bytes;
import com.google.inject.Singleton;
-
-import org.eclipse.jgit.util.Base64;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
-
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
+import org.eclipse.jgit.util.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Singleton
public class LfsCipher {
- private static final Logger log =
- LoggerFactory.getLogger(LfsCipher.class);
+ private static final Logger log = LoggerFactory.getLogger(LfsCipher.class);
private static final int IV_LENGTH = 16;
private static final String ALGORITHM = "AES";
private static final String CIPHER_TYPE = ALGORITHM + "/CBC/PKCS5PADDING";
@@ -58,8 +54,7 @@
byte[] initVector = new byte[IV_LENGTH];
random.nextBytes(initVector);
Cipher cipher = cipher(initVector, Cipher.ENCRYPT_MODE);
- return Base64.encodeBytes(
- Bytes.concat(initVector, cipher.doFinal(input.getBytes(UTF_8))));
+ return Base64.encodeBytes(Bytes.concat(initVector, cipher.doFinal(input.getBytes(UTF_8))));
} catch (GeneralSecurityException e) {
log.error("Token generation failed with error", e);
throw new RuntimeException(e);
@@ -75,9 +70,8 @@
byte[] initVector = Arrays.copyOf(bytes, IV_LENGTH);
try {
Cipher cipher = cipher(initVector, Cipher.DECRYPT_MODE);
- return Optional.of(new String(
- cipher.doFinal(Arrays.copyOfRange(bytes, IV_LENGTH, bytes.length)),
- UTF_8));
+ return Optional.of(
+ new String(cipher.doFinal(Arrays.copyOfRange(bytes, IV_LENGTH, bytes.length)), UTF_8));
} catch (GeneralSecurityException e) {
log.error("Exception was thrown during token verification", e);
}
@@ -85,8 +79,7 @@
return Optional.absent();
}
- private Cipher cipher(byte[] initVector, int mode)
- throws GeneralSecurityException {
+ private Cipher cipher(byte[] initVector, int mode) throws GeneralSecurityException {
IvParameterSpec spec = new IvParameterSpec(initVector);
AlgorithmParameters params = AlgorithmParameters.getInstance(ALGORITHM);
params.init(spec);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsConfigurationFactory.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsConfigurationFactory.java
index 165568e..400c30a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsConfigurationFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsConfigurationFactory.java
@@ -29,7 +29,8 @@
private final PluginConfigFactory configFactory;
@Inject
- LfsConfigurationFactory(@PluginName String pluginName,
+ LfsConfigurationFactory(
+ @PluginName String pluginName,
ProjectCache projectCache,
AllProjectsName allProjects,
PluginConfigFactory configFactory) {
@@ -39,16 +40,12 @@
this.configFactory = configFactory;
}
- /**
- * @return the project-specific LFS configuration.
- */
+ /** @return the project-specific LFS configuration. */
public LfsProjectsConfig getProjectsConfig() {
return new LfsProjectsConfig(pluginName, projectCache, allProjects);
}
- /**
- * @return the global LFS configuration.
- */
+ /** @return the global LFS configuration. */
public LfsGlobalConfig getGlobalConfig() {
return new LfsGlobalConfig(configFactory.getGlobalPluginConfig(pluginName));
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsGlobalConfig.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsGlobalConfig.java
index 994da0d..6283c9e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsGlobalConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsGlobalConfig.java
@@ -17,14 +17,10 @@
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
-
+import java.util.Map;
import org.eclipse.jgit.lib.Config;
-import java.util.Map;
-
-/**
- * Represents the global LFS configuration stored in $SITE/etc/lfs.config.
- */
+/** Represents the global LFS configuration stored in $SITE/etc/lfs.config. */
public class LfsGlobalConfig {
private final Config cfg;
@@ -34,8 +30,7 @@
}
public LfsBackend getDefaultBackend() {
- LfsBackendType type =
- cfg.getEnum("storage", null, "backend", LfsBackendType.FS);
+ LfsBackendType type = cfg.getEnum("storage", null, "backend", LfsBackendType.FS);
return new LfsBackend(null, type);
}
@@ -43,8 +38,7 @@
Builder<String, LfsBackend> builder = ImmutableMap.builder();
for (LfsBackendType type : LfsBackendType.values()) {
Map<String, LfsBackend> backendsOfType =
- FluentIterable.from(cfg.getSubsections(type.name()))
- .toMap(s -> new LfsBackend(s, type));
+ FluentIterable.from(cfg.getSubsections(type.name())).toMap(s -> new LfsBackend(s, type));
builder.putAll(backendsOfType);
}
@@ -55,13 +49,11 @@
return cfg.getString(section, subsection, name);
}
- public int getInt(String section, String subsection, String name,
- int defaultValue) {
+ public int getInt(String section, String subsection, String name, int defaultValue) {
return cfg.getInt(section, subsection, name, defaultValue);
}
- public boolean getBoolean(String section, String subsection, String name,
- boolean defaultValue) {
+ public boolean getBoolean(String section, String subsection, String name, boolean defaultValue) {
return cfg.getBoolean(section, subsection, name, defaultValue);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsProjectsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsProjectsConfig.java
index c686258..390a65f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsProjectsConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsProjectsConfig.java
@@ -23,21 +23,19 @@
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.VersionedMetaData;
import com.google.gerrit.server.project.ProjectCache;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.lib.CommitBuilder;
-import org.eclipse.jgit.lib.Config;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.CommitBuilder;
+import org.eclipse.jgit.lib.Config;
/**
- * Represents the project-specific LFS configuration stored in
- * the lfs.config file on the refs/meta/config branch of All-Projects.
+ * Represents the project-specific LFS configuration stored in the lfs.config file on the
+ * refs/meta/config branch of All-Projects.
*/
public class LfsProjectsConfig extends VersionedMetaData {
private final String configFilename;
@@ -45,18 +43,15 @@
private final AllProjectsName allProjects;
private Config projectConfig;
- public LfsProjectsConfig(@PluginName String pluginName,
- ProjectCache projectCache,
- AllProjectsName allProjects) {
+ public LfsProjectsConfig(
+ @PluginName String pluginName, ProjectCache projectCache, AllProjectsName allProjects) {
this.configFilename = pluginName + ".config";
this.projectCache = projectCache;
this.allProjects = allProjects;
this.projectConfig = loadProjectConfig();
}
- /**
- * @return all the configured LFS sections.
- */
+ /** @return all the configured LFS sections. */
public List<LfsProjectConfigSection> getConfigSections() {
Set<String> namespaces = projectConfig.getSubsections(LfsProjectConfigSection.LFS);
if (!namespaces.isEmpty()) {
@@ -124,8 +119,7 @@
}
@Override
- protected boolean onSave(CommitBuilder commit)
- throws IOException, ConfigInvalidException {
+ protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
if (Strings.isNullOrEmpty(commit.getMessage())) {
commit.setMessage("Update LFS configuration\n");
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoriesCache.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoriesCache.java
index 2a15578..8732331 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoriesCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoriesCache.java
@@ -17,7 +17,6 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Singleton;
-
import org.eclipse.jgit.lfs.server.LargeFileRepository;
@Singleton
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoryResolver.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoryResolver.java
index 1aebf8b..cbb5e95 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoryResolver.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsRepositoryResolver.java
@@ -19,25 +19,21 @@
import com.google.common.base.Strings;
import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
-
+import java.util.Map;
import org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound;
import org.eclipse.jgit.lfs.server.LargeFileRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Map;
-
public class LfsRepositoryResolver {
- private static final Logger log =
- LoggerFactory.getLogger(LfsRepositoryResolver.class);
+ private static final Logger log = LoggerFactory.getLogger(LfsRepositoryResolver.class);
private final LfsRepositoriesCache cache;
private final LfsBackend defaultBackend;
private final Map<String, LfsBackend> backends;
@Inject
- LfsRepositoryResolver(LfsRepositoriesCache cache,
- LfsConfigurationFactory configFactory) {
+ LfsRepositoryResolver(LfsRepositoriesCache cache, LfsConfigurationFactory configFactory) {
this.cache = cache;
LfsGlobalConfig config = configFactory.getGlobalConfig();
@@ -53,9 +49,10 @@
} else {
backend = backends.get(backendName);
if (backend == null) {
- log.error(String.format("Project %s is configured with not existing"
- + " backend %s", project,
- Strings.isNullOrEmpty(backendName) ? DEFAULT : backendName));
+ log.error(
+ String.format(
+ "Project %s is configured with not existing" + " backend %s",
+ project, Strings.isNullOrEmpty(backendName) ? DEFAULT : backendName));
throw new LfsRepositoryNotFound(project.get());
}
}
@@ -66,10 +63,10 @@
}
//this is unlikely situation as cache is pre-populated from config but...
- log.error(String.format("Project %s is configured with not existing"
- + " backend %s of type %s", project,
- Strings.isNullOrEmpty(backendName) ? DEFAULT : backendName,
- backend.type));
+ log.error(
+ String.format(
+ "Project %s is configured with not existing" + " backend %s of type %s",
+ project, Strings.isNullOrEmpty(backendName) ? DEFAULT : backendName, backend.type));
throw new LfsRepositoryNotFound(project.get());
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshAuth.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshAuth.java
index 22d7236..61a6032 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshAuth.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshAuth.java
@@ -25,7 +25,6 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@@ -37,39 +36,41 @@
private final Gson gson;
@Inject
- LfsSshAuth(LfsSshRequestAuthorizer auth,
- @CanonicalWebUrl Provider<String> canonicalWebUrl) {
+ LfsSshAuth(LfsSshRequestAuthorizer auth, @CanonicalWebUrl Provider<String> canonicalWebUrl) {
this.auth = auth;
this.canonicalWebUrl = canonicalWebUrl.get();
- this.gson = new GsonBuilder()
- .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
- .disableHtmlEscaping()
- .create();
+ this.gson =
+ new GsonBuilder()
+ .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
+ .disableHtmlEscaping()
+ .create();
}
@Override
- public String authenticate(CurrentUser user, List<String> args)
- throws UnloggedFailure, Failure {
+ public String authenticate(CurrentUser user, List<String> args) throws UnloggedFailure, Failure {
try {
URL url = new URL(canonicalWebUrl);
String path = url.getPath();
String project = args.get(0);
String operation = args.get(1);
- StringBuilder href = new StringBuilder(url.getProtocol())
- .append("://")
- .append(url.getAuthority())
- .append(path)
- .append(path.endsWith("/") ? "" : "/")
- .append(project)
- .append("/info/lfs");
- LfsSshRequestAuthorizer.SshAuthInfo info =
- auth.generateAuthInfo(user, project, operation);
+ StringBuilder href =
+ new StringBuilder(url.getProtocol())
+ .append("://")
+ .append(url.getAuthority())
+ .append(path)
+ .append(path.endsWith("/") ? "" : "/")
+ .append(project)
+ .append("/info/lfs");
+ LfsSshRequestAuthorizer.SshAuthInfo info = auth.generateAuthInfo(user, project, operation);
ExpiringAction action = new ExpiringAction(href.toString(), info);
return gson.toJson(action);
} catch (MalformedURLException e) {
- throw new Failure(1, "Server configuration error: "
- + "forming Git LFS endpoint URL from canonicalWebUrl ["
- + canonicalWebUrl + "] failed.");
+ throw new Failure(
+ 1,
+ "Server configuration error: "
+ + "forming Git LFS endpoint URL from canonicalWebUrl ["
+ + canonicalWebUrl
+ + "] failed.");
}
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshRequestAuthorizer.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshRequestAuthorizer.java
index 208f30e..2259db9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshRequestAuthorizer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsSshRequestAuthorizer.java
@@ -18,12 +18,10 @@
import com.google.gerrit.server.CurrentUser;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Singleton
class LfsSshRequestAuthorizer {
@@ -33,8 +31,7 @@
}
}
- private static final Logger log =
- LoggerFactory.getLogger(LfsSshRequestAuthorizer.class);
+ private static final Logger log = LoggerFactory.getLogger(LfsSshRequestAuthorizer.class);
private static final int DEFAULT_SSH_TIMEOUT = 10;
static final String SSH_AUTH_PREFIX = "Ssh: ";
@@ -42,29 +39,30 @@
private final int expirationSeconds;
@Inject
- LfsSshRequestAuthorizer(Processor processor,
- LfsConfigurationFactory configFactory) {
+ LfsSshRequestAuthorizer(Processor processor, LfsConfigurationFactory configFactory) {
this.processor = processor;
int timeout = DEFAULT_SSH_TIMEOUT;
try {
- timeout = configFactory.getGlobalConfig().getInt("auth",
- null, "sshExpirationSeconds", DEFAULT_SSH_TIMEOUT);
+ timeout =
+ configFactory
+ .getGlobalConfig()
+ .getInt("auth", null, "sshExpirationSeconds", DEFAULT_SSH_TIMEOUT);
} catch (IllegalArgumentException e) {
- log.warn("Reading expiration timeout failed with error."
- + " Falling back to default {}", DEFAULT_SSH_TIMEOUT, e);
+ log.warn(
+ "Reading expiration timeout failed with error." + " Falling back to default {}",
+ DEFAULT_SSH_TIMEOUT,
+ e);
}
this.expirationSeconds = timeout;
}
- SshAuthInfo generateAuthInfo(CurrentUser user, String project,
- String operation) {
- LfsSshAuthToken token = new LfsSshAuthToken(user.getUserName(), project,
- operation, expirationSeconds);
+ SshAuthInfo generateAuthInfo(CurrentUser user, String project, String operation) {
+ LfsSshAuthToken token =
+ new LfsSshAuthToken(user.getUserName(), project, operation, expirationSeconds);
return new SshAuthInfo(processor.serialize(token), token.expiresAt);
}
- Optional<String> getUserFromValidToken(String authToken,
- String project, String operation) {
+ Optional<String> getUserFromValidToken(String authToken, String project, String operation) {
Optional<LfsSshAuthToken> token = processor.deserialize(authToken);
if (!token.isPresent()) {
return Optional.absent();
@@ -101,8 +99,8 @@
return Optional.absent();
}
- return Optional.of(new LfsSshAuthToken(values.get(0), values.get(1),
- values.get(2), values.get(3)));
+ return Optional.of(
+ new LfsSshAuthToken(values.get(0), values.get(1), values.get(2), values.get(3)));
}
}
@@ -110,8 +108,7 @@
private final String project;
private final String operation;
- protected Verifier(LfsSshAuthToken token, String project,
- String operation) {
+ protected Verifier(LfsSshAuthToken token, String project, String operation) {
super(token);
this.project = project;
this.operation = operation;
@@ -119,8 +116,7 @@
@Override
protected boolean verifyTokenValues() {
- return project.equals(token.project)
- && operation.equals(token.operation);
+ return project.equals(token.project) && operation.equals(token.operation);
}
}
@@ -129,16 +125,14 @@
private final String project;
private final String operation;
- LfsSshAuthToken(String user, String project, String operation,
- int expirationSeconds) {
+ LfsSshAuthToken(String user, String project, String operation, int expirationSeconds) {
super(expirationSeconds);
this.user = user;
this.project = project;
this.operation = operation;
}
- LfsSshAuthToken(String user, String project, String operation,
- String expiresAt) {
+ LfsSshAuthToken(String user, String project, String operation, String expiresAt) {
super(expiresAt);
this.user = user;
this.project = project;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/Lifecycle.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/Lifecycle.java
index b002c6d..73302ad 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/Lifecycle.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/Lifecycle.java
@@ -14,16 +14,15 @@
package com.googlesource.gerrit.plugins.lfs;
-import org.eclipse.jgit.lib.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.common.base.Strings;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import org.eclipse.jgit.lib.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Singleton
public class Lifecycle implements LifecycleListener {
@@ -49,12 +48,13 @@
}
private void warn(String msg) {
- log.warn(String.format(
- "%s; LFS will not be enabled. Run site initialization, or manually set"
- + " lfs.plugin to '%s' in gerrit.config", msg, name));
+ log.warn(
+ String.format(
+ "%s; LFS will not be enabled. Run site initialization, or manually set"
+ + " lfs.plugin to '%s' in gerrit.config",
+ msg, name));
}
@Override
- public void stop() {
- }
+ public void stop() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/Module.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/Module.java
index 0aa4adc..089ebc4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/Module.java
@@ -28,14 +28,15 @@
@Override
protected void configure() {
- install(new RestApiModule() {
- @Override
- protected void configure() {
- get(PROJECT_KIND, "lfs:config-project").to(GetLfsProjectConfig.class);
- get(PROJECT_KIND, "lfs:config-global").to(GetLfsGlobalConfig.class);
- put(PROJECT_KIND, "lfs:config-global").to(PutLfsGlobalConfig.class);
- }
- });
+ install(
+ new RestApiModule() {
+ @Override
+ protected void configure() {
+ get(PROJECT_KIND, "lfs:config-project").to(GetLfsProjectConfig.class);
+ get(PROJECT_KIND, "lfs:config-global").to(GetLfsGlobalConfig.class);
+ put(PROJECT_KIND, "lfs:config-global").to(PutLfsGlobalConfig.class);
+ }
+ });
bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(Lifecycle.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/PutLfsGlobalConfig.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/PutLfsGlobalConfig.java
index a996e3b..5e81e73 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/PutLfsGlobalConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/PutLfsGlobalConfig.java
@@ -34,19 +34,16 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
-import org.eclipse.jgit.lib.Config;
-
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.errors.RepositoryNotFoundException;
+import org.eclipse.jgit.lib.Config;
@Singleton
-class PutLfsGlobalConfig
- implements RestModifyView<ProjectResource, LfsGlobalConfigInput> {
+class PutLfsGlobalConfig implements RestModifyView<ProjectResource, LfsGlobalConfigInput> {
private final String pluginName;
private final AllProjectsName allProjectsName;
@@ -56,7 +53,8 @@
private final GetLfsGlobalConfig get;
@Inject
- PutLfsGlobalConfig(@PluginName String pluginName,
+ PutLfsGlobalConfig(
+ @PluginName String pluginName,
AllProjectsName allProjectsName,
Provider<CurrentUser> self,
Provider<MetaDataUpdate.User> metaDataUpdateFactory,
@@ -71,13 +69,12 @@
}
@Override
- public LfsGlobalConfigInfo apply(ProjectResource resource,
- LfsGlobalConfigInput input) throws RestApiException {
+ public LfsGlobalConfigInfo apply(ProjectResource resource, LfsGlobalConfigInput input)
+ throws RestApiException {
IdentifiedUser user = self.get().asIdentifiedUser();
Project.NameKey projectName = resource.getNameKey();
- if (!(projectName.equals(allProjectsName)
- && user.getCapabilities().canAdministrateServer())) {
+ if (!(projectName.equals(allProjectsName) && user.getCapabilities().canAdministrateServer())) {
throw new ResourceNotFoundException();
}
@@ -90,38 +87,30 @@
try {
config.load(md);
} catch (ConfigInvalidException | IOException e) {
- throw new ResourceConflictException(
- "Cannot read LFS config in " + projectName);
+ throw new ResourceConflictException("Cannot read LFS config in " + projectName);
}
Config cfg = new Config();
if (input.namespaces != null) {
- Set<String> backends =
- lfsConfigFactory.getGlobalConfig().getBackends().keySet();
- Set<Entry<String, LfsProjectConfigInfo>> namespaces =
- input.namespaces.entrySet();
+ Set<String> backends = lfsConfigFactory.getGlobalConfig().getBackends().keySet();
+ Set<Entry<String, LfsProjectConfigInfo>> namespaces = input.namespaces.entrySet();
for (Map.Entry<String, LfsProjectConfigInfo> namespace : namespaces) {
LfsProjectConfigInfo info = namespace.getValue();
if (info.enabled != null) {
- cfg.setBoolean(
- pluginName, namespace.getKey(), KEY_ENABLED, info.enabled);
+ cfg.setBoolean(pluginName, namespace.getKey(), KEY_ENABLED, info.enabled);
}
if (info.maxObjectSize != null) {
- cfg.setLong(
- pluginName, namespace.getKey(),
- KEY_MAX_OBJECT_SIZE, info.maxObjectSize);
+ cfg.setLong(pluginName, namespace.getKey(), KEY_MAX_OBJECT_SIZE, info.maxObjectSize);
}
if (info.readOnly != null) {
- cfg.setBoolean(
- pluginName, namespace.getKey(), KEY_READ_ONLY, info.readOnly);
+ cfg.setBoolean(pluginName, namespace.getKey(), KEY_READ_ONLY, info.readOnly);
}
if (!Strings.isNullOrEmpty(info.backend)) {
if (!backends.contains(info.backend)) {
throw new ResourceConflictException(
- String.format("Namespace %s: backend %s does not exist",
- namespace, info.backend));
+ String.format(
+ "Namespace %s: backend %s does not exist", namespace, info.backend));
}
- cfg.setString(pluginName, namespace.getKey(),
- KEY_BACKEND, info.backend);
+ cfg.setString(pluginName, namespace.getKey(), KEY_BACKEND, info.backend);
}
}
}
@@ -131,11 +120,9 @@
} catch (IOException e) {
if (e.getCause() instanceof ConfigInvalidException) {
throw new ResourceConflictException(
- "Cannot update LFS config in " + projectName
- + ": " + e.getCause().getMessage());
+ "Cannot update LFS config in " + projectName + ": " + e.getCause().getMessage());
}
- throw new ResourceConflictException(
- "Cannot update LFS config in " + projectName);
+ throw new ResourceConflictException("Cannot update LFS config in " + projectName);
}
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(projectName.get());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/SshModule.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/SshModule.java
index 816e0a1..e74e813 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/SshModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/SshModule.java
@@ -22,7 +22,6 @@
@Override
protected void configureCommands() {
- DynamicItem.bind(binder(), LfsPluginAuthCommand.LfsSshPluginAuth.class)
- .to(LfsSshAuth.class);
+ DynamicItem.bind(binder(), LfsPluginAuthCommand.LfsSshPluginAuth.class).to(LfsSshAuth.class);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsContentServlet.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsContentServlet.java
index 66d0765..5bdb4d8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsContentServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsContentServlet.java
@@ -20,7 +20,12 @@
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
-
+import java.io.IOException;
+import java.text.MessageFormat;
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpStatus;
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
import org.eclipse.jgit.lfs.server.fs.FileLfsServlet;
@@ -28,14 +33,6 @@
import org.eclipse.jgit.lfs.server.fs.ObjectUploadListener;
import org.eclipse.jgit.lfs.server.internal.LfsServerText;
-import java.io.IOException;
-import java.text.MessageFormat;
-
-import javax.servlet.AsyncContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
public class LfsFsContentServlet extends FileLfsServlet {
public interface Factory {
LfsFsContentServlet create(LocalLargeFileRepository largeFileRepository);
@@ -48,8 +45,8 @@
private final long timeout;
@Inject
- public LfsFsContentServlet(LfsFsRequestAuthorizer authorizer,
- @Assisted LocalLargeFileRepository repository) {
+ public LfsFsContentServlet(
+ LfsFsRequestAuthorizer authorizer, @Assisted LocalLargeFileRepository repository) {
super(repository, 0);
this.authorizer = authorizer;
this.repository = repository;
@@ -65,22 +62,26 @@
}
if (repository.getSize(obj) == -1) {
- sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat
- .format(LfsServerText.get().objectNotFound, obj.getName()));
+ sendError(
+ rsp,
+ HttpStatus.SC_NOT_FOUND,
+ MessageFormat.format(LfsServerText.get().objectNotFound, obj.getName()));
return;
}
- if (!authorizer.verifyAuthInfo(req.getHeader(HDR_AUTHORIZATION),
- DOWNLOAD, obj)) {
- sendError(rsp, HttpStatus.SC_UNAUTHORIZED, MessageFormat.format(
- LfsServerText.get().failedToCalcSignature, "Invalid authorization token"));
+ if (!authorizer.verifyAuthInfo(req.getHeader(HDR_AUTHORIZATION), DOWNLOAD, obj)) {
+ sendError(
+ rsp,
+ HttpStatus.SC_UNAUTHORIZED,
+ MessageFormat.format(
+ LfsServerText.get().failedToCalcSignature, "Invalid authorization token"));
return;
}
AsyncContext context = req.startAsync();
context.setTimeout(timeout);
- rsp.getOutputStream().setWriteListener(
- new ObjectDownloadListener(repository, context, rsp, obj));
+ rsp.getOutputStream()
+ .setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj));
}
@Override
@@ -91,17 +92,18 @@
return;
}
- if (!authorizer.verifyAuthInfo(
- req.getHeader(HDR_AUTHORIZATION), UPLOAD, id)) {
- sendError(rsp, HttpStatus.SC_UNAUTHORIZED,
- MessageFormat.format(LfsServerText.get().failedToCalcSignature,
- "Invalid authorization token"));
+ if (!authorizer.verifyAuthInfo(req.getHeader(HDR_AUTHORIZATION), UPLOAD, id)) {
+ sendError(
+ rsp,
+ HttpStatus.SC_UNAUTHORIZED,
+ MessageFormat.format(
+ LfsServerText.get().failedToCalcSignature, "Invalid authorization token"));
return;
}
AsyncContext context = req.startAsync();
context.setTimeout(timeout);
- req.getInputStream().setReadListener(
- new ObjectUploadListener(repository, context, req, rsp, id));
+ req.getInputStream()
+ .setReadListener(new ObjectUploadListener(repository, context, req, rsp, id));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizer.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizer.java
index 87eb349..1626e38 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizer.java
@@ -17,16 +17,13 @@
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.lfs.AuthInfo;
import com.googlesource.gerrit.plugins.lfs.LfsAuthToken;
import com.googlesource.gerrit.plugins.lfs.LfsCipher;
-
-import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
-import org.eclipse.jgit.lfs.lib.LongObjectId;
-
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
+import org.eclipse.jgit.lfs.lib.LongObjectId;
@Singleton
public class LfsFsRequestAuthorizer {
@@ -37,14 +34,12 @@
this.processor = processor;
}
- public AuthInfo generateAuthInfo(String operation, AnyLongObjectId id,
- int expirationSeconds) {
+ public AuthInfo generateAuthInfo(String operation, AnyLongObjectId id, int expirationSeconds) {
LfsFsAuthToken token = new LfsFsAuthToken(operation, id, expirationSeconds);
return new AuthInfo(processor.serialize(token), token.expiresAt);
}
- public boolean verifyAuthInfo(String authToken, String operation,
- AnyLongObjectId id) {
+ public boolean verifyAuthInfo(String authToken, String operation, AnyLongObjectId id) {
Optional<LfsFsAuthToken> token = processor.deserialize(authToken);
if (!token.isPresent()) {
return false;
@@ -74,8 +69,8 @@
return Optional.absent();
}
- return Optional.of(new LfsFsAuthToken(values.get(0),
- LongObjectId.fromString(values.get(1)), values.get(2)));
+ return Optional.of(
+ new LfsFsAuthToken(values.get(0), LongObjectId.fromString(values.get(1)), values.get(2)));
}
}
@@ -83,8 +78,7 @@
private final String operation;
private final AnyLongObjectId id;
- protected Verifier(LfsFsAuthToken token,
- String operation, AnyLongObjectId id) {
+ protected Verifier(LfsFsAuthToken token, String operation, AnyLongObjectId id) {
super(token);
this.operation = operation;
this.id = id;
@@ -92,8 +86,7 @@
@Override
protected boolean verifyTokenValues() {
- return operation.equals(token.operation)
- && id.getName().equals(token.id.getName());
+ return operation.equals(token.operation) && id.getName().equals(token.id.getName());
}
}
@@ -101,8 +94,7 @@
private final String operation;
private final AnyLongObjectId id;
- LfsFsAuthToken(String operation, AnyLongObjectId id,
- int expirationSeconds) {
+ LfsFsAuthToken(String operation, AnyLongObjectId id, int expirationSeconds) {
super(expirationSeconds);
this.operation = operation;
this.id = id;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LocalLargeFileRepository.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LocalLargeFileRepository.java
index f96cd7e..4d897d4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LocalLargeFileRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/fs/LocalLargeFileRepository.java
@@ -23,21 +23,18 @@
import com.google.gerrit.extensions.annotations.PluginData;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
-
import com.googlesource.gerrit.plugins.lfs.AuthInfo;
import com.googlesource.gerrit.plugins.lfs.ExpiringAction;
import com.googlesource.gerrit.plugins.lfs.LfsBackend;
import com.googlesource.gerrit.plugins.lfs.LfsConfigurationFactory;
import com.googlesource.gerrit.plugins.lfs.LfsGlobalConfig;
-
-import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
-import org.eclipse.jgit.lfs.server.Response;
-import org.eclipse.jgit.lfs.server.fs.FileLfsRepository;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
+import org.eclipse.jgit.lfs.server.Response;
+import org.eclipse.jgit.lfs.server.fs.FileLfsRepository;
public class LocalLargeFileRepository extends FileLfsRepository {
public interface Factory {
@@ -52,19 +49,22 @@
private final int expirationSeconds;
@Inject
- LocalLargeFileRepository(LfsConfigurationFactory configFactory,
+ LocalLargeFileRepository(
+ LfsConfigurationFactory configFactory,
LfsFsRequestAuthorizer authorizer,
@PluginCanonicalWebUrl String url,
@PluginData Path defaultDataDir,
- @Assisted LfsBackend backend) throws IOException {
- super(getContentUrl(url, backend),
- getOrCreateDataDir(configFactory.getGlobalConfig(),
- backend, defaultDataDir));
+ @Assisted LfsBackend backend)
+ throws IOException {
+ super(
+ getContentUrl(url, backend),
+ getOrCreateDataDir(configFactory.getGlobalConfig(), backend, defaultDataDir));
this.authorizer = authorizer;
this.servletUrlPattern = "/" + getContentPath(backend) + "*";
- this.expirationSeconds = configFactory.getGlobalConfig()
- .getInt(backend.type.name(), backend.name, "expirationSeconds",
- DEFAULT_TIMEOUT);
+ this.expirationSeconds =
+ configFactory
+ .getGlobalConfig()
+ .getInt(backend.type.name(), backend.name, "expirationSeconds", DEFAULT_TIMEOUT);
}
public String getServletUrlPattern() {
@@ -74,16 +74,14 @@
@Override
public Response.Action getDownloadAction(AnyLongObjectId id) {
Response.Action action = super.getDownloadAction(id);
- AuthInfo authInfo =
- authorizer.generateAuthInfo(DOWNLOAD, id, expirationSeconds);
+ AuthInfo authInfo = authorizer.generateAuthInfo(DOWNLOAD, id, expirationSeconds);
return new ExpiringAction(action.href, authInfo);
}
@Override
public Response.Action getUploadAction(AnyLongObjectId id, long size) {
Response.Action action = super.getUploadAction(id, size);
- AuthInfo authInfo =
- authorizer.generateAuthInfo(UPLOAD, id, expirationSeconds);
+ AuthInfo authInfo = authorizer.generateAuthInfo(UPLOAD, id, expirationSeconds);
return new ExpiringAction(action.href, authInfo);
}
@@ -94,15 +92,15 @@
}
private static String getContentPath(LfsBackend backend) {
- return CONTENT_PATH + "/"
- + (Strings.isNullOrEmpty(backend.name) ? DEFAULT : backend.name) + "/";
+ return CONTENT_PATH
+ + "/"
+ + (Strings.isNullOrEmpty(backend.name) ? DEFAULT : backend.name)
+ + "/";
}
- private static Path getOrCreateDataDir(LfsGlobalConfig config,
- LfsBackend backendConfig, Path defaultDataDir)
- throws IOException {
- String dataDir = config.getString(
- backendConfig.type.name(), backendConfig.name, "directory");
+ private static Path getOrCreateDataDir(
+ LfsGlobalConfig config, LfsBackend backendConfig, Path defaultDataDir) throws IOException {
+ String dataDir = config.getString(backendConfig.type.name(), backendConfig.name, "directory");
if (Strings.isNullOrEmpty(dataDir)) {
return defaultDataDir;
}
@@ -114,8 +112,7 @@
// we should at least make sure that directory is readable
if (!Files.isReadable(ensured)) {
- throw new IOException(
- "Path '" + ensured.toAbsolutePath() + "' cannot be accessed");
+ throw new IOException("Path '" + ensured.toAbsolutePath() + "' cannot be accessed");
}
return ensured;
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 9a413e6..a10242a 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
@@ -17,11 +17,9 @@
import com.google.common.base.MoreObjects;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
-
import com.googlesource.gerrit.plugins.lfs.LfsBackend;
import com.googlesource.gerrit.plugins.lfs.LfsConfigurationFactory;
import com.googlesource.gerrit.plugins.lfs.LfsGlobalConfig;
-
import org.eclipse.jgit.lfs.server.s3.S3Config;
import org.eclipse.jgit.lfs.server.s3.S3Repository;
@@ -31,29 +29,25 @@
}
@Inject
- S3LargeFileRepository(LfsConfigurationFactory configFactory,
- @Assisted LfsBackend backendConfig) {
+ S3LargeFileRepository(LfsConfigurationFactory configFactory, @Assisted LfsBackend backendConfig) {
super(getS3Config(configFactory.getGlobalConfig(), backendConfig));
}
- private static S3Config getS3Config(LfsGlobalConfig config,
- LfsBackend backendConfig) {
+ private static S3Config getS3Config(LfsGlobalConfig config, LfsBackend backendConfig) {
String section = backendConfig.type.name();
String region = config.getString(section, backendConfig.name, "region");
String bucket = config.getString(section, backendConfig.name, "bucket");
String storageClass =
MoreObjects.firstNonNull(
- config.getString(section, backendConfig.name, "storageClass"),
- "REDUCED_REDUNDANCY");
- int expirationSeconds =
- config.getInt(section, backendConfig.name, "expirationSeconds", 60);
+ config.getString(section, backendConfig.name, "storageClass"), "REDUCED_REDUNDANCY");
+ int expirationSeconds = config.getInt(section, backendConfig.name, "expirationSeconds", 60);
boolean disableSslVerify =
config.getBoolean(section, backendConfig.name, "disableSslVerify", false);
String accessKey = config.getString(section, backendConfig.name, "accessKey");
String secretKey = config.getString(section, backendConfig.name, "secretKey");
- return new S3Config(region, bucket, storageClass, accessKey, secretKey,
- expirationSeconds, disableSslVerify);
+ return new S3Config(
+ region, bucket, storageClass, accessKey, secretKey, expirationSeconds, disableSslVerify);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsAuthTokenTest.java b/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsAuthTokenTest.java
index 5b5c532..825a746 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsAuthTokenTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsAuthTokenTest.java
@@ -19,14 +19,12 @@
import static com.googlesource.gerrit.plugins.lfs.LfsAuthToken.Verifier.onTime;
import com.google.common.base.Optional;
-
+import java.util.ArrayList;
+import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
public class LfsAuthTokenTest {
private final LfsCipher cipher = new LfsCipher();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsCipherTest.java b/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsCipherTest.java
index 5f51f4a..5970845 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsCipherTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/lfs/LfsCipherTest.java
@@ -17,7 +17,6 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Optional;
-
import org.junit.Test;
public class LfsCipherTest {
@@ -46,12 +45,13 @@
String encrypted = cipher.encrypt(plain);
// there is a chance that two first chars in token are the same
// in such case re-generate the token
- while(encrypted.charAt(0) == encrypted.charAt(1)) {
+ while (encrypted.charAt(0) == encrypted.charAt(1)) {
encrypted = cipher.encrypt(plain);
}
- Optional<String> decrypted = cipher.decrypt(encrypted.substring(1, 2)
- + encrypted.substring(0, 1) + encrypted.substring(2));
+ Optional<String> decrypted =
+ cipher.decrypt(
+ encrypted.substring(1, 2) + encrypted.substring(0, 1) + encrypted.substring(2));
assertThat(decrypted.isPresent()).isTrue();
assertThat(decrypted.get()).isNotEqualTo(plain);
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizerTest.java b/src/test/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizerTest.java
index 8513efb..38c310f 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/lfs/fs/LfsFsRequestAuthorizerTest.java
@@ -20,7 +20,6 @@
import com.googlesource.gerrit.plugins.lfs.AuthInfo;
import com.googlesource.gerrit.plugins.lfs.LfsCipher;
import com.googlesource.gerrit.plugins.lfs.fs.LfsFsRequestAuthorizer.Processor;
-
import org.eclipse.jgit.lfs.lib.LongObjectId;
import org.junit.Test;
@@ -43,8 +42,12 @@
@Test
public void testVerifyAgainstDifferentObjectId() throws Exception {
AuthInfo info = auth.generateAuthInfo("o", zeroId(), 1);
- assertThat(auth.verifyAuthInfo(info.authToken, "o",
- LongObjectId.fromString("123456789012345678901234567890"
- + "123456789012345678901234567890" + "1234"))).isFalse();
+ assertThat(
+ auth.verifyAuthInfo(
+ info.authToken,
+ "o",
+ LongObjectId.fromString(
+ "123456789012345678901234567890" + "123456789012345678901234567890" + "1234")))
+ .isFalse();
}
}