Merge "Merge branch 'stable-2.11'"
diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt
index 0ee6966..b32f58e 100644
--- a/Documentation/rest-api-config.txt
+++ b/Documentation/rest-api-config.txt
@@ -30,6 +30,87 @@
"2.7"
----
+[[get-info]]
+=== Get Server Info
+--
+'GET /config/server/info'
+--
+
+Returns the information about the Gerrit server configuration.
+
+.Request
+----
+ GET /config/server/info HTTP/1.0
+----
+
+As result a link:#server-info[ServerInfo] entity is returned.
+
+.Response
+----
+ HTTP/1.1 200 OK
+ Content-Type: application/json; charset=UTF-8
+
+ )]}'
+ {
+ "auth": {
+ "auth_type": "LDAP",
+ "editable_account_fields": [
+ "FULL_NAME",
+ "REGISTER_NEW_EMAIL"
+ ]
+ },
+ "download": {
+ "schemes": [
+ {
+ "name": "ssh",
+ "url": "ssh://jdoe@gerrithost:29418/${project}",
+ "is_auth_required": true,
+ "is_auth_supported": true,
+ "commands": {
+ "Checkout": "git fetch ssh://jdoe@gerrithost:29418/${project} ${ref} \u0026\u0026 git checkout FETCH_HEAD",
+ "Format Patch": "git fetch ssh://jdoe@gerrithost:29418/${project} ${ref} \u0026\u0026 git format-patch -1 --stdout FETCH_HEAD",
+ "Pull": "git pull ssh://jdoe@gerrithost:29418/${project} ${ref}",
+ "Cherry Pick": "git fetch ssh://jdoe@gerrithost:29418/${project} ${ref} \u0026\u0026 git cherry-pick FETCH_HEAD"
+ }
+ },
+ {
+ "name": "http",
+ "url": "http://jdoe@gerrithost:8080/${project}",
+ "is_auth_required": true,
+ "is_auth_supported": true,
+ "commands": {
+ "Checkout": "git fetch http://jdoe@gerrithost:8080/${project} ${ref} \u0026\u0026 git checkout FETCH_HEAD",
+ "Format Patch": "git fetch http://jdoe@gerrithost:8080/${project} ${ref} \u0026\u0026 git format-patch -1 --stdout FETCH_HEAD",
+ "Pull": "git pull http://jdoe@gerrithost:8080/${project} ${ref}",
+ "Cherry Pick": "git fetch http://jdoe@gerrithost:8080/${project} ${ref} \u0026\u0026 git cherry-pick FETCH_HEAD"
+ }
+ },
+ {
+ "name": "anonymous http",
+ "url": "http://gerrithost:8080/${project}",
+ "commands": {
+ "Checkout": "git fetch http://gerrithost:8080/${project} ${ref} \u0026\u0026 git checkout FETCH_HEAD",
+ "Format Patch": "git fetch http://gerrithost:8080/${project} ${ref} \u0026\u0026 git format-patch -1 --stdout FETCH_HEAD",
+ "Pull": "git pull http://gerrithost:8080/${project} ${ref}",
+ "Cherry Pick": "git fetch http://gerrithost:8080/${project} ${ref} \u0026\u0026 git cherry-pick FETCH_HEAD"
+ }
+ }
+ ],
+ "archives": [
+ "TGZ",
+ "TAR",
+ "TBZ2",
+ "TXZ"
+ ]
+ },
+ "gerrit": {
+ "all_projects": "All-Projects",
+ "all_users": "All-Users"
+ }
+ }
+----
+
+
[[list-caches]]
=== List Caches
--
@@ -822,6 +903,27 @@
[[json-entities]]
== JSON Entities
+[[auth-info]]
+=== AuthInfo
+The `AuthInfo` entity contains information about the authentication
+configuration of the Gerrit server.
+
+[options="header",cols="1,^1,5"]
+|==========================================
+|Field Name ||Description
+|`type` ||
+The link:config-gerrit.html#auth.type[authentication type] that is
+configured on the server. Can be `OPENID`, `OPENID_SSO`, `OAUTH`,
+`HTTP`, `HTTP_LDAP`, `CLIENT_SSL_CERT_LDAP`, `LDAP`, `LDAP_BIND`,
+`CUSTOM_EXTENSION` or `DEVELOPMENT_BECOME_ANY_ACCOUNT`.
+|`use_contributor_agreements` |not set if `false`|
+Whether link:config-gerrit.html#auth.contributorAgreements[contributor
+agreements] are required.
+|`editable_account_fields` ||
+List of account fields that are editable. Possible values are
+`FULL_NAME`, `USER_NAME` and `REGISTER_NEW_EMAIL`.
+|==========================================
+
[[cache-info]]
=== CacheInfo
The `CacheInfo` entity contains information about a cache.
@@ -878,6 +980,60 @@
|`name` |capability name
|=================================
+[[contact-store-info]]
+=== ContactStoreInfo
+The `ContactStoreInfo` entity contains information about the contact
+store.
+
+[options="header",cols="1,6"]
+|=======================
+|Field Name |Description
+|`url` |
+The link:config-gerrit.html#contactstore.url[URL of the contact store].
+|=======================
+
+[[download-info]]
+=== DownloadInfo
+The `DownloadInfo` entity contains information about supported download
+options.
+
+[options="header",cols="1,6"]
+|=======================
+|Field Name |Description
+|`schemes` |
+The supported download schemes as list of link:#download-scheme-info[
+DownloadSchemeInfo] entities.
+|`archives` |
+List of supported archive formats. Possible values are `TGZ`, `TAR`,
+`TBZ2` and `TXZ`.
+|=======================
+
+[[download-scheme-info]]
+=== DownloadSchemeInfo
+The `DownloadSchemeInfo` entity contains information about a supported
+download scheme and its commands.
+
+[options="header",cols="1,^1,5"]
+|=================================
+|Field Name ||Description
+|`name` ||
+The name of the download scheme.
+|`url` ||
+The URL of the download scheme, where '${project}' is used as
+placeholder for the project name.
+|`is_auth_required` |not set if `false`|
+Whether this download scheme requires authentication.
+|`is_auth_supported` |not set if `false`|
+Whether this download scheme supports authentication.
+|`commands` ||
+List of download commands, where '${project}' is used as
+placeholder for the project name, and '${ref}' is used as
+placeholder for the (change) ref.
+
+Empty, if accessed anonymously and the download scheme requires
+authentication.
+|=================================
+
[[entries-info]]
=== EntriesInfo
The `EntriesInfo` entity contains information about the entries in a
@@ -896,6 +1052,21 @@
`g`: gigabytes). Only set for disk caches.
|==================================
+[[gerrit-info]]
+=== GerritInfo
+The `GerritInfo` entity contains information about Gerrit
+configuration from the link:config-gerrit.html#gerrit[gerrit] section.
+
+[options="header",cols="1,6"]
+|================================
+|Field Name |Description
+|`all_projects_name` |
+Name of the link:config-gerrit.html#gerrit.allProjects[root project].
+|`all_users_name` |
+Name of the link:config-gerrit.html#gerrit.allUsers[project in which
+meta data of all users is stored].
+|================================
+
[[hit-ration-info]]
=== HitRatioInfo
The `HitRatioInfo` entity contains information about the hit ratio of a
@@ -958,6 +1129,30 @@
The number of open files.
|============================
+[[server-info]]
+=== ServerInfo
+The `ServerInfo` entity contains information about the configuration of
+the Gerrit server.
+
+[options="header",cols="1,^1,5"]
+|=======================================
+|Field Name ||Description
+|`auth` ||
+Information about the authentication configuration as
+link:#auth-info[AuthInfo] entity.
+|`contact_store` |optional|
+Information about the contact store configuration as
+link:#contact-store-info[ContactStoreInfo] entity.
+|`download` ||
+Information about the configured download options as
+link:#download-info[DownloadInfo] entity.
+information about Gerrit
+|`gerrit` ||
+Information about the configuration from the
+link:config-gerrit.html#gerrit[gerrit] section as link:#gerrit-info[
+GerritInfo] entity.
+|=======================================
+
[[summary-info]]
=== SummaryInfo
The `SummaryInfo` entity contains information about the current state
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
index 25c5321..114dba9 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
@@ -20,7 +20,6 @@
import com.google.common.collect.Lists;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.GitwebConfig;
-import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.change.ArchiveFormat;
import com.google.gerrit.server.change.GetArchive;
@@ -31,7 +30,6 @@
import com.google.gerrit.server.config.DownloadConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.contact.ContactStore;
-import com.google.gerrit.server.mail.EmailSender;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -40,8 +38,6 @@
import org.eclipse.jgit.lib.Config;
import java.net.MalformedURLException;
-import java.util.HashSet;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext;
@@ -56,7 +52,6 @@
private final AllProjectsName wildProject;
private final SshInfo sshInfo;
- private EmailSender emailSender;
private final ContactStore contactStore;
private final ServletContext servletContext;
private final String anonymousCowardName;
@@ -81,11 +76,6 @@
anonymousCowardName = acn;
}
- @Inject(optional = true)
- void setEmailSender(final EmailSender d) {
- emailSender = d;
- }
-
private GerritConfig create() throws MalformedURLException {
final GerritConfig config = new GerritConfig();
switch (authConfig.getAuthType()) {
@@ -118,8 +108,7 @@
break;
}
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
- config.setUseContributorAgreements(cfg.getBoolean("auth",
- "contributoragreements", false));
+ config.setUseContributorAgreements(authConfig.isUseContributorAgreements());
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
@@ -146,17 +135,7 @@
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
config.setReportBugText(cfg.getString("gerrit", null, "reportBugText"));
- final Set<Account.FieldName> fields = new HashSet<>();
- for (final Account.FieldName n : Account.FieldName.values()) {
- if (realm.allowsEdit(n)) {
- fields.add(n);
- }
- }
- if (emailSender != null && emailSender.isEnabled()
- && realm.allowsEdit(Account.FieldName.REGISTER_NEW_EMAIL)) {
- fields.add(Account.FieldName.REGISTER_NEW_EMAIL);
- }
- config.setEditableAccountFields(fields);
+ config.setEditableAccountFields(realm.getEditableFields());
if (gitWebConfig.getUrl() != null) {
config.setGitwebLink(new GitwebConfig(gitWebConfig.getUrl(), gitWebConfig
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
index dca850ac..ad2237e 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
@@ -46,7 +46,7 @@
import com.google.common.math.IntMath;
import com.google.common.net.HttpHeaders;
import com.google.gerrit.audit.AuditService;
-import com.google.gerrit.audit.HttpAuditEvent;
+import com.google.gerrit.audit.ExtendedHttpAuditEvent;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.registration.DynamicItem;
@@ -204,6 +204,8 @@
Object result = null;
Multimap<String, String> params = LinkedHashMultimap.create();
Object inputRequestBody = null;
+ RestResource rsrc = TopLevelResource.INSTANCE;
+ ViewData viewData = null;
try {
checkUserSession(req);
@@ -213,8 +215,8 @@
CapabilityUtils.checkRequiresCapability(globals.currentUser,
null, rc.getClass());
- RestResource rsrc = TopLevelResource.INSTANCE;
- ViewData viewData = new ViewData(null, null);
+ viewData = new ViewData(null, null);
+
if (path.isEmpty()) {
if (isGetOrHead(req)) {
viewData = new ViewData(null, rc.list());
@@ -386,10 +388,10 @@
status = SC_INTERNAL_SERVER_ERROR;
handleException(e, req, res);
} finally {
- globals.auditService.dispatch(new HttpAuditEvent(globals.webSession.get()
- .getSessionId(), globals.currentUser.get(), req.getRequestURI(),
- auditStartTs, params, req.getMethod(), inputRequestBody, status,
- result));
+ globals.auditService.dispatch(new ExtendedHttpAuditEvent(globals.webSession.get()
+ .getSessionId(), globals.currentUser.get(), req,
+ auditStartTs, params, inputRequestBody, status,
+ result, rsrc, viewData.view));
}
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/audit/ExtendedHttpAuditEvent.java b/gerrit-server/src/main/java/com/google/gerrit/audit/ExtendedHttpAuditEvent.java
new file mode 100644
index 0000000..78fe38c
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/audit/ExtendedHttpAuditEvent.java
@@ -0,0 +1,55 @@
+// Copyright (C) 2015 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.audit;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Multimap;
+import com.google.gerrit.extensions.restapi.RestResource;
+import com.google.gerrit.extensions.restapi.RestView;
+import com.google.gerrit.server.CurrentUser;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Extended audit event. Adds request, resource and view data to HttpAuditEvent.
+ */
+public class ExtendedHttpAuditEvent extends HttpAuditEvent {
+ public final HttpServletRequest httpRequest;
+ public final RestResource resource;
+ public final RestView<? extends RestResource> view;
+
+ /**
+ * Creates a new audit event with results
+ *
+ * @param sessionId session id the event belongs to
+ * @param who principal that has generated the event
+ * @param httpRequest the HttpServletRequest
+ * @param when time-stamp of when the event started
+ * @param params parameters of the event
+ * @param result result of the event
+ * @param resource REST resource data
+ * @param view view rendering object
+ */
+ public ExtendedHttpAuditEvent(String sessionId, CurrentUser who,
+ HttpServletRequest httpRequest, long when, Multimap<String, ?> params,
+ Object input, int status, Object result, RestResource resource,
+ RestView<RestResource> view) {
+ super(sessionId, who, httpRequest.getRequestURI(), when, params, httpRequest.getMethod(),
+ input, status, result);
+ this.httpRequest = Preconditions.checkNotNull(httpRequest);
+ this.resource = resource;
+ this.view = view;
+ }
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AbstractRealm.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AbstractRealm.java
index 7031672..d457555 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AbstractRealm.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AbstractRealm.java
@@ -16,15 +16,44 @@
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
+import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountExternalId;
+import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.server.IdentifiedUser;
+import com.google.gerrit.server.mail.EmailSender;
+import com.google.inject.Inject;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/** Basic implementation of {@link Realm}. */
public abstract class AbstractRealm implements Realm {
+ private EmailSender emailSender;
+
+ @Inject(optional = true)
+ void setEmailSender(EmailSender emailSender) {
+ this.emailSender = emailSender;
+ }
+
+ @Override
+ public Set<FieldName> getEditableFields() {
+ Set<Account.FieldName> fields = new HashSet<>();
+ for (Account.FieldName n : Account.FieldName.values()) {
+ if (allowsEdit(n)) {
+ if (n == Account.FieldName.REGISTER_NEW_EMAIL) {
+ if (emailSender != null && emailSender.isEnabled()) {
+ fields.add(n);
+ }
+ } else {
+ fields.add(n);
+ }
+ }
+ }
+ return fields;
+ }
+
@Override
public boolean hasEmailAddress(IdentifiedUser user, String email) {
for (AccountExternalId ext : user.state().getExternalIds()) {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/Realm.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/Realm.java
index 8dd8de7..056fa85b 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/Realm.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/Realm.java
@@ -24,6 +24,9 @@
/** Can the end-user modify this field of their own account? */
public boolean allowsEdit(Account.FieldName field);
+ /** Returns the account fields that the end-user can modify. */
+ public Set<Account.FieldName> getEditableFields();
+
public AuthRequest authenticate(AuthRequest who) throws AccountException;
public AuthRequest link(ReviewDb db, Account.Id to, AuthRequest who)
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java
index 9bd625d..73f9cab 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java
@@ -140,7 +140,7 @@
return deleteFileFactory.create(id.get());
}
- static class Create implements
+ public static class Create implements
RestModifyView<ChangeResource, Put.Input> {
interface Factory {
@@ -195,7 +195,7 @@
}
}
- static class DeleteFile implements
+ public static class DeleteFile implements
RestModifyView<ChangeResource, DeleteFile.Input> {
public static class Input {
}
@@ -407,7 +407,7 @@
* as reverting or restoring a file to its previous contents.
*/
@Singleton
- static class DeleteContent implements
+ public static class DeleteContent implements
RestModifyView<ChangeEditResource, DeleteContent.Input> {
public static class Input {
}
@@ -432,7 +432,7 @@
}
@Singleton
- static class Get implements RestReadView<ChangeEditResource> {
+ public static class Get implements RestReadView<ChangeEditResource> {
private final FileContentUtil fileContentUtil;
@Inject
@@ -455,7 +455,7 @@
}
@Singleton
- static class GetMeta implements RestReadView<ChangeEditResource> {
+ public static class GetMeta implements RestReadView<ChangeEditResource> {
private final WebLinks webLinks;
@Inject
@@ -481,8 +481,8 @@
return r;
}
- static class FileInfo {
- List<DiffWebLinkInfo> webLinks;
+ public static class FileInfo {
+ public List<DiffWebLinkInfo> webLinks;
}
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/FileResource.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/FileResource.java
index 1662237..ca47fb9 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/FileResource.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/FileResource.java
@@ -44,7 +44,7 @@
return rev.getAccountId();
}
- RevisionResource getRevision() {
+ public RevisionResource getRevision() {
return rev;
}
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java
index 913f69e..93d8567 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java
@@ -19,15 +19,13 @@
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.RestReadView;
-import com.google.gerrit.server.config.ConfigUtil;
-import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.config.DownloadConfig;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.api.ArchiveCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -36,11 +34,7 @@
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -51,28 +45,16 @@
final Set<ArchiveFormat> allowed;
@Inject
- AllowedFormats(@GerritServerConfig Config cfg) {
- Collection<ArchiveFormat> enabled;
- String v = cfg.getString("download", null, "archive");
- if (v == null) {
- enabled = Arrays.asList(ArchiveFormat.values());
- } else if (v.isEmpty() || "off".equalsIgnoreCase(v)) {
- enabled = Collections.emptyList();
- } else {
- enabled = ConfigUtil.getEnumList(cfg,
- "download", null, "archive",
- ArchiveFormat.TGZ);
- }
-
+ AllowedFormats(DownloadConfig cfg) {
Map<String, ArchiveFormat> exts = new HashMap<>();
- for (ArchiveFormat format : enabled) {
+ for (ArchiveFormat format : cfg.getArchiveFormats()) {
for (String ext : format.getSuffixes()) {
exts.put(ext, format);
}
exts.put(format.name().toLowerCase(), format);
}
extensions = ImmutableMap.copyOf(exts);
- allowed = Collections.unmodifiableSet(new LinkedHashSet<>(enabled));
+ allowed = cfg.getArchiveFormats();
}
public Set<ArchiveFormat> getAllowed() {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/RevisionResource.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/RevisionResource.java
index a18df5b..538f36b 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/RevisionResource.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/RevisionResource.java
@@ -92,7 +92,7 @@
return this;
}
- Optional<ChangeEdit> getEdit() {
+ public Optional<ChangeEdit> getEdit() {
return edit;
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/AuthConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/AuthConfig.java
index d7138b3..abcd441 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/config/AuthConfig.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/AuthConfig.java
@@ -44,6 +44,7 @@
private final boolean enableRunAs;
private final boolean userNameToLowerCase;
private final boolean gitBasicAuth;
+ private final boolean useContributorAgreements;
private final String loginUrl;
private final String logoutUrl;
private final String openIdSsoUrl;
@@ -75,6 +76,8 @@
trustContainerAuth = cfg.getBoolean("auth", "trustContainerAuth", false);
enableRunAs = cfg.getBoolean("auth", null, "enableRunAs", true);
gitBasicAuth = cfg.getBoolean("auth", "gitBasicAuth", false);
+ useContributorAgreements =
+ cfg.getBoolean("auth", "contributoragreements", false);
userNameToLowerCase = cfg.getBoolean("auth", "userNameToLowerCase", false);
@@ -194,6 +197,11 @@
return gitBasicAuth;
}
+ /** Whether contributor agreements are used. */
+ public boolean isUseContributorAgreements() {
+ return useContributorAgreements;
+ }
+
public boolean isIdentityTrustable(final Collection<AccountExternalId> ids) {
switch (getAuthType()) {
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java
index 2d9f21a..4986989 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java
@@ -16,12 +16,14 @@
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 @@
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 @@
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 Set<DownloadCommand> getDownloadCommands() {
return downloadCommands;
}
+
+ /** Archive formats for downloading. */
+ public Set<ArchiveFormat> getArchiveFormats() {
+ return archiveFormats;
+ }
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java
new file mode 100644
index 0000000..52bf7a5
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java
@@ -0,0 +1,168 @@
+// Copyright (C) 2015 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.config;
+
+import com.google.gerrit.extensions.config.DownloadCommand;
+import com.google.gerrit.extensions.config.DownloadScheme;
+import com.google.gerrit.extensions.registration.DynamicMap;
+import com.google.gerrit.extensions.restapi.RestReadView;
+import com.google.gerrit.reviewdb.client.Account;
+import com.google.gerrit.reviewdb.client.AuthType;
+import com.google.gerrit.server.account.Realm;
+import com.google.gerrit.server.change.ArchiveFormat;
+import com.google.inject.Inject;
+
+import org.eclipse.jgit.lib.Config;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class GetServerInfo implements RestReadView<ConfigResource> {
+ private final Config config;
+ private final AuthConfig authConfig;
+ private final Realm realm;
+ private final DownloadConfig downloadConfig;
+ private final DynamicMap<DownloadScheme> downloadSchemes;
+ private final DynamicMap<DownloadCommand> downloadCommands;
+ private final AllProjectsName allProjectsName;
+ private final AllUsersName allUsersName;
+
+ @Inject
+ public GetServerInfo(
+ @GerritServerConfig Config config,
+ AuthConfig authConfig,
+ Realm realm,
+ DownloadConfig downloadConfig,
+ DynamicMap<DownloadScheme> downloadSchemes,
+ DynamicMap<DownloadCommand> downloadCommands,
+ AllProjectsName allProjectsName,
+ AllUsersName allUsersName) {
+ this.config = config;
+ this.authConfig = authConfig;
+ this.realm = realm;
+ this.downloadConfig = downloadConfig;
+ this.downloadSchemes = downloadSchemes;
+ this.downloadCommands = downloadCommands;
+ this.allProjectsName = allProjectsName;
+ this.allUsersName = allUsersName;
+ }
+
+ @Override
+ public ServerInfo apply(ConfigResource rsrc) throws MalformedURLException {
+ ServerInfo info = new ServerInfo();
+ info.auth = new AuthInfo(authConfig, realm);
+ info.contactStore = getContactStoreInfo();
+ info.download =
+ new DownloadInfo(downloadConfig, downloadSchemes, downloadCommands);
+ info.gerrit = new GerritInfo(allProjectsName, allUsersName);
+ return info;
+ }
+
+ private ContactStoreInfo getContactStoreInfo() {
+ String url = config.getString("contactstore", null, "url");
+ if (url == null) {
+ return null;
+ }
+
+ ContactStoreInfo contactStore = new ContactStoreInfo();
+ contactStore.url = url;
+ return contactStore;
+ }
+
+ private static Boolean toBoolean(boolean v) {
+ return v ? v : null;
+ }
+
+ public static class ServerInfo {
+ public AuthInfo auth;
+ public ContactStoreInfo contactStore;
+ public DownloadInfo download;
+ public GerritInfo gerrit;
+ }
+
+ public static class AuthInfo {
+ public AuthType authType;
+ public Boolean useContributorAgreements;
+ public List<Account.FieldName> editableAccountFields;
+
+ public AuthInfo(AuthConfig cfg, Realm realm) {
+ authType = cfg.getAuthType();
+ useContributorAgreements = toBoolean(cfg.isUseContributorAgreements());
+ editableAccountFields = new ArrayList<>(realm.getEditableFields());
+ }
+ }
+
+ public static class ContactStoreInfo {
+ public String url;
+ }
+
+ public static class DownloadInfo {
+ public List<DownloadSchemeInfo> schemes;
+ public List<ArchiveFormat> archives;
+
+ public DownloadInfo(DownloadConfig downloadConfig,
+ DynamicMap<DownloadScheme> downloadSchemes,
+ DynamicMap<DownloadCommand> downloadCommands) {
+ schemes = new ArrayList<>();
+ for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
+ DownloadScheme scheme = e.getProvider().get();
+ if (scheme.isEnabled()) {
+ schemes.add(
+ new DownloadSchemeInfo(e.getExportName(), scheme, downloadCommands));
+ }
+ }
+ archives = new ArrayList<>(downloadConfig.getArchiveFormats());
+ }
+ }
+
+ public static class DownloadSchemeInfo {
+ public String name;
+ public String url;
+ public Boolean isAuthRequired;
+ public Boolean isAuthSupported;
+ public Map<String, String> commands;
+
+ public DownloadSchemeInfo(String schemeName, DownloadScheme scheme,
+ DynamicMap<DownloadCommand> downloadCommands) {
+ name = schemeName;
+ url = scheme.getUrl("${project}");
+ isAuthRequired = toBoolean(scheme.isAuthRequired());
+ isAuthSupported = toBoolean(scheme.isAuthSupported());
+
+ commands = new HashMap<>();
+ for (DynamicMap.Entry<DownloadCommand> e : downloadCommands) {
+ String commandName = e.getExportName();
+ DownloadCommand command = e.getProvider().get();
+ String c = command.getCommand(scheme, "${project}", "${ref}");
+ if (c != null) {
+ commands.put(commandName, c);
+ }
+ }
+ }
+ }
+
+ public static class GerritInfo {
+ public String allProjects;
+ public String allUsers;
+
+ public GerritInfo(AllProjectsName allProjectsName, AllUsersName allUsersName) {
+ allProjects = allProjectsName.get();
+ allUsers = allUsersName.get();
+ }
+ }
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/Module.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/Module.java
index 64848ba..31fdc1e 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/config/Module.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/Module.java
@@ -35,6 +35,7 @@
delete(TASK_KIND).to(DeleteTask.class);
child(CONFIG_KIND, "top-menus").to(TopMenuCollection.class);
get(CONFIG_KIND, "version").to(GetVersion.class);
+ get(CONFIG_KIND, "info").to(GetServerInfo.class);
get(CONFIG_KIND, "preferences").to(GetPreferences.class);
put(CONFIG_KIND, "preferences").to(SetPreferences.class);
}