From 3594b1e5f1aeac96630848af3af95d0669c22e50 Mon Sep 17 00:00:00 2001 From: Wyatt Miller Date: Tue, 13 Aug 2019 11:43:40 -0400 Subject: [PATCH] struct mapping, initialize conneciton works --- main.go | 6 ++---- ssh.go | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 209bc1a..26414bf 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,11 @@ package main -import "fmt" - func main() { //fmt.Println("Hello!") //var config Configuration config := initializeConfig("config.yaml") - fmt.Println(config.Hosts) - + sshConn, sshConfig := initializeConnection(config) + sshConn.DialConnection(sshConfig) } diff --git a/ssh.go b/ssh.go index d4bef06..22e5939 100644 --- a/ssh.go +++ b/ssh.go @@ -1,8 +1,37 @@ package main -type sshConnection struct { +import ( + "fmt" + + "golang.org/x/crypto/ssh" +) + +type SSHConnection struct { Username string Password string Port string Hosts []string } + +func initializeConnection(config Configuration) (SSHConnection, *ssh.ClientConfig) { + var sshConn SSHConnection + sshConn.Username = config.Username + sshConn.Password = config.Password + sshConn.Port = config.Port + sshConn.Hosts = config.Hosts + + sshConfig := &ssh.ClientConfig{ + User: sshConn.Username, + Auth: []ssh.AuthMethod{ + ssh.Password(sshConn.Password), + }, + } + + return sshConn, sshConfig +} + +func (sshConn SSHConnection) DialConnection(sshConnec *ssh.ClientConfig) { + for _, j := range sshConn.Hosts { + fmt.Println(j) + } +}