NOTE: must load when tokenFile != ""
(tokenFile string)
| 16 | |
| 17 | // NOTE: must load when tokenFile != "" |
| 18 | func LoadToken(tokenFile string) string { |
| 19 | var ( |
| 20 | token TokenMsg |
| 21 | mustLoad = true |
| 22 | ) |
| 23 | if tokenFile == "" { |
| 24 | tokenFile = os.Getenv(env.AuthN.TokenFile) |
| 25 | } |
| 26 | if tokenFile == "" { |
| 27 | // when generated via CLI (and without the `-f` option) - the location: |
| 28 | // $HOME/.config/ais/cli/<fname.Token> |
| 29 | tokenFile = filepath.Join(cos.HomeConfigDir(fname.HomeCLI), fname.Token) |
| 30 | mustLoad = false |
| 31 | } |
| 32 | _, err := jsp.LoadMeta(tokenFile, &token) |
| 33 | if err != nil && (mustLoad || !os.IsNotExist(err)) { |
| 34 | cos.Errorf("Failed to load token %q: %v", tokenFile, err) |
| 35 | } |
| 36 | return token.Token |
| 37 | } |
no test coverage detected