From 2c32fd202bac23df456d6515f1c33443cc803f35 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 13 Sep 2011 08:10:03 -0400
Subject: [PATCH] Revised federation setting names.  Improved documentation.

---
 src/com/gitblit/FederationServlet.java      |    5 +
 src/com/gitblit/GitBlit.java                |   25 ++++---
 docs/02_federation.mkd                      |   83 +++++++++++++++++++++++----
 docs/04_releases.mkd                        |    4 
 src/com/gitblit/FederationPullExecutor.java |    2 
 src/com/gitblit/models/FederationModel.java |    2 
 distrib/gitblit.properties                  |   47 +++++++--------
 docs/00_index.mkd                           |    4 
 8 files changed, 116 insertions(+), 56 deletions(-)

diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties
index ebdd0b0..5ea43cd 100644
--- a/distrib/gitblit.properties
+++ b/distrib/gitblit.properties
@@ -317,7 +317,30 @@
 #
 # *git.enableGitServlet* must be true to use this feature.
 
+# Your federation name is used for federation status acknowledgments.  If it is
+# unset, and you elect to send a status acknowledgment, your Gitblit instance
+# will be identified by its hostname, if available, else your internal ip address.
+# The source Gitblit instance will also append your external IP address to your
+# identification to differentiate multiple pulling systems behind a single proxy.
 #
+# SINCE 0.6.0
+federation.name =
+
+# Specify the passphrase of this Gitblit instance.
+#
+# An unspecified (empty) passphrase disables processing federation requests.
+#
+# This value can be anything you want: an integer, a sentence, an haiku, etc.
+# Keep the value simple, though, to avoid Java properties file encoding issues.
+#
+# Changing your passphrase will break any registrations you have established with other
+# Gitblit instances.
+#
+# CASE-SENSITIVE
+# SINCE 0.6.0
+# RESTART REQUIRED
+federation.passphrase =
+
 # Control whether or not this Gitblit instance can receive federation proposals
 # from another Gitblit instance.  Registering a federated Gitblit is a manual
 # process.  Proposals help to simplify that process by allowing a remote Gitblit
@@ -336,30 +359,6 @@
 #
 # SINCE 0.6.0
 federation.defaultFrequency = 60 mins
-
-# Specify the unique id of this Gitblit instance.
-#
-# An unspecified (empty) uuid disables procesing federation requests.
-#
-# This value can be anything you want: an integer, a sentence, an haiku, etc.
-# Keep the value simple, though, to avoid Java properties file encoding issues.
-#
-# Changing your uuid will break any registrations you have established with other
-# Gitblit instances.
-#
-# CASE-SENSITIVE
-# SINCE 0.6.0
-# RESTART REQUIRED
-federation.uuid =
-
-# Your federation name is used for federation status acknowledgments.  If it is
-# unset, and you elect to send a status acknowledgment, your Gitblit instance
-# will be identified by its hostname, if available, else your internal ip address.
-# The source Gitblit instance will also append your external IP address to your
-# identification to differentiate multiple pulling systems behind a single proxy.
-#
-# SINCE 0.6.0
-federation.name = 
 
 # Federation pull registrations
 # Registrations are read once, at startup.
diff --git a/docs/00_index.mkd b/docs/00_index.mkd
index 3a6e540..5338634 100644
--- a/docs/00_index.mkd
+++ b/docs/00_index.mkd
@@ -25,11 +25,11 @@
 
 - added: federation feature to allow gitblit instances to pull repositories and, optionally, settings and accounts from other gitblit instances.<br/>
 This is something like svn-sync for gitblit.
+<br/>**New:** *federation.name =*
+<br/>**New:** *federation.passphrase =*
 <br/>**New:** *federation.allowProposals = false*
 <br/>**New:** *federation.proposalsFolder = proposals*
 <br/>**New:** *federation.defaultFrequency = 60 mins*
-<br/>**New:** *federation.uuid =*
-<br/>**New:** *federation.name =*
 <br/>**New:** *mail.* settings for sending emails
 <br/>**New:** user role *#notfederated* to prevent a user account from being pulled by a federated Gitblit instance
 - added: google-gson dependency
diff --git a/docs/02_federation.mkd b/docs/02_federation.mkd
index 2d174a6..1eb1bbb 100644
--- a/docs/02_federation.mkd
+++ b/docs/02_federation.mkd
@@ -9,21 +9,21 @@
 ### Source Gitblit Instance Requirements
 
 - *git.enableGitServlet* must be true, all Git clone and pull requests are handled through Gitblit's JGit servlet
-- *federation.uuid* must be non-empty
+- *federation.passphrase* must be non-empty
 - The Gitblit source instance must be http/https accessible by the pulling Gitblit instance.<br/>That may require configuring port-forwarding on your router and/or opening ports on your firewall.
 
-#### federation.uuid
+#### federation.passphrase
 
-The uuid is used to generate permission tokens that can be shared with other Gitblit instances.
+The passphrase is used to generate permission tokens that can be shared with other Gitblit instances.
 
-The uuid value never needs to be shared, although if you give another Gitblit instance the *ALL* federation token then your uuid will be transferred/backed-up along with all other server settings. 
+The passphrase value never needs to be shared, although if you give another Gitblit instance the *ALL* federation token then your passphrase will be transferred/backed-up along with all other server settings.
 
-This value can be anything you want: an integer, a sentence, an haiku, etc.  You should probably keep the uuid simple and use standard Latin characters to prevent Java properties file encoding errors.  The tokens generated from this value are affected by case, so consider this value CASE-SENSITIVE.
+This value can be anything you want: an integer, a sentence, an haiku, etc.  You should probably keep the passphrase simple and use standard Latin characters to prevent Java properties file encoding errors.  The tokens generated from this value are affected by case, so consider this value CASE-SENSITIVE.
 
-The federation feature is completely disabled if your uuid value is empty.
+The federation feature is completely disabled if your passphrase value is empty.
 
 **NOTE**:<br/>
-Changing your *federation.uuid* will break any registrations you have established with other Gitblit instances.
+Changing your *federation.passphrase* will break any registrations you have established with other Gitblit instances.
 
 ### Pulling Gitblit Instance Requirements
 
@@ -36,9 +36,9 @@
 
 Gitblit generates the following federation tokens:
 %BEGINCODE%
-String allToken = SHA1(uuid + "-ALL");
-String usersAndRepositoriesToken = SHA1(uuid + "-USERS_AND_REPOSITORIES");
-String repositoriesToken = SHA1(uuid + "-REPOSITORIES");
+String allToken = SHA1(passphrase + "-ALL");
+String usersAndRepositoriesToken = SHA1(passphrase + "-USERS_AND_REPOSITORIES");
+String repositoriesToken = SHA1(passphrase + "-REPOSITORIES");
 %ENDCODE%
     
 The *ALL* token allows another Gitblit instance to pull all your repositories, user accounts, and server settings.<br/>
@@ -47,12 +47,12 @@
 
 Individual Gitblit repository configurations such as *description* and *accessRestriction* are always mirrored.
 
-If *federation.uuid* has a non-empty value, the federation tokens are displayed in the log file and are visible, to administrators, in the web ui.
+If *federation.passphrase* has a non-empty value, the federation tokens are displayed in the log file and are visible, to administrators, in the web ui.
 
 
 ### Federation Proposals (Source Gitblit Instance)
 
-Once you have properly setup your uuid and can see your federation tokens, you are ready to share them with a pulling Gitblit instance.
+Once you have properly setup your passphrase and can see your federation tokens, you are ready to share them with a pulling Gitblit instance.
  
 The registration process can be partially automated by sending a *federation proposal* to another Gitblit instance.<br/>
 To send a proposal:
@@ -115,7 +115,7 @@
 
 The federation process executes using an internal administrator account, *$gitblit*.  All the normal authentication and authorization processes are used for federation requests. For example, Git commands are authenticated as *$gitblit / token*.
 
-While the *$gitblit* account has access to all repositories, server settings, and user accounts, it is prohibited from accessing the web ui and it is disabled if *federation.uuid* is empty.
+While the *$gitblit* account has access to all repositories, server settings, and user accounts, it is prohibited from accessing the web ui and it is disabled if *federation.passphrase* is empty.
 
 The federation feature should be considered a backdoor and enabled or disabled as appropriate for your installation.
 
@@ -137,7 +137,7 @@
 
 #### User Accounts
 
-By default all user accounts except the *admin* account are automatically pulled when using the *ALL* token or the *USERS_AND_REPOSITORIES* token.  You may exclude a user account form being pulled by a federated Gitblit instance by checking *exclude form federation* in the edit user page.
+By default all user accounts except the *admin* account are automatically pulled when using the *ALL* token or the *USERS_AND_REPOSITORIES* token.  You may exclude a user account form being pulled by a federated Gitblit instance by checking *exclude from federation* in the edit user page.
 
 The pulling Gitblit instance will store a registration-specific `users.properties` file for the pulled user accounts and their repository permissions. This file is stored in the *federation.N.folder* folder.
 
@@ -163,6 +163,60 @@
 
 By default, federated repositories can not be pushed to, they are read-only by the *isFrozen* flag.  This flag is **ONLY** enforced by Gitblit's JGit servlet.  If you push to a federated repository after resetting the *isFrozen* flag or via some other Git access technique then you may break Gitblit's ability to continue pulling from the source repository.  If you are only pushing to a local branch then you might be safe.
 
+## Federation Pull Registration Keys
+
+<table>
+<tr><th>federation.N.url</th>
+<td>string</td>
+<td>the url of the source Gitblit instance</td>
+</tr>
+
+<tr><th>federation.N.token</th>
+<td>string</td>
+<td>the token provided by the source Gitblit instance</td>
+</tr>
+
+<tr><th>federation.N.frequency</th>
+<td>N [mins/hours/days]</td>
+<td>the period to wait between pull executions</td>
+</tr>
+
+<tr><th>federation.N.folder</th>
+<td>string</td>
+<td>the destination folder, relative to *git.repositoriesFolder*, for these repositories.  If empty, the repositories are put in *git.repositoriesFolder*.</td>
+</tr>
+
+<tr><th>federation.N.mergeAccounts</th>
+<td>boolean</td>
+<td>merge the retrieved accounts into the `users.properties` of **this** Gitblit instance</td>
+</tr>
+
+<tr><th>federation.N.sendStatus</th>
+<td>boolean</td>
+<td>send the status of the federated pull to the source Gitblit instance</td>
+</tr>
+
+<tr><th>federation.N.freeze</th>
+<td>boolean</td>
+<td>freeze the repository at the end of each pull</td>
+</tr>
+
+<tr><th>federation.N.include</th>
+<td>string array<br/>(space separated)</td>
+<td>list of included repositories *(wildcard and fuzzy matching supported)*</td>
+</tr>
+
+<tr><th>federation.N.exclude</th>
+<td>string array<br/>(space separated)</td>
+<td>list of excluded repositories *(wildcard and fuzzy matching supported)*</td>
+</tr>
+
+<tr><th>federation.N.notifyOnError</th>
+<td>boolean</td>
+<td>send an email to the administrators on an error</td>
+</tr>
+</table>
+
 ## Example Federation Pull Registrations
 
 These examples would be entered into the `gitblit.properties` file of the pulling gitblit instance.
@@ -180,6 +234,7 @@
     federation.example1.folder = 
     federation.example1.mergeAccounts = true
     federation.example1.sendStatus = true
+    federation.example1.freeze = true
     
 #### Just Repositories Example
 
diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd
index a8f64a4..01296b0 100644
--- a/docs/04_releases.mkd
+++ b/docs/04_releases.mkd
@@ -5,11 +5,11 @@
 
 - added: federation feature to allow gitblit instances to pull repositories and, optionally, settings and accounts from other gitblit instances.<br/>
 This is something like svn-sync for gitblit.
+<br/>**New:** *federation.name =*
+<br/>**New:** *federation.passphrase =*
 <br/>**New:** *federation.allowProposals = false*
 <br/>**New:** *federation.proposalsFolder = proposals*
 <br/>**New:** *federation.defaultFrequency = 60 mins*
-<br/>**New:** *federation.uuid =*
-<br/>**New:** *federation.name =*
 <br/>**New:** *mail.* settings for sending emails
 <br/>**New:** user role *#notfederated* to prevent a user account from being pulled by a federated Gitblit instance
 - added: google-gson dependency
diff --git a/src/com/gitblit/FederationPullExecutor.java b/src/com/gitblit/FederationPullExecutor.java
index 127e1fc..9a1c3cf 100644
--- a/src/com/gitblit/FederationPullExecutor.java
+++ b/src/com/gitblit/FederationPullExecutor.java
@@ -184,7 +184,7 @@
 			if (result.createdRepository) {
 				// default local settings
 				repository.federationStrategy = FederationStrategy.EXCLUDE;
-				repository.isFrozen = true;
+				repository.isFrozen = registration.freeze;
 			} else {
 				// preserve local settings
 				repository.isFrozen = rm.isFrozen;
diff --git a/src/com/gitblit/FederationServlet.java b/src/com/gitblit/FederationServlet.java
index b8b6408..86aadb0 100644
--- a/src/com/gitblit/FederationServlet.java
+++ b/src/com/gitblit/FederationServlet.java
@@ -117,9 +117,10 @@
 			return;
 		}
 
-		String uuid = GitBlit.getString(Keys.federation.uuid, "");
+		String uuid = GitBlit.getString(Keys.federation.passphrase, "");
 		if (StringUtils.isEmpty(uuid)) {
-			logger.warn(Keys.federation.uuid + " is not properly set!  Federation request denied.");
+			logger.warn(Keys.federation.passphrase
+					+ " is not properly set!  Federation request denied.");
 			response.sendError(HttpServletResponse.SC_FORBIDDEN);
 			return;
 		}
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 7c49969..b32440b 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -794,8 +794,8 @@
 	}
 
 	public static boolean canFederate() {
-		String uuid = getString(Keys.federation.uuid, "");
-		return !StringUtils.isEmpty(uuid);
+		String passphrase = getString(Keys.federation.passphrase, "");
+		return !StringUtils.isEmpty(passphrase);
 	}
 
 	/**
@@ -803,13 +803,13 @@
 	 * instances.
 	 */
 	private void configureFederation() {
-		boolean validUuid = true;
-		String uuid = settings.getString(Keys.federation.uuid, "");
-		if (StringUtils.isEmpty(uuid)) {
-			logger.warn("Federation UUID is blank! This server can not be PULLED from.");
-			validUuid = false;
+		boolean validPassphrase = true;
+		String passphrase = settings.getString(Keys.federation.passphrase, "");
+		if (StringUtils.isEmpty(passphrase)) {
+			logger.warn("Federation passphrase is blank! This server can not be PULLED from.");
+			validPassphrase = false;
 		}
-		if (validUuid) {
+		if (validPassphrase) {
 			for (FederationToken tokenType : FederationToken.values()) {
 				logger.info(MessageFormat.format("Federation {0} token = {1}", tokenType.name(),
 						getFederationToken(tokenType)));
@@ -834,7 +834,7 @@
 		if (federationRegistrations.isEmpty()) {
 			List<String> keys = settings.getAllKeys(Keys.federation._ROOT);
 			keys.remove(Keys.federation.name);
-			keys.remove(Keys.federation.uuid);
+			keys.remove(Keys.federation.passphrase);
 			keys.remove(Keys.federation.allowProposals);
 			keys.remove(Keys.federation.proposalsFolder);
 			keys.remove(Keys.federation.defaultFrequency);
@@ -860,6 +860,9 @@
 				} else if (setting.equals("folder")) {
 					// destination folder of the pull operation
 					federatedModels.get(server).folder = settings.getString(key, "");
+				} else if (setting.equals("freeze")) {
+					// set the repository to read-only after pull
+					federatedModels.get(server).freeze = settings.getBoolean(key, true);
 				} else if (setting.equals("mergeAccounts")) {
 					// merge remote accounts into local accounts
 					federatedModels.get(server).mergeAccounts = settings.getBoolean(key, false);
@@ -946,8 +949,8 @@
 	 * @return a federation token
 	 */
 	public String getFederationToken(FederationToken type) {
-		String uuid = settings.getString(Keys.federation.uuid, "");
-		return StringUtils.getSHA1(uuid + "-" + type.name());
+		String passphrase = settings.getString(Keys.federation.passphrase, "");
+		return StringUtils.getSHA1(passphrase + "-" + type.name());
 	}
 
 	/**
diff --git a/src/com/gitblit/models/FederationModel.java b/src/com/gitblit/models/FederationModel.java
index 017c2e0..97a93d0 100644
--- a/src/com/gitblit/models/FederationModel.java
+++ b/src/com/gitblit/models/FederationModel.java
@@ -46,6 +46,8 @@
 
 	public String folder;
 
+    public boolean freeze;
+
 	public boolean mergeAccounts;
 
 	public boolean sendStatus;

--
Gitblit v1.9.1