Skip to content

Commit

Permalink
Use Apache Mina as ssh transport layer for JGit, remove trilead
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy committed Jun 14, 2024
1 parent d4b5aec commit 463189f
Show file tree
Hide file tree
Showing 29 changed files with 1,165 additions and 850 deletions.
38 changes: 31 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</scm>

<properties>
<revision>4.8.0</revision>
<revision>5.0.0</revision>
<changelist>-SNAPSHOT</changelist>
<!-- Character set tests fail unless file.encoding is set -->
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
Expand Down Expand Up @@ -207,16 +207,24 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
<artifactId>testcontainers-gitserver</artifactId>
<version>0.8.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>test-harness</artifactId>
Expand All @@ -234,8 +242,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-server</artifactId>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -262,6 +271,12 @@
<version>3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.8</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand All @@ -280,6 +295,15 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<org.jenkinsci.plugins.gitclient.verifier.SshHostKeyVerificationStrategy.jgit_known_hosts_file>${project.build.directory}/ssh/know_hosts</org.jenkinsci.plugins.gitclient.verifier.SshHostKeyVerificationStrategy.jgit_known_hosts_file>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/org/jenkinsci/plugins/gitclient/Git.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.gitclient.jgit.PreemptiveAuthHttpClientConnectionFactory;
import org.jenkinsci.plugins.gitclient.verifier.HostKeyVerifierFactory;
import org.jenkinsci.plugins.gitclient.verifier.NoHostKeyVerificationStrategy;

Expand Down Expand Up @@ -42,6 +41,7 @@ public class Git implements Serializable {
private TaskListener listener;
private EnvVars env;
private String exe;
private HostKeyVerifierFactory hostKeyFactory;

/**
* Constructor for a Git object. Either <code>Git.with(listener, env)</code>
Expand Down Expand Up @@ -116,6 +116,11 @@ public Git using(String exe) {
return this;
}

public Git withHostKeyVerifierFactory(HostKeyVerifierFactory hostKeyFactory) {
this.hostKeyFactory = hostKeyFactory;
return this;
}

/**
* {@link org.jenkinsci.plugins.gitclient.GitClient} implementation. The {@link org.jenkinsci.plugins.gitclient.GitClient} interface
* provides the key operations which can be performed on a git repository.
Expand All @@ -125,14 +130,15 @@ public Git using(String exe) {
* @throws java.lang.InterruptedException if interrupted.
*/
public GitClient getClient() throws IOException, InterruptedException {
HostKeyVerifierFactory hostKeyFactory;
if (Jenkins.getInstanceOrNull() == null) {
LOGGER.log(Level.FINE, "No Jenkins instance, skipping host key checking by default");
hostKeyFactory = new NoHostKeyVerificationStrategy().getVerifier();
} else {
hostKeyFactory = GitHostKeyVerificationConfiguration.get()
.getSshHostKeyVerificationStrategy()
.getVerifier();
if (this.hostKeyFactory == null) {
if (Jenkins.getInstanceOrNull() == null) {
LOGGER.log(Level.FINE, "No Jenkins instance, skipping host key checking by default");
this.hostKeyFactory = new NoHostKeyVerificationStrategy().getVerifier();
} else {
this.hostKeyFactory = GitHostKeyVerificationConfiguration.get()
.getSshHostKeyVerificationStrategy()
.getVerifier();
}
}
jenkins.MasterToSlaveFileCallable<GitClient> callable = new GitAPIMasterToSlaveFileCallable(hostKeyFactory);
GitClient git = (repository != null ? repository.act(callable) : callable.invoke(null, null));
Expand Down Expand Up @@ -199,9 +205,7 @@ public GitClient invoke(File f, VirtualChannel channel) throws IOException, Inte
}

if (JGitApacheTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) {
final PreemptiveAuthHttpClientConnectionFactory factory =
new PreemptiveAuthHttpClientConnectionFactory();
return new JGitAPIImpl(f, listener, factory, hostKeyFactory);
return new JGitAPIImpl(f, listener, hostKeyFactory);
}
// Ensure we return a backward compatible GitAPI, even API only claim to provide a GitClient
GitAPI gitAPI = new GitAPI(exe, f, listener, env);
Expand Down
Loading

0 comments on commit 463189f

Please sign in to comment.