From f047caeeef32cb63c4e7f00f1a9b404a313c59e5 Mon Sep 17 00:00:00 2001 From: Peter Willis Date: Fri, 31 May 2024 20:49:30 +0100 Subject: [PATCH] ignore errors when opening one_auth file Signed-off-by: Peter Willis --- src/oca/go/src/goca/client.go | 21 ++++++++++---------- src/oca/go/src/goca/flow_client.go | 32 ++++++++++++++---------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/oca/go/src/goca/client.go b/src/oca/go/src/goca/client.go index 53b9bd3226..1e1bd15113 100644 --- a/src/oca/go/src/goca/client.go +++ b/src/oca/go/src/goca/client.go @@ -66,20 +66,19 @@ func NewConfig(user, password, endpoint string) OneConfig { oneAuthPath = os.Getenv("HOME") + "/.one/one_auth" } - file, err := os.Open(oneAuthPath) - if err != nil { - log.Fatalln(err) - } - defer file.Close() + file, _ := os.Open(oneAuthPath) + if file != nil { + defer file.Close() - scanner := bufio.NewScanner(file) + scanner := bufio.NewScanner(file) - scanner.Scan() - if scanner.Err() != nil { - log.Fatalln(scanner.Err()) - } + scanner.Scan() + if scanner.Err() != nil { + log.Fatalln(scanner.Err()) + } - conf.Token = scanner.Text() + conf.Token = scanner.Text() + } } else { conf.Token = user + ":" + password } diff --git a/src/oca/go/src/goca/flow_client.go b/src/oca/go/src/goca/flow_client.go index 41855c25bd..c3f567991c 100644 --- a/src/oca/go/src/goca/flow_client.go +++ b/src/oca/go/src/goca/flow_client.go @@ -61,27 +61,25 @@ func NewFlowConfig(user, password, endpoint string) HTTPAuth { oneAuthPath = os.Getenv("HOME") + "/.one/one_auth" } - file, err := os.Open(oneAuthPath) - if err != nil { - log.Fatalln(err) - } - defer file.Close() + file, _ := os.Open(oneAuthPath) + if file != nil { + defer file.Close() - scanner := bufio.NewScanner(file) + scanner := bufio.NewScanner(file) - scanner.Scan() - if scanner.Err() != nil { - log.Fatalln(scanner.Err()) - } + scanner.Scan() + if scanner.Err() != nil { + log.Fatalln(scanner.Err()) + } - parts := strings.Split(scanner.Text(), ":") - if len(parts) != 2 { - log.Fatalln("unable to parse credentials") - } - - conf.user = parts[0] - conf.pass = parts[1] + parts := strings.Split(scanner.Text(), ":") + if len(parts) != 2 { + log.Fatalln("unable to parse credentials") + } + conf.user = parts[0] + conf.pass = parts[1] + } } else { conf.user = user conf.pass = password