Skip to content

Commit

Permalink
ignore errors when opening one_auth file
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Willis <[email protected]>
  • Loading branch information
peterwillis committed May 31, 2024
1 parent c53e485 commit a006aea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
21 changes: 10 additions & 11 deletions src/oca/go/src/goca/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 15 additions & 17 deletions src/oca/go/src/goca/flow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a006aea

Please sign in to comment.