Add REST endpoint to get info about server configuration

Some of the Gerrit configuration parameters can now be accessed by

  GET /config/server/info

This REST endpoint can also be used anonymously.

For now the REST endpoint returns only a very limited set of
configuration parameters, which are needed by the Gerrit Mylyn
Connector. The result contains information about:

- auth type, editable account fields, if contributor agreements are
  used
- contact store
- download schemes, commands and archive formats
- All-Projects and All-Users project names

At the moment the Mylyn Gerrit Connector retrieves this information by
parsing the config from the HostPageData which is sent to the client.
This is an internal data structure which is used to exchange
information between Gerrit server and Gerrit WebUI. It's not an API
and third-party tools should not rely on it. As a result the Mylyn
Gerrit Connector is currently broken for Gerrit 2.11 and newer.

Provide the Mylyn Gerrit Connector team a stable API that provides
them the information they need so that future breakages can be
avoided. See Eclipse Bugzilla issue 465132 [1] for further details.

The structure of the returned JSON correlates to the structure in the
gerrit.config file.

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=465132

Change-Id: Iac4be762bff971403438aa84923d9f0e11883366
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-04-30 12:55:34 +02:00
parent ed2064f05e
commit b8590bd990
9 changed files with 429 additions and 45 deletions

View File

@@ -16,12 +16,14 @@ package com.google.gerrit.server.config;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.server.change.ArchiveFormat;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -31,6 +33,7 @@ import java.util.Set;
public class DownloadConfig {
private final Set<DownloadScheme> downloadSchemes;
private final Set<DownloadCommand> downloadCommands;
private final Set<ArchiveFormat> archiveFormats;
@Inject
DownloadConfig(@GerritServerConfig final Config cfg) {
@@ -45,6 +48,17 @@ public class DownloadConfig {
DownloadCommand.DEFAULT_DOWNLOADS);
downloadCommands =
Collections.unmodifiableSet(new HashSet<>(allCommands));
String v = cfg.getString("download", null, "archive");
if (v == null) {
archiveFormats = EnumSet.allOf(ArchiveFormat.class);
} else if (v.isEmpty() || "off".equalsIgnoreCase(v)) {
archiveFormats = Collections.emptySet();
} else {
archiveFormats = new HashSet<>(ConfigUtil.getEnumList(cfg,
"download", null, "archive",
ArchiveFormat.TGZ));
}
}
/** Scheme used to download. */
@@ -56,4 +70,9 @@ public class DownloadConfig {
public Set<DownloadCommand> getDownloadCommands() {
return downloadCommands;
}
/** Archive formats for downloading. */
public Set<ArchiveFormat> getArchiveFormats() {
return archiveFormats;
}
}