Skip to content

Commit

Permalink
throwing exception on ssh failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Clifford committed Oct 13, 2021
1 parent 663808e commit fd50fa6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions gatherers/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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] == "" {
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -138,7 +138,7 @@ func GetEnvironmentId(projectId int, environmentName string) (int, error) {

var environmentQuery struct {
EnvironmentByName struct {
Id int
Id int
Name string
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func DeleteFactsBySource(environmentId int, source string) error {
return err
}

var responseText struct{
var responseText struct {
Data string
}

Expand All @@ -192,4 +192,4 @@ func DeleteFactsBySource(environmentId int, source string) error {
}

return nil
}
}
10 changes: 5 additions & 5 deletions utils/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -46,4 +46,4 @@ func GetToken() (string, error) {
connection.Close()

return strings.TrimSpace(string(out)), nil
}
}

0 comments on commit fd50fa6

Please sign in to comment.