Merge changes from topic 'remove-gerrit-config-from-client'
* changes: Check with HEAD request if docs are available and remove GerritConfig Remove usage of GerritConfig from GitWebServlet Add acceptance test for /config/server/info REST endpoint Return info about SSHD with /config/server/info REST endpoint Retrieve clone commands from /config/server/info REST endpoint Add new extension point for clone commands Make *Info classes in GetServerInfo movable to extension package Expose more config parameters via REST Expose GitWeb config via /config/server/info REST endpoint Gerrit Client: Retrieve archives formats via REST Expose all auth config params that are needed by client over REST For clone commands rely on scheme URLs from the server
This commit is contained in:
@@ -1,172 +0,0 @@
|
||||
// Copyright (C) 2009 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.httpd;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.common.data.GitwebConfig;
|
||||
import com.google.gerrit.server.account.Realm;
|
||||
import com.google.gerrit.server.change.ArchiveFormat;
|
||||
import com.google.gerrit.server.change.GetArchive;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.ssh.SshInfo;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.ProvisionException;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
private final Realm realm;
|
||||
private final Config cfg;
|
||||
private final AuthConfig authConfig;
|
||||
private final GetArchive.AllowedFormats archiveFormats;
|
||||
private final GitWebConfig gitWebConfig;
|
||||
private final SshInfo sshInfo;
|
||||
|
||||
private final ServletContext servletContext;
|
||||
private final String anonymousCowardName;
|
||||
|
||||
@Inject
|
||||
GerritConfigProvider(Realm r,
|
||||
@GerritServerConfig Config gsc,
|
||||
AuthConfig ac,
|
||||
GitWebConfig gwc,
|
||||
SshInfo si,
|
||||
ServletContext sc,
|
||||
GetArchive.AllowedFormats af,
|
||||
@AnonymousCowardName String acn) {
|
||||
realm = r;
|
||||
cfg = gsc;
|
||||
authConfig = ac;
|
||||
archiveFormats = af;
|
||||
gitWebConfig = gwc;
|
||||
sshInfo = si;
|
||||
servletContext = sc;
|
||||
anonymousCowardName = acn;
|
||||
}
|
||||
|
||||
private GerritConfig create() throws MalformedURLException {
|
||||
final GerritConfig config = new GerritConfig();
|
||||
switch (authConfig.getAuthType()) {
|
||||
case LDAP:
|
||||
case LDAP_BIND:
|
||||
config.setRegisterUrl(cfg.getString("auth", null, "registerurl"));
|
||||
config.setRegisterText(cfg.getString("auth", null, "registertext"));
|
||||
config.setEditFullNameUrl(cfg.getString("auth", null, "editFullNameUrl"));
|
||||
config.setHttpPasswordSettingsEnabled(!authConfig.isGitBasicAuth());
|
||||
break;
|
||||
|
||||
case CUSTOM_EXTENSION:
|
||||
config.setRegisterUrl(cfg.getString("auth", null, "registerurl"));
|
||||
config.setRegisterText(cfg.getString("auth", null, "registertext"));
|
||||
config.setEditFullNameUrl(cfg.getString("auth", null, "editFullNameUrl"));
|
||||
config.setHttpPasswordUrl(cfg.getString("auth", null, "httpPasswordUrl"));
|
||||
break;
|
||||
|
||||
case HTTP:
|
||||
case HTTP_LDAP:
|
||||
config.setLoginUrl(cfg.getString("auth", null, "loginurl"));
|
||||
config.setLoginText(cfg.getString("auth", null, "logintext"));
|
||||
break;
|
||||
|
||||
case CLIENT_SSL_CERT_LDAP:
|
||||
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
|
||||
case OAUTH:
|
||||
case OPENID:
|
||||
case OPENID_SSO:
|
||||
break;
|
||||
}
|
||||
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
|
||||
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
||||
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
|
||||
config.setAuthType(authConfig.getAuthType());
|
||||
config.setDocumentationAvailable(servletContext
|
||||
.getResource("/Documentation/index.html") != null);
|
||||
config.setAnonymousCowardName(anonymousCowardName);
|
||||
config.setSuggestFrom(cfg.getInt("suggest", "from", 0));
|
||||
config.setChangeUpdateDelay((int) ConfigUtil.getTimeUnit(
|
||||
cfg, "change", null, "updateDelay", 30, TimeUnit.SECONDS));
|
||||
config.setLargeChangeSize(cfg.getInt("change", "largeChange", 500));
|
||||
|
||||
// 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.
|
||||
config.setArchiveFormats(Lists.newArrayList(Iterables.transform(
|
||||
Iterables.filter(
|
||||
archiveFormats.getAllowed(),
|
||||
new Predicate<ArchiveFormat>() {
|
||||
@Override
|
||||
public boolean apply(ArchiveFormat format) {
|
||||
return (format != ArchiveFormat.ZIP);
|
||||
}
|
||||
}),
|
||||
new Function<ArchiveFormat, String>() {
|
||||
@Override
|
||||
public String apply(ArchiveFormat in) {
|
||||
return in.getShortName();
|
||||
}
|
||||
})));
|
||||
|
||||
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
|
||||
config.setReportBugText(cfg.getString("gerrit", null, "reportBugText"));
|
||||
|
||||
config.setEditableAccountFields(realm.getEditableFields());
|
||||
|
||||
if (gitWebConfig.getUrl() != null) {
|
||||
config.setGitwebLink(new GitwebConfig(gitWebConfig.getUrl(), gitWebConfig
|
||||
.getGitWebType()));
|
||||
}
|
||||
|
||||
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
||||
config.setSshdAddress(sshInfo.getHostKeys().get(0).getHost());
|
||||
}
|
||||
|
||||
String replyTitle =
|
||||
Optional.fromNullable(cfg.getString("change", null, "replyTooltip"))
|
||||
.or("Reply and score")
|
||||
+ " (Shortcut: a)";
|
||||
String replyLabel =
|
||||
Optional.fromNullable(cfg.getString("change", null, "replyLabel"))
|
||||
.or("Reply")
|
||||
+ "\u2026";
|
||||
config.setReplyTitle(replyTitle);
|
||||
config.setReplyLabel(replyLabel);
|
||||
|
||||
config.setAllowDraftChanges(cfg.getBoolean("change", "allowDrafts", true));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GerritConfig get() {
|
||||
try {
|
||||
return create();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new ProvisionException("Cannot create GerritConfig instance", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,245 +0,0 @@
|
||||
// Copyright (C) 2009 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.httpd;
|
||||
|
||||
import static java.nio.file.Files.isExecutable;
|
||||
import static java.nio.file.Files.isRegularFile;
|
||||
|
||||
import com.google.gerrit.common.data.GitWebType;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class GitWebConfig {
|
||||
private static final Logger log = LoggerFactory.getLogger(GitWebConfig.class);
|
||||
|
||||
private final String url;
|
||||
private final Path gitweb_cgi;
|
||||
private final Path gitweb_css;
|
||||
private final Path gitweb_js;
|
||||
private final Path git_logo_png;
|
||||
private GitWebType type;
|
||||
|
||||
@Inject
|
||||
GitWebConfig(final SitePaths sitePaths, @GerritServerConfig final Config cfg) {
|
||||
final String cfgUrl = cfg.getString("gitweb", null, "url");
|
||||
final String cfgCgi = cfg.getString("gitweb", null, "cgi");
|
||||
|
||||
type = GitWebType.fromName(cfg.getString("gitweb", null, "type"));
|
||||
if (type == null) {
|
||||
url = null;
|
||||
gitweb_cgi = null;
|
||||
gitweb_css = null;
|
||||
gitweb_js = null;
|
||||
git_logo_png = null;
|
||||
return;
|
||||
}
|
||||
|
||||
type.setLinkName(cfg.getString("gitweb", null, "linkname"));
|
||||
type.setBranch(cfg.getString("gitweb", null, "branch"));
|
||||
type.setProject(cfg.getString("gitweb", null, "project"));
|
||||
type.setRevision(cfg.getString("gitweb", null, "revision"));
|
||||
type.setRootTree(cfg.getString("gitweb", null, "roottree"));
|
||||
type.setFile(cfg.getString("gitweb", null, "file"));
|
||||
type.setFileHistory(cfg.getString("gitweb", null, "filehistory"));
|
||||
type.setLinkDrafts(cfg.getBoolean("gitweb", null, "linkdrafts", true));
|
||||
type.setUrlEncode(cfg.getBoolean("gitweb", null, "urlencode", true));
|
||||
String pathSeparator = cfg.getString("gitweb", null, "pathSeparator");
|
||||
if (pathSeparator != null) {
|
||||
if (pathSeparator.length() == 1) {
|
||||
char c = pathSeparator.charAt(0);
|
||||
if (isValidPathSeparator(c)) {
|
||||
type.setPathSeparator(c);
|
||||
} else {
|
||||
log.warn("Invalid value specified for gitweb.pathSeparator: " + c);
|
||||
}
|
||||
} else {
|
||||
log.warn("Value specified for gitweb.pathSeparator is not a single character:" + pathSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
if (type.getBranch() == null) {
|
||||
log.warn("No Pattern specified for gitweb.branch, disabling.");
|
||||
type = null;
|
||||
} else if (type.getProject() == null) {
|
||||
log.warn("No Pattern specified for gitweb.project, disabling.");
|
||||
type = null;
|
||||
} else if (type.getRevision() == null) {
|
||||
log.warn("No Pattern specified for gitweb.revision, disabling.");
|
||||
type = null;
|
||||
} else if (type.getRootTree() == null) {
|
||||
log.warn("No Pattern specified for gitweb.roottree, disabling.");
|
||||
type = null;
|
||||
} else if (type.getFile() == null) {
|
||||
log.warn("No Pattern specified for gitweb.file, disabling.");
|
||||
type = null;
|
||||
} else if (type.getFileHistory() == null) {
|
||||
log.warn("No Pattern specified for gitweb.filehistory, disabling.");
|
||||
type = null;
|
||||
}
|
||||
|
||||
if ((cfgUrl != null && cfgUrl.isEmpty())
|
||||
|| (cfgCgi != null && cfgCgi.isEmpty())) {
|
||||
// Either setting was explicitly set to the empty string disabling
|
||||
// gitweb for this server. Disable the configuration.
|
||||
//
|
||||
url = null;
|
||||
gitweb_cgi = null;
|
||||
gitweb_css = null;
|
||||
gitweb_js = null;
|
||||
git_logo_png = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((cfgUrl != null) && (cfgCgi == null || cfgCgi.isEmpty())) {
|
||||
// Use an externally managed gitweb instance, and not an internal one.
|
||||
//
|
||||
url = cfgUrl;
|
||||
gitweb_cgi = null;
|
||||
gitweb_css = null;
|
||||
gitweb_js = null;
|
||||
git_logo_png = null;
|
||||
return;
|
||||
}
|
||||
|
||||
final Path pkgCgi = Paths.get("/usr/lib/cgi-bin/gitweb.cgi");
|
||||
String[] resourcePaths = {"/usr/share/gitweb/static", "/usr/share/gitweb",
|
||||
"/var/www/static", "/var/www"};
|
||||
Path cgi;
|
||||
|
||||
if (cfgCgi != null) {
|
||||
// Use the CGI script configured by the administrator, failing if it
|
||||
// cannot be used as specified.
|
||||
//
|
||||
cgi = sitePaths.resolve(cfgCgi);
|
||||
if (!isRegularFile(cgi)) {
|
||||
throw new IllegalStateException("Cannot find gitweb.cgi: " + cgi);
|
||||
}
|
||||
if (!isExecutable(cgi)) {
|
||||
throw new IllegalStateException("Cannot execute gitweb.cgi: " + cgi);
|
||||
}
|
||||
|
||||
if (!cgi.equals(pkgCgi)) {
|
||||
// Assume the administrator pointed us to the distribution,
|
||||
// which also has the corresponding CSS and logo file.
|
||||
//
|
||||
String absPath = cgi.getParent().toAbsolutePath().toString();
|
||||
resourcePaths = new String[] {absPath + "/static", absPath};
|
||||
}
|
||||
|
||||
} else if (isRegularFile(pkgCgi) && isExecutable(pkgCgi)) {
|
||||
// Use the OS packaged CGI.
|
||||
//
|
||||
log.debug("Assuming gitweb at " + pkgCgi);
|
||||
cgi = pkgCgi;
|
||||
|
||||
} else {
|
||||
log.warn("gitweb not installed (no " + pkgCgi + " found)");
|
||||
cgi = null;
|
||||
resourcePaths = new String[] {};
|
||||
}
|
||||
|
||||
Path css = null;
|
||||
Path js = null;
|
||||
Path logo = null;
|
||||
for (String path : resourcePaths) {
|
||||
Path dir = Paths.get(path);
|
||||
css = dir.resolve("gitweb.css");
|
||||
js = dir.resolve("gitweb.js");
|
||||
logo = dir.resolve("git-logo.png");
|
||||
if (isRegularFile(css) && isRegularFile(logo)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgUrl == null || cfgUrl.isEmpty()) {
|
||||
url = cgi != null ? "gitweb" : null;
|
||||
} else {
|
||||
url = cgi != null ? cfgUrl : null;
|
||||
}
|
||||
gitweb_cgi = cgi;
|
||||
gitweb_css = css;
|
||||
gitweb_js = js;
|
||||
git_logo_png = logo;
|
||||
}
|
||||
|
||||
/** @return GitWebType for gitweb viewer. */
|
||||
public GitWebType getGitWebType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return URL of the entry point into gitweb. This URL may be relative to our
|
||||
* context if gitweb is hosted by ourselves; or absolute if its hosted
|
||||
* elsewhere; or null if gitweb has not been configured.
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/** @return local path to the CGI executable; null if we shouldn't execute. */
|
||||
public Path getGitwebCGI() {
|
||||
return gitweb_cgi;
|
||||
}
|
||||
|
||||
/** @return local path of the {@code gitweb.css} matching the CGI. */
|
||||
public Path getGitwebCSS() {
|
||||
return gitweb_css;
|
||||
}
|
||||
|
||||
/** @return local path of the {@code gitweb.js} for the CGI. */
|
||||
public Path getGitwebJS() {
|
||||
return gitweb_js;
|
||||
}
|
||||
|
||||
/** @return local path of the {@code git-logo.png} for the CGI. */
|
||||
public Path getGitLogoPNG() {
|
||||
return git_logo_png;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given character can be used unencoded in an URL as a
|
||||
* replacement for the path separator '/'.
|
||||
*
|
||||
* Reasoning: http://www.ietf.org/rfc/rfc1738.txt § 2.2:
|
||||
*
|
||||
* ... only alphanumerics, the special characters "$-_.+!*'(),", and
|
||||
* reserved characters used for their reserved purposes may be used
|
||||
* unencoded within a URL.
|
||||
*
|
||||
* The following characters might occur in file names, however:
|
||||
*
|
||||
* alphanumeric characters,
|
||||
*
|
||||
* "$-_.+!',"
|
||||
*/
|
||||
static boolean isValidPathSeparator(char c) {
|
||||
switch (c) {
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@ package com.google.gerrit.httpd;
|
||||
import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.webui.WebUiPlugin;
|
||||
import com.google.gerrit.httpd.auth.become.BecomeAnyAccountModule;
|
||||
@@ -31,12 +30,11 @@ import com.google.gerrit.server.RemotePeer;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.config.GerritRequestModule;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.git.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.util.GuiceRequestScopePropagator;
|
||||
import com.google.gerrit.server.util.RequestScopePropagator;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.servlet.RequestScoped;
|
||||
|
||||
@@ -49,21 +47,14 @@ public class WebModule extends LifecycleModule {
|
||||
private final GerritOptions options;
|
||||
|
||||
@Inject
|
||||
WebModule(final AuthConfig authConfig,
|
||||
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
||||
WebModule(AuthConfig authConfig,
|
||||
@CanonicalWebUrl @Nullable String canonicalUrl,
|
||||
GerritOptions options,
|
||||
final Injector creatingInjector) {
|
||||
GitWebConfig gitWebConfig) {
|
||||
this.authConfig = authConfig;
|
||||
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
||||
this.options = options;
|
||||
|
||||
this.gitWebConfig =
|
||||
creatingInjector.createChildInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GitWebConfig.class);
|
||||
}
|
||||
}).getInstance(GitWebConfig.class);
|
||||
this.gitWebConfig = gitWebConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,13 +75,10 @@ public class WebModule extends LifecycleModule {
|
||||
install(new GerritRequestModule());
|
||||
install(new GitOverHttpServlet.Module(options.enableMasterFeatures()));
|
||||
|
||||
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
||||
if (gitWebConfig.getGitwebCGI() != null) {
|
||||
install(new GitWebModule());
|
||||
}
|
||||
|
||||
bind(GerritConfigProvider.class);
|
||||
bind(GerritConfig.class).toProvider(GerritConfigProvider.class);
|
||||
DynamicSet.setOf(binder(), WebUiPlugin.class);
|
||||
|
||||
install(new AsyncReceiveCommits.Module());
|
||||
|
@@ -17,7 +17,7 @@ package com.google.gerrit.httpd.gitweb;
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
@@ -16,8 +16,8 @@ package com.google.gerrit.httpd.gitweb;
|
||||
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.httpd.HtmlDomUtil;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.gwtjsonrpc.server.RPCServletUtils;
|
||||
|
@@ -17,7 +17,7 @@ package com.google.gerrit.httpd.gitweb;
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
@@ -32,23 +32,25 @@ package com.google.gerrit.httpd.gitweb;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.ssh.SshInfo;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -96,12 +98,14 @@ class GitWebServlet extends HttpServlet {
|
||||
private final EnvList _env;
|
||||
|
||||
@Inject
|
||||
GitWebServlet(final LocalDiskRepositoryManager repoManager,
|
||||
final ProjectControl.Factory projectControl,
|
||||
final Provider<AnonymousUser> anonymousUserProvider,
|
||||
final Provider<CurrentUser> userProvider,
|
||||
final SitePaths site,
|
||||
final GerritConfig gerritConfig, final GitWebConfig gitWebConfig)
|
||||
GitWebServlet(LocalDiskRepositoryManager repoManager,
|
||||
ProjectControl.Factory projectControl,
|
||||
Provider<AnonymousUser> anonymousUserProvider,
|
||||
Provider<CurrentUser> userProvider,
|
||||
SitePaths site,
|
||||
@GerritServerConfig Config cfg,
|
||||
SshInfo sshInfo,
|
||||
GitWebConfig gitWebConfig)
|
||||
throws IOException {
|
||||
this.repoManager = repoManager;
|
||||
this.projectControl = projectControl;
|
||||
@@ -128,7 +132,7 @@ class GitWebServlet extends HttpServlet {
|
||||
deniedActions.add("project_index");
|
||||
|
||||
_env = new EnvList();
|
||||
makeSiteConfig(site, gerritConfig);
|
||||
makeSiteConfig(site, cfg, sshInfo);
|
||||
|
||||
if (!_env.envMap.containsKey("SystemRoot")) {
|
||||
String os = System.getProperty("os.name");
|
||||
@@ -146,8 +150,8 @@ class GitWebServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private void makeSiteConfig(final SitePaths site,
|
||||
final GerritConfig gerritConfig) throws IOException {
|
||||
private void makeSiteConfig(SitePaths site, Config cfg, SshInfo sshInfo)
|
||||
throws IOException {
|
||||
if (!Files.exists(site.tmp_dir)) {
|
||||
Files.createDirectories(site.tmp_dir);
|
||||
}
|
||||
@@ -231,8 +235,8 @@ class GitWebServlet extends HttpServlet {
|
||||
|
||||
// Generate URLs using anonymous git://
|
||||
//
|
||||
if (gerritConfig.getGitDaemonUrl() != null) {
|
||||
String url = gerritConfig.getGitDaemonUrl();
|
||||
String url = cfg.getString("gerrit", null, "canonicalGitUrl");
|
||||
if (url != null) {
|
||||
if (url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
@@ -245,8 +249,8 @@ class GitWebServlet extends HttpServlet {
|
||||
|
||||
// Generate URLs using authenticated ssh://
|
||||
//
|
||||
if (gerritConfig.getSshdAddress() != null) {
|
||||
String sshAddr = gerritConfig.getSshdAddress();
|
||||
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
||||
String sshAddr = sshInfo.getHostKeys().get(0).getHost();
|
||||
p.print("if ($ENV{'GERRIT_USER_NAME'}) {\n");
|
||||
p.print(" push @git_base_url_list, join('', 'ssh://'");
|
||||
p.print(", $ENV{'GERRIT_USER_NAME'}");
|
||||
|
@@ -22,7 +22,6 @@ import com.google.common.hash.Hasher;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.common.data.HostPageData;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
@@ -77,7 +76,6 @@ public class HostPageServlet extends HttpServlet {
|
||||
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final DynamicItem<WebSession> session;
|
||||
private final GerritConfig config;
|
||||
private final DynamicSet<WebUiPlugin> plugins;
|
||||
private final DynamicSet<MessageOfTheDay> messages;
|
||||
private final HostPageData.Theme signedOutTheme;
|
||||
@@ -92,18 +90,20 @@ public class HostPageServlet extends HttpServlet {
|
||||
private volatile Page page;
|
||||
|
||||
@Inject
|
||||
HostPageServlet(final Provider<CurrentUser> cu, final DynamicItem<WebSession> w,
|
||||
final SitePaths sp, final ThemeFactory themeFactory,
|
||||
final GerritConfig gc, final ServletContext servletContext,
|
||||
final DynamicSet<WebUiPlugin> webUiPlugins,
|
||||
final DynamicSet<MessageOfTheDay> motd,
|
||||
@GerritServerConfig final Config cfg,
|
||||
final StaticServlet ss,
|
||||
final NotesMigration migration)
|
||||
HostPageServlet(
|
||||
Provider<CurrentUser> cu,
|
||||
DynamicItem<WebSession> w,
|
||||
SitePaths sp,
|
||||
ThemeFactory themeFactory,
|
||||
ServletContext servletContext,
|
||||
DynamicSet<WebUiPlugin> webUiPlugins,
|
||||
DynamicSet<MessageOfTheDay> motd,
|
||||
@GerritServerConfig Config cfg,
|
||||
StaticServlet ss,
|
||||
NotesMigration migration)
|
||||
throws IOException, ServletException {
|
||||
currentUser = cu;
|
||||
session = w;
|
||||
config = gc;
|
||||
plugins = webUiPlugins;
|
||||
messages = motd;
|
||||
signedOutTheme = themeFactory.getSignedOutTheme();
|
||||
@@ -323,7 +323,6 @@ public class HostPageServlet extends HttpServlet {
|
||||
|
||||
final HostPageData pageData = new HostPageData();
|
||||
pageData.version = Version.getVersion();
|
||||
pageData.config = config;
|
||||
pageData.isNoteDbEnabled = isNoteDbEnabled;
|
||||
pageData.pluginsLoadTimeout = pluginsLoadTimeout;
|
||||
|
||||
|
@@ -16,7 +16,6 @@ package com.google.gerrit.httpd.rpc;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.common.data.SshHostKey;
|
||||
import com.google.gerrit.common.data.SystemInfoService;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -46,16 +45,14 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
|
||||
private final List<HostKey> hostKeys;
|
||||
private final Provider<HttpServletRequest> httpRequest;
|
||||
private final Provider<GerritConfig> config;
|
||||
private final ProjectCache projectCache;
|
||||
|
||||
@Inject
|
||||
SystemInfoServiceImpl(final SshInfo daemon,
|
||||
final Provider<HttpServletRequest> hsr, final Provider<GerritConfig> cfg,
|
||||
final ProjectCache pc) {
|
||||
SystemInfoServiceImpl(SshInfo daemon,
|
||||
Provider<HttpServletRequest> hsr,
|
||||
ProjectCache pc) {
|
||||
hostKeys = daemon.getHostKeys();
|
||||
httpRequest = hsr;
|
||||
config = cfg;
|
||||
projectCache = pc;
|
||||
}
|
||||
|
||||
@@ -95,9 +92,4 @@ class SystemInfoServiceImpl implements SystemInfoService {
|
||||
log.error("Client UI JavaScript error: User-Agent=" + ua + ": " + message);
|
||||
callback.onSuccess(VoidResult.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gerritConfig(final AsyncCallback<GerritConfig> callback) {
|
||||
callback.onSuccess(config.get());
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2011 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.httpd;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GitWebConfigTest {
|
||||
|
||||
private static final String VALID_CHARACTERS = "*()";
|
||||
private static final String SOME_INVALID_CHARACTERS = "09AZaz$-_.+!',";
|
||||
|
||||
@Test
|
||||
public void testValidPathSeparator() {
|
||||
for(char c : VALID_CHARACTERS.toCharArray()) {
|
||||
assertTrue("valid character rejected: " + c, GitWebConfig.isValidPathSeparator(c));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInalidPathSeparator() {
|
||||
for(char c : SOME_INVALID_CHARACTERS.toCharArray()) {
|
||||
assertFalse("invalid character accepted: " + c, GitWebConfig.isValidPathSeparator(c));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user