From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit, gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command
---
src/com/gitblit/FederationServlet.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/src/com/gitblit/FederationServlet.java b/src/com/gitblit/FederationServlet.java
index 0be1066..e772050 100644
--- a/src/com/gitblit/FederationServlet.java
+++ b/src/com/gitblit/FederationServlet.java
@@ -15,20 +15,25 @@
*/
package com.gitblit;
+import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import com.gitblit.Constants.FederationRequest;
import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
+import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.FederationUtils;
+import com.gitblit.utils.FileUtils;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -90,7 +95,7 @@
if (proposal == null) {
return;
}
-
+
// reject proposal, if not receipt prohibited
if (!GitBlit.getBoolean(Keys.federation.allowProposals, false)) {
logger.error(MessageFormat.format("Rejected {0} federation proposal from {1}",
@@ -198,6 +203,58 @@
}
}
result = users;
+ } else if (FederationRequest.PULL_TEAMS.equals(reqType)) {
+ // pull teams
+ if (!GitBlit.self().validateFederationRequest(reqType, token)) {
+ // invalid token to pull teams
+ logger.warn(MessageFormat.format(
+ "Federation token from {0} not authorized to pull TEAMS",
+ request.getRemoteAddr()));
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+ List<String> teamnames = GitBlit.self().getAllTeamnames();
+ List<TeamModel> teams = new ArrayList<TeamModel>();
+ for (String teamname : teamnames) {
+ TeamModel user = GitBlit.self().getTeamModel(teamname);
+ teams.add(user);
+ }
+ result = teams;
+ } else if (FederationRequest.PULL_SCRIPTS.equals(reqType)) {
+ // pull scripts
+ if (!GitBlit.self().validateFederationRequest(reqType, token)) {
+ // invalid token to pull script
+ logger.warn(MessageFormat.format(
+ "Federation token from {0} not authorized to pull SCRIPTS",
+ request.getRemoteAddr()));
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+ Map<String, String> scripts = new HashMap<String, String>();
+
+ Set<String> names = new HashSet<String>();
+ names.addAll(GitBlit.getStrings(Keys.groovy.preReceiveScripts));
+ names.addAll(GitBlit.getStrings(Keys.groovy.postReceiveScripts));
+ for (TeamModel team : GitBlit.self().getAllTeams()) {
+ names.addAll(team.preReceiveScripts);
+ names.addAll(team.postReceiveScripts);
+ }
+ File scriptsFolder = GitBlit.getFileOrFolder(Keys.groovy.scriptsFolder, "groovy");
+ for (String name : names) {
+ File file = new File(scriptsFolder, name);
+ if (!file.exists() && !file.getName().endsWith(".groovy")) {
+ file = new File(scriptsFolder, name + ".groovy");
+ }
+ if (file.exists()) {
+ // read the script
+ String content = FileUtils.readContent(file, "\n");
+ scripts.put(name, content);
+ } else {
+ // missing script?!
+ logger.warn(MessageFormat.format("Failed to find push script \"{0}\"", name));
+ }
+ }
+ result = scripts;
}
}
--
Gitblit v1.9.1