add client creation logic

This commit is contained in:
William Banfield
2022-11-30 12:46:00 -05:00
parent 31a37eed02
commit fcb92561ce
2 changed files with 32 additions and 3 deletions

View File

@@ -22,12 +22,24 @@ func Exec(cfg *ssh.ClientConfig, addr, cmd string) error {
return nil
}
func NewClientConfig(key string) (*ssh.ClientConfig, error) {
func NewClientConfig(keyFile string) (*ssh.ClientConfig, error) {
hkc, err := knownhosts.New(filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts"))
if err != nil {
return nil, err
}
key, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
}
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
return nil, err
}
return &ssh.ClientConfig{
HostKeyCallback: hkc,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyAlgorithms: []string{ssh.KeyAlgoED25519},
}, nil
}

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"os"
"path/filepath"
"strconv"
"github.com/spf13/cobra"
@@ -13,7 +14,9 @@ import (
"github.com/tendermint/tendermint/libs/log"
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
"github.com/tendermint/tendermint/test/e2e/pkg/infra"
"github.com/tendermint/tendermint/test/e2e/pkg/infra/digitalocean"
"github.com/tendermint/tendermint/test/e2e/pkg/infra/docker"
e2essh "github.com/tendermint/tendermint/test/e2e/pkg/ssh"
)
const randomSeed = 2308084734268
@@ -85,9 +88,23 @@ func NewCLI() *CLI {
}
cli.testnet = testnet
cli.infp = &infra.NoopProvider{}
if inft == "docker" {
switch inft {
case "docker":
cli.infp = &docker.Provider{Testnet: testnet}
case "digitalocean":
// TMP: hardcoded key
cfg, err := e2essh.NewClientConfig(filepath.Join(os.Getenv("HOME"), ".ssh", "PVT_KEY"))
if err != nil {
return err
}
cli.infp = &digitalocean.Provider{
Testnet: testnet,
InfrastructureData: ifd,
SSHConfig: cfg,
}
default:
cli.infp = &infra.NoopProvider{}
}
return nil
},