Allow admins to configure URL aliases

This allows to map plugin screens into the Gerrit URL namespace, e.g.:

  [urlAlias "MyPluginScreen"]
    match = /myscreen/(.*)
    token = /x/myplugin/myscreen/$1

This can also be used to replace Gerrit screens with plugin screens,
e.g. to replace change screen:

  [urlAlias "MyChangeScreen"]
    match = /c/(.*)
    token = /x/myplugin/c/$1

Defining URL aliases is similar to defining comment links. This is why
a similar representation in the gerrit.config was chosen.

Change-Id: Ie4a3b69703629051f7627eeb0c479dfc964f27ae
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-07-16 12:38:52 +02:00
parent 8586292fcf
commit fa0d494d11
8 changed files with 140 additions and 1 deletions

View File

@@ -47,6 +47,10 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
public class GetServerInfo implements RestReadView<ConfigResource> {
private final static String URL_ALIAS = "urlAlias";
private final static String KEY_MATCH = "match";
private final static String KEY_TOKEN = "token";
private final Config config;
private final AuthConfig authConfig;
private final Realm realm;
@@ -102,6 +106,10 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
info.plugin = getPluginInfo();
info.sshd = getSshdInfo(config);
info.suggest = getSuggestInfo(config);
Map<String, String> urlAliases = getUrlAliasesInfo(config);
info.urlAliases = !urlAliases.isEmpty() ? urlAliases : null;
info.user = getUserInfo(anonymousCowardName);
info.receive = getReceiveInfo(config);
return info;
@@ -267,6 +275,15 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
return info;
}
private Map<String, String> getUrlAliasesInfo(Config cfg) {
Map<String, String> urlAliases = new HashMap<>();
for (String subsection : cfg.getSubsections(URL_ALIAS)) {
urlAliases.put(cfg.getString(URL_ALIAS, subsection, KEY_MATCH),
cfg.getString(URL_ALIAS, subsection, KEY_TOKEN));
}
return urlAliases;
}
private SshdInfo getSshdInfo(Config cfg) {
String[] addr = cfg.getStringList("sshd", null, "listenAddress");
if (addr.length == 1 && isOff(addr[0])) {
@@ -313,6 +330,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
public PluginConfigInfo plugin;
public SshdInfo sshd;
public SuggestInfo suggest;
public Map<String, String> urlAliases;
public UserConfigInfo user;
public ReceiveInfo receive;
}