mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Added checks for access token when running command
This commit is contained in:
parent
7760857ae5
commit
09c5af44b9
3 changed files with 38 additions and 10 deletions
18
cmd/root.go
18
cmd/root.go
|
|
@ -50,9 +50,27 @@ func Execute() {
|
|||
}
|
||||
}
|
||||
|
||||
func LoadAccessToken() (string, error) {
|
||||
// try to load token from env var
|
||||
testToken := os.Getenv("OCHAMI_ACCESS_TOKEN")
|
||||
if testToken != "" {
|
||||
return testToken, nil
|
||||
}
|
||||
|
||||
// try reading access token from a file
|
||||
b, err := os.ReadFile(tokenPath)
|
||||
if err == nil {
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// TODO: try to load token from config
|
||||
return "", fmt.Errorf("could not load from environment variable or file")
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().IntVar(&threads, "threads", -1, "set the number of threads")
|
||||
rootCmd.PersistentFlags().IntVar(&timeout, "timeout", 30, "set the timeout")
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", true, "set verbose flag")
|
||||
rootCmd.PersistentFlags().StringVar(&accessToken, "access-token", "", "set the access token")
|
||||
rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", "/tmp/magellan/magellan.db", "set the probe storage path")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue