Support multiple API keys (command-line and config) (fixes #2747)

This commit is contained in:
Antony Male
2016-01-29 17:16:01 +00:00
parent 8ff7531f89
commit 5971c00a4f
5 changed files with 18 additions and 10 deletions

View File

@@ -76,9 +76,17 @@ func (c GUIConfiguration) URL() string {
return u.String()
}
func (c GUIConfiguration) APIKey() string {
if override := os.Getenv("STGUIAPIKEY"); override != "" {
return override
// Returns whether the given API key is valid, including both the value in config
// and any overrides
func (c GUIConfiguration) IsValidAPIKey(apiKey string) bool {
switch apiKey {
case "":
return false
case c.RawAPIKey, os.Getenv("STGUIAPIKEY"):
return true
default:
return false
}
return c.RawAPIKey
}