Skip to content

Commit

Permalink
Add missing snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Aug 18, 2023
1 parent 7d13815 commit c103d33
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ junit5 = { module = "org.junit:junit-bom", version.ref = "junit5" }

[libraries.armeria]
module = "com.linecorp.armeria:armeria"
javadocs = "https://www.javadoc.io/doc/com.linecorp.armeria/armeria-javadoc/1.24.0/"
javadocs = "https://www.javadoc.io/doc/com.linecorp.armeria/armeria-javadoc/1.24.3/"
[libraries.armeria-junit5]
module = "com.linecorp.armeria:armeria-junit5"
[libraries.armeria-logback]
Expand Down Expand Up @@ -264,11 +264,11 @@ javadocs = "https://www.javadoc.io/doc/ch.qos.logback/logback-classic/1.2.12/"
[libraries.micrometer-core]
module = "io.micrometer:micrometer-core"
version.ref = "micrometer"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-core/1.10.5/"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-core/1.11.1/"
[libraries.micrometer-prometheus]
module = "io.micrometer:micrometer-registry-prometheus"
version.ref = "micrometer"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-registry-prometheus/1.10.5/"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-registry-prometheus/1.11.1/"

[libraries.mockito-core]
module = "org.mockito:mockito-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.jgit.transport.SshTransport;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory;
import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig;
import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig.Host;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -70,6 +71,7 @@ final class GitWithAuth extends Git {

private static final Logger logger = LoggerFactory.getLogger(GitWithAuth.class);

private static final OpenSshConfig EMPTY_CONFIG = emptySshConfig();
/**
* One of the Locks in this array is locked while a Git repository is accessed so that other GitMirrors
* that access the same repository cannot access it at the same time. The lock is chosen based on the
Expand Down Expand Up @@ -186,7 +188,7 @@ public LsRemoteCommand lsRemote() {
private static <T extends TransportCommand<?, ?>> void configureSsh(T cmd, PublicKeyMirrorCredential cred) {
cmd.setTransportConfigCallback(transport -> {
final SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() {
final JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
try {
Expand All @@ -199,14 +201,18 @@ protected void configure(Host host, Session session) {
throw new MirrorException(e);

Check warning on line 201 in server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java

View check run for this annotation

Codecov / codecov/patch

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java#L198-L201

Added lines #L198 - L201 were not covered by tests
}
}
});
};

// Disable the default SSH config file lookup.
sessionFactory.setConfig(EMPTY_CONFIG);
sshTransport.setSshSessionFactory(sessionFactory);
});
}

private static <T extends TransportCommand<?, ?>> void configureSsh(T cmd, PasswordMirrorCredential cred) {
cmd.setTransportConfigCallback(transport -> {
final SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() {
final JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {

Check warning on line 215 in server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java

View check run for this annotation

Codecov / codecov/patch

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java#L213-L215

Added lines #L213 - L215 were not covered by tests
@Override
protected void configure(Host host, Session session) {
try {
Expand All @@ -218,7 +224,11 @@ protected void configure(Host host, Session session) {
throw new MirrorException(e);
}
}

Check warning on line 226 in server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java

View check run for this annotation

Codecov / codecov/patch

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java#L219-L226

Added lines #L219 - L226 were not covered by tests
});
};

// Disable the default SSH config file lookup.
sessionFactory.setConfig(EMPTY_CONFIG);
sshTransport.setSshSessionFactory(sessionFactory);
});
}

Check warning on line 233 in server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java

View check run for this annotation

Codecov / codecov/patch

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java#L230-L233

Added lines #L230 - L233 were not covered by tests

Expand Down Expand Up @@ -373,4 +383,24 @@ public void removeAll() {
throw new UnsupportedOperationException();
}
}

/**
* Returns an empty {@link OpenSshConfig}.
*
* <p>The default {@link OpenSshConfig} reads the SSH config in `~/.ssh/config` and converts the identity
* files into {@code com.jcraft.jsch.KeyPair}. Since JSch does not support Ed25519, `KeyPair.load()`
* raise an exception if Ed25519 is used locally. Plus, Central Dogma uses
* {@link PublicKeyMirrorCredential}, we need to provide an empty config for an isolated environment.
*/
private static OpenSshConfig emptySshConfig() {
final File emptyConfigFile;
try {
emptyConfigFile = File.createTempFile("dogma", "empty-ssh-config");
emptyConfigFile.deleteOnExit();
} catch (IOException e) {
throw new IllegalStateException(e);

Check warning on line 401 in server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java

View check run for this annotation

Codecov / codecov/patch

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitWithAuth.java#L400-L401

Added lines #L400 - L401 were not covered by tests
}

return new OpenSshConfig(emptyConfigFile.getParentFile(), emptyConfigFile);
}
}

0 comments on commit c103d33

Please sign in to comment.