From bf5df61e6cb031adb9914704f04b71c57d44747a Mon Sep 17 00:00:00 2001 From: giangbui Date: Tue, 3 Mar 2020 10:25:37 -0600 Subject: [PATCH] Fix/token (#13) * feat(test): test * fix(token): fix null token --- handlers/config.go | 7 ++++++- handlers/jobs.go | 2 +- handlers/sower.go | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/handlers/config.go b/handlers/config.go index 62852e5..aae57e8 100644 --- a/handlers/config.go +++ b/handlers/config.go @@ -2,6 +2,7 @@ package handlers import ( "encoding/json" + "fmt" "io/ioutil" k8sv1 "k8s.io/api/core/v1" @@ -30,6 +31,10 @@ type SowerConfig struct { func loadSowerConfigs(config string) []SowerConfig { plan, _ := ioutil.ReadFile(config) var data []SowerConfig - _ = json.Unmarshal(plan, &data) + err := json.Unmarshal(plan, &data) + if err != nil { + fmt.Println("ERROR: ", err) + return nil + } return data } diff --git a/handlers/jobs.go b/handlers/jobs.go index b58d0ff..294430b 100644 --- a/handlers/jobs.go +++ b/handlers/jobs.go @@ -129,7 +129,7 @@ func createK8sJob(currentAction string, inputData string, accessToken string, us randname := GetRandString(5) name := fmt.Sprintf("%s-%s", conf.Name, randname) fmt.Println("input data: ", inputData) - var deadline int64 = 3600 + var deadline int64 = 7200 var backoff int32 = 1 labels := make(map[string]string) labels["app"] = "sowerjob" diff --git a/handlers/sower.go b/handlers/sower.go index 0c85f10..ac5b432 100644 --- a/handlers/sower.go +++ b/handlers/sower.go @@ -54,7 +54,12 @@ func dispatch(w http.ResponseWriter, r *http.Request) { fmt.Println(string(out)) - result, err := createK8sJob(currentAction, string(out), *accessToken, userName) + accessTokenVal := "" + if accessToken != nil { + accessTokenVal = *accessToken + } + + result, err := createK8sJob(currentAction, string(out), accessTokenVal, userName) if err != nil { http.Error(w, err.Error(), 500) return