From fd50fa6c49c46a125809793816d59d10907fc4cb Mon Sep 17 00:00:00 2001 From: Tim Clifford Date: Wed, 13 Oct 2021 10:07:07 +0100 Subject: [PATCH] throwing exception on ssh failure --- gatherers/graphql.go | 18 +++++++++--------- utils/token.go | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gatherers/graphql.go b/gatherers/graphql.go index 1863187..86a323c 100644 --- a/gatherers/graphql.go +++ b/gatherers/graphql.go @@ -5,8 +5,8 @@ import ( "fmt" "log" - "github.com/uselagoon/lagoon-facts-app/utils" "github.com/machinebox/graphql" + "github.com/uselagoon/lagoon-facts-app/utils" "golang.org/x/oauth2" ) @@ -28,7 +28,7 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact sources := map[string]string{} - for i,e := range facts{ + for i, e := range facts { e.Environment = environmentId facts[i] = e if sources[e.Source] == "" { @@ -48,8 +48,8 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact if err != nil { return err } - var addFactMutation struct{ - AddFacts []struct{ + var addFactMutation struct { + AddFacts []struct { Id int } } @@ -62,7 +62,7 @@ func Writefacts(projectName string, environmentName string, facts []GatheredFact } `) - var factInput struct{ + var factInput struct { Facts []GatheredFact `json:"facts"` } factInput.Facts = facts @@ -86,7 +86,7 @@ func getGraphqlClient() (*graphql.Client, error) { token, err := utils.GetToken() if err != nil { - return nil, err + log.Fatal(err) } httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{ @@ -138,7 +138,7 @@ func GetEnvironmentId(projectId int, environmentName string) (int, error) { var environmentQuery struct { EnvironmentByName struct { - Id int + Id int Name string } } @@ -171,7 +171,7 @@ func DeleteFactsBySource(environmentId int, source string) error { return err } - var responseText struct{ + var responseText struct { Data string } @@ -192,4 +192,4 @@ func DeleteFactsBySource(environmentId int, source string) error { } return nil -} \ No newline at end of file +} diff --git a/utils/token.go b/utils/token.go index e84c488..73f5f2a 100644 --- a/utils/token.go +++ b/utils/token.go @@ -3,11 +3,12 @@ package utils import ( "errors" "fmt" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" "net" "os" "strings" + + "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/agent" ) func sshAgent() ssh.AuthMethod { @@ -26,14 +27,13 @@ func GetToken() (string, error) { HostKeyCallback: ssh.InsecureIgnoreHostKey(), } - connection, err := ssh.Dial("tcp", "ssh.lagoon.amazeeio.cloud:32222", sshConfig) if err != nil { return "", fmt.Errorf("Failed to dial: %s", err) } session, err := connection.NewSession() - if(err != nil) { + if err != nil { return "", err } @@ -46,4 +46,4 @@ func GetToken() (string, error) { connection.Close() return strings.TrimSpace(string(out)), nil -} \ No newline at end of file +}