add ssh client helper function

This commit is contained in:
Aaron Bieber 2024-06-26 20:56:01 -06:00
parent e4f7e775c8
commit 4f129c8d87
No known key found for this signature in database

14
main.go
View File

@ -68,6 +68,11 @@ type Status struct {
Uptime string `json:"uptime"` Uptime string `json:"uptime"`
} }
func (s *Status) SshClose() error {
s.clientEstablished = false
return s.client.Close()
}
func (s *Status) RunCmd(cmd string, x *xinStatus) error { func (s *Status) RunCmd(cmd string, x *xinStatus) error {
khFile := path.Clean(path.Join(os.Getenv("HOME"), ".ssh/known_hosts")) khFile := path.Clean(path.Join(os.Getenv("HOME"), ".ssh/known_hosts"))
hostKeyCB, err := knownhosts.New(khFile) hostKeyCB, err := knownhosts.New(khFile)
@ -301,8 +306,7 @@ func (x *xinStatus) updateHostInfo() error {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
s.client.Close() s.SshClose()
s.clientEstablished = false
} }
}, x.window) }, x.window)
cnf.SetDismissText("Cancel") cnf.SetDismissText("Cancel")
@ -318,8 +322,7 @@ func (x *xinStatus) updateHostInfo() error {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
s.client.Close() s.SshClose()
s.clientEstablished = false
}() }()
}) })
@ -327,7 +330,6 @@ func (x *xinStatus) updateHostInfo() error {
s.buttonBox.Add(restartButton) s.buttonBox.Add(restartButton)
s.buttonBox.Add(updateButton) s.buttonBox.Add(updateButton)
log.Println(s.Host, x.config.CIHost)
if s.Host == x.config.CIHost { if s.Host == x.config.CIHost {
ciStart := widget.NewButton("CI Start", func() { ciStart := widget.NewButton("CI Start", func() {
go func() { go func() {
@ -364,6 +366,8 @@ func (x *xinStatus) updateHostInfo() error {
if err != nil { if err != nil {
x.Log(fmt.Sprintf("can't run command: %q", err)) x.Log(fmt.Sprintf("can't run command: %q", err))
upToDateCount = upToDateCount - 1 upToDateCount = upToDateCount - 1
session.Close()
s.SshClose()
continue continue
} }