You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/01/31 16:00:50 UTC

[1/2] mina-sshd git commit: [SSHD-797] Updated README documentation to reflect enhanced GitSshdSessionFactory capabilities and its usage with JGIT

Repository: mina-sshd
Updated Branches:
  refs/heads/master 2d6fbc94a -> 9a87c27e1


[SSHD-797] Updated README documentation to reflect enhanced GitSshdSessionFactory capabilities and its usage with JGIT


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/9a87c27e
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/9a87c27e
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/9a87c27e

Branch: refs/heads/master
Commit: 9a87c27e13a40f5dc43d3542ff5bb2f9e8d1970b
Parents: c645152
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Wed Jan 31 17:47:28 2018 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Wed Jan 31 18:00:43 2018 +0200

----------------------------------------------------------------------
 README.md | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9a87c27e/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 5cc741f..82e92d3 100644
--- a/README.md
+++ b/README.md
@@ -1333,7 +1333,38 @@ The distribution also includes also an _sshd_ script that can be used to launch
 
 ## GIT support
 
-The _sshd-git_ artifact contains server-side command factories for handling some _git_ commands - see `GitPackCommandFactory` and `GitPgmCommandFactory`. These command factories accept a delegate to which non-_git_ commands are routed:
+The _sshd-git_ artifact contains both client and server-side command factories for issuing and handling some _git_ commands. The code is based on [JGit](https://github.com/eclipse/jgit)
+and iteracts with it smoothly.
+
+### Client-side
+
+This module provides SSHD-based replacements for the SSH and SFTP transports used by the JGIT client - see `GitSshdSessionFactory` - it can be used as a drop-in replacement
+for the [JSCH](http://www.jcraft.com/jsch/) based built-in session factory provided by _jgit_. In this context, it is worth noting that the `GitSshdSessionFactory` has been tailored so as to provide
+flexible control over which `SshClient` instance to use, and even which `ClientSession`. The default instance allocates a **new** client every time a new `GitSshdSession` is created - which is
+started and stopped as necessary. However, this can be pretty wasteful, so if one intends to issue several commands that access GIT repositories via SSH, one should maintain a **single**
+client instance and re-use it:
+
+
+```java
+
+    SshClient client = ...create and setup the client...
+    try {
+        client.start();
+        
+        GitSshdSessionFactory sshdFactory = new GitSshdSessionFactory(client);  // re-use the same client for all SSH sessions
+        org.eclipse.jgit.transport.SshSessionFactory.setInstance(sshdFactory);  // replace the JSCH-based factory
+
+        ... issue GIT commands that access remote repositories via SSH ....
+        
+    } finally {
+        client.stop();
+    }
+
+```
+
+### Server-side
+
+See `GitPackCommandFactory` and `GitPgmCommandFactory`. These command factories accept a delegate to which non-_git_ commands are routed:
 
 
 ```java
@@ -1349,7 +1380,6 @@ The _sshd-git_ artifact contains server-side command factories for handling some
     // or any other combination ...
 ```
 
-
 ## LDAP adaptors
 
 The _sshd-ldap_ artifact contains an [LdapPasswordAuthenticator](https://issues.apache.org/jira/browse/SSHD-607) and an [LdapPublicKeyAuthenticator](https://issues.apache.org/jira/browse/SSHD-608) that have been written along the same lines as the [openssh-ldap-publickey](https://github.com/AndriiGrytsenko/openssh-ldap-publickey) project. The authenticators can be easily configured to match most LDAP schemes, or alternatively serve as base classes for code that extends them and adds proprietary logic.


[2/2] mina-sshd git commit: [SSHD-797] Updated GitPackCommandTest to re-use the same client instance in its GitSshdSessionFactory

Posted by lg...@apache.org.
[SSHD-797] Updated GitPackCommandTest to re-use the same client instance in its GitSshdSessionFactory


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/c6451526
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/c6451526
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/c6451526

Branch: refs/heads/master
Commit: c64515269c82f914d479163aea0111c864cd640b
Parents: 2d6fbc9
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Wed Jan 31 17:59:32 2018 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Wed Jan 31 18:00:43 2018 +0200

----------------------------------------------------------------------
 .../sshd/git/pack/GitPackCommandTest.java       | 33 +++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/c6451526/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java b/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
index 2bca899..339170c 100644
--- a/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
+++ b/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 
 import com.jcraft.jsch.JSch;
 
+import org.apache.sshd.client.SshClient;
 import org.apache.sshd.common.util.OsUtils;
 import org.apache.sshd.git.transport.GitSshdSessionFactory;
 import org.apache.sshd.server.SshServer;
@@ -83,26 +84,34 @@ public class GitPackCommandTest extends BaseTestSupport {
 
                 JSch.setConfig("StrictHostKeyChecking", "no");
                 CredentialsProvider.setDefault(new UsernamePasswordCredentialsProvider(getCurrentTestName(), getCurrentTestName()));
-                SshSessionFactory.setInstance(new GitSshdSessionFactory());
-
                 Path localRootDir = gitRootDir.resolve("local");
                 Path localDir = localRootDir.resolve(serverDir.getFileName());
                 Utils.deleteRecursive(localDir);
-                Git.cloneRepository()
+
+                SshClient client = SshClient.setUpDefaultClient();
+                SshSessionFactory.setInstance(new GitSshdSessionFactory(client));
+                try (Git git = Git.cloneRepository()
                         .setURI("ssh://" + getCurrentTestName() + "@" + TEST_LOCALHOST + ":" + port + "/" + serverDir.getFileName())
                         .setDirectory(localDir.toFile())
-                        .call();
+                        .call()) {
+                    assertTrue("Client not started after clone", client.isStarted());
+                    git.commit().setMessage("First Commit").setCommitter(getCurrentTestName(), "sshd@apache.org").call();
+                    git.push().call();
+                    assertTrue("Client not started after 1st push", client.isStarted());
 
-                Git git = Git.open(localDir.toFile());
-                git.commit().setMessage("First Commit").setCommitter(getCurrentTestName(), "sshd@apache.org").call();
-                git.push().call();
+                    Path readmeFile = Files.createFile(localDir.resolve("readme.txt"));
+                    git.add().addFilepattern(readmeFile.getFileName().toString()).call();
+                    git.commit().setMessage(getCurrentTestName()).setCommitter(getCurrentTestName(), "sshd@apache.org").call();
+                    git.push().call();
+                    assertTrue("Client not started after 2nd push", client.isStarted());
 
-                Path readmeFile = Files.createFile(localDir.resolve("readme.txt"));
-                git.add().addFilepattern(readmeFile.getFileName().toString()).call();
-                git.commit().setMessage(getCurrentTestName()).setCommitter(getCurrentTestName(), "sshd@apache.org").call();
-                git.push().call();
+                    git.pull().setRebase(true).call();
+                    assertTrue("Client not started after rebase", client.isStarted());
+                } finally {
+                    client.stop();
+                }
 
-                git.pull().setRebase(true).call();
+                assertFalse("Client not stopped after exit", client.isStarted());
             } finally {
                 sshd.stop();
             }