Make RDE SSH key identity injectable

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133883090
This commit is contained in:
Hans Ridder 2016-09-21 15:23:00 -07:00 committed by Ben McIlwain
parent 28eeda189d
commit 2d46c7c27c
3 changed files with 16 additions and 1 deletions

View file

@ -406,6 +406,18 @@ public final class ConfigModule {
return Duration.standardHours(2); return Duration.standardHours(2);
} }
/**
* Returns the identity (an email address) used for the SSH keys used in RDE SFTP uploads.
*
* @see google.registry.keyring.api.Keyring#getRdeSshClientPublicKey()
* @see google.registry.keyring.api.Keyring#getRdeSshClientPrivateKey()
*/
@Provides
@Config("rdeSshIdentity")
public static String provideSshIdentity() {
return "rde@charlestonroadregistry.com";
}
/** /**
* Returns SFTP URL containing a username, hostname, port (optional), and directory (optional) to * Returns SFTP URL containing a username, hostname, port (optional), and directory (optional) to
* which cloud storage files are uploaded. The password should not be included, as it's better to * which cloud storage files are uploaded. The password should not be included, as it's better to

View file

@ -21,6 +21,7 @@ import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import google.registry.config.ConfigModule.Config;
import google.registry.keyring.api.KeyModule.Key; import google.registry.keyring.api.KeyModule.Key;
/** Dagger module for {@link JSch} which provides SSH/SFTP connectivity. */ /** Dagger module for {@link JSch} which provides SSH/SFTP connectivity. */
@ -29,13 +30,14 @@ public final class JSchModule {
@Provides @Provides
static JSch provideJSch( static JSch provideJSch(
@Config("rdeSshIdentity") String identity,
@Key("rdeSshClientPrivateKey") String privateKey, @Key("rdeSshClientPrivateKey") String privateKey,
@Key("rdeSshClientPublicKey") String publicKey) { @Key("rdeSshClientPublicKey") String publicKey) {
applyAppEngineKludge(); applyAppEngineKludge();
JSch jsch = new JSch(); JSch jsch = new JSch();
try { try {
jsch.addIdentity( jsch.addIdentity(
"rde@charlestonroadregistry.com", identity,
privateKey.getBytes(UTF_8), privateKey.getBytes(UTF_8),
publicKey.getBytes(UTF_8), publicKey.getBytes(UTF_8),
null); null);

View file

@ -181,6 +181,7 @@ public class RdeUploadActionTest {
action.ghostryde = new Ghostryde(BUFFER_SIZE); action.ghostryde = new Ghostryde(BUFFER_SIZE);
action.jsch = action.jsch =
JSchModule.provideJSch( JSchModule.provideJSch(
"user@ignored",
keyring.getRdeSshClientPrivateKey(), keyring.getRdeSshClientPublicKey()); keyring.getRdeSshClientPrivateKey(), keyring.getRdeSshClientPublicKey());
action.jschSshSessionFactory = new JSchSshSessionFactory(standardSeconds(3)); action.jschSshSessionFactory = new JSchSshSessionFactory(standardSeconds(3));
action.response = response; action.response = response;