Respect download.scheme in clone links Gitblit-plugin did not respect gerrit.config's download.scheme settings when passing web.otherUrls to Gitblit. This change attempts to evaluate download.scheme when populating web.otherUrls. This is only interpretting download.scheme when it is: not provided, http, or ssh. Change-Id: Ife13c7a93aa8e1848a08429555ae1f61c0479895
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java index 8367e79..75c681d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java +++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java
@@ -17,6 +17,8 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.List; import org.eclipse.jgit.lib.Config; import org.slf4j.Logger; @@ -34,17 +36,23 @@ private String canonicalWebUrlString; private String sshdListenAddressString; private String httpdListenUrlString; + private List<String> downloadSchemes; public GitBlitUrlsConfig(Config config) { canonicalWebUrlString = config.getString("gerrit", null, "canonicalWebUrl"); sshdListenAddressString = config.getString("sshd", null, "listenAddress"); httpdListenUrlString = config.getString("httpd", null, "listenUrl"); + downloadSchemes = Arrays.asList(config.getStringList("download", null, "scheme")); } public String getGitSshUrl() { if (sshdListenAddressString == null) { return ""; } + if (!downloadSchemes.isEmpty() && !downloadSchemes.contains("ssh")) { + return ""; + } + String[] urlParts = sshdListenAddressString.split(":"); if (urlParts.length < 2) { log.error("Invalid SSHD listenUrl: " + sshdListenAddressString); @@ -87,6 +95,9 @@ if (httpListenUrl == null) { return ""; } + if (!downloadSchemes.isEmpty() && !downloadSchemes.contains("http")) { + return ""; + } String httpUrl = Objects.firstNonNull(canonicalWebUrlString, httpListenUrl); httpUrl = httpUrl.replace("://", "://" + GITBLIT_USER + "@");