Move GetArchive.AllowedFormats to its own file
Change-Id: I999ed908d587ff9af91715c488b944de5254fac4
This commit is contained in:
parent
2962ec29c7
commit
d96c3e5986
@ -0,0 +1,63 @@
|
|||||||
|
// Copyright (C) 2016 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.google.gerrit.server.change;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.gerrit.server.config.DownloadConfig;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class AllowedFormats {
|
||||||
|
final ImmutableMap<String, ArchiveFormat> extensions;
|
||||||
|
final Set<ArchiveFormat> allowed;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AllowedFormats(DownloadConfig cfg) {
|
||||||
|
Map<String, ArchiveFormat> exts = new HashMap<>();
|
||||||
|
for (ArchiveFormat format : cfg.getArchiveFormats()) {
|
||||||
|
for (String ext : format.getSuffixes()) {
|
||||||
|
exts.put(ext, format);
|
||||||
|
}
|
||||||
|
exts.put(format.name().toLowerCase(), format);
|
||||||
|
}
|
||||||
|
extensions = ImmutableMap.copyOf(exts);
|
||||||
|
|
||||||
|
// Zip is not supported because it may be interpreted by a Java plugin as a
|
||||||
|
// valid JAR file, whose code would have access to cookies on the domain.
|
||||||
|
allowed = Sets.filter(
|
||||||
|
cfg.getArchiveFormats(),
|
||||||
|
new Predicate<ArchiveFormat>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(ArchiveFormat format) {
|
||||||
|
return (format != ArchiveFormat.ZIP);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ArchiveFormat> getAllowed() {
|
||||||
|
return allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableMap<String, ArchiveFormat> getExtensions() {
|
||||||
|
return extensions;
|
||||||
|
}
|
||||||
|
}
|
@ -14,18 +14,13 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.change;
|
package com.google.gerrit.server.change;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.server.config.DownloadConfig;
|
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.api.ArchiveCommand;
|
import org.eclipse.jgit.api.ArchiveCommand;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
@ -37,48 +32,8 @@ import org.kohsuke.args4j.Option;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class GetArchive implements RestReadView<RevisionResource> {
|
public class GetArchive implements RestReadView<RevisionResource> {
|
||||||
@Singleton
|
|
||||||
public static class AllowedFormats {
|
|
||||||
final ImmutableMap<String, ArchiveFormat> extensions;
|
|
||||||
final Set<ArchiveFormat> allowed;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
AllowedFormats(DownloadConfig cfg) {
|
|
||||||
Map<String, ArchiveFormat> exts = new HashMap<>();
|
|
||||||
for (ArchiveFormat format : cfg.getArchiveFormats()) {
|
|
||||||
for (String ext : format.getSuffixes()) {
|
|
||||||
exts.put(ext, format);
|
|
||||||
}
|
|
||||||
exts.put(format.name().toLowerCase(), format);
|
|
||||||
}
|
|
||||||
extensions = ImmutableMap.copyOf(exts);
|
|
||||||
|
|
||||||
// Zip is not supported because it may be interpreted by a Java plugin as a
|
|
||||||
// valid JAR file, whose code would have access to cookies on the domain.
|
|
||||||
allowed = Sets.filter(
|
|
||||||
cfg.getArchiveFormats(),
|
|
||||||
new Predicate<ArchiveFormat>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(ArchiveFormat format) {
|
|
||||||
return (format != ArchiveFormat.ZIP);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ArchiveFormat> getAllowed() {
|
|
||||||
return allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImmutableMap<String, ArchiveFormat> getExtensions() {
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final AllowedFormats allowedFormats;
|
private final AllowedFormats allowedFormats;
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ import com.google.gerrit.extensions.webui.WebUiPlugin;
|
|||||||
import com.google.gerrit.server.EnableSignedPush;
|
import com.google.gerrit.server.EnableSignedPush;
|
||||||
import com.google.gerrit.server.account.Realm;
|
import com.google.gerrit.server.account.Realm;
|
||||||
import com.google.gerrit.server.avatar.AvatarProvider;
|
import com.google.gerrit.server.avatar.AvatarProvider;
|
||||||
|
import com.google.gerrit.server.change.AllowedFormats;
|
||||||
import com.google.gerrit.server.change.ArchiveFormat;
|
import com.google.gerrit.server.change.ArchiveFormat;
|
||||||
import com.google.gerrit.server.change.GetArchive;
|
|
||||||
import com.google.gerrit.server.change.Submit;
|
import com.google.gerrit.server.change.Submit;
|
||||||
import com.google.gerrit.server.documentation.QueryDocumentationExecutor;
|
import com.google.gerrit.server.documentation.QueryDocumentationExecutor;
|
||||||
import com.google.gerrit.server.notedb.NotesMigration;
|
import com.google.gerrit.server.notedb.NotesMigration;
|
||||||
@ -72,7 +72,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
private final DynamicMap<DownloadCommand> downloadCommands;
|
private final DynamicMap<DownloadCommand> downloadCommands;
|
||||||
private final DynamicMap<CloneCommand> cloneCommands;
|
private final DynamicMap<CloneCommand> cloneCommands;
|
||||||
private final DynamicSet<WebUiPlugin> plugins;
|
private final DynamicSet<WebUiPlugin> plugins;
|
||||||
private final GetArchive.AllowedFormats archiveFormats;
|
private final AllowedFormats archiveFormats;
|
||||||
private final AllProjectsName allProjectsName;
|
private final AllProjectsName allProjectsName;
|
||||||
private final AllUsersName allUsersName;
|
private final AllUsersName allUsersName;
|
||||||
private final String anonymousCowardName;
|
private final String anonymousCowardName;
|
||||||
@ -92,7 +92,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
DynamicMap<DownloadCommand> downloadCommands,
|
DynamicMap<DownloadCommand> downloadCommands,
|
||||||
DynamicMap<CloneCommand> cloneCommands,
|
DynamicMap<CloneCommand> cloneCommands,
|
||||||
DynamicSet<WebUiPlugin> webUiPlugins,
|
DynamicSet<WebUiPlugin> webUiPlugins,
|
||||||
GetArchive.AllowedFormats archiveFormats,
|
AllowedFormats archiveFormats,
|
||||||
AllProjectsName allProjectsName,
|
AllProjectsName allProjectsName,
|
||||||
AllUsersName allUsersName,
|
AllUsersName allUsersName,
|
||||||
@AnonymousCowardName String anonymousCowardName,
|
@AnonymousCowardName String anonymousCowardName,
|
||||||
@ -215,7 +215,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
DynamicMap<DownloadScheme> downloadSchemes,
|
DynamicMap<DownloadScheme> downloadSchemes,
|
||||||
DynamicMap<DownloadCommand> downloadCommands,
|
DynamicMap<DownloadCommand> downloadCommands,
|
||||||
DynamicMap<CloneCommand> cloneCommands,
|
DynamicMap<CloneCommand> cloneCommands,
|
||||||
GetArchive.AllowedFormats archiveFormats) {
|
AllowedFormats archiveFormats) {
|
||||||
DownloadInfo info = new DownloadInfo();
|
DownloadInfo info = new DownloadInfo();
|
||||||
info.schemes = new HashMap<>();
|
info.schemes = new HashMap<>();
|
||||||
for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
|
for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
|
||||||
|
@ -18,8 +18,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.change.AllowedFormats;
|
||||||
import com.google.gerrit.server.change.ArchiveFormat;
|
import com.google.gerrit.server.change.ArchiveFormat;
|
||||||
import com.google.gerrit.server.change.GetArchive;
|
|
||||||
import com.google.gerrit.sshd.AbstractGitCommand;
|
import com.google.gerrit.sshd.AbstractGitCommand;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public class UploadArchive extends AbstractGitCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GetArchive.AllowedFormats allowedFormats;
|
private AllowedFormats allowedFormats;
|
||||||
@Inject
|
@Inject
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
private Options options = new Options();
|
private Options options = new Options();
|
||||||
|
Loading…
Reference in New Issue
Block a user