summaryrefslogtreecommitdiffstats
path: root/client/go/cmd/config.go
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-04-19 11:29:27 +0200
committerMartin Polden <mpolden@mpolden.no>2022-04-20 08:56:29 +0200
commit9790091ed97be301ea39eb95cda218dd6dd1b16e (patch)
tree65206e54bd4e15d59a1e2668c68161e6452980dc /client/go/cmd/config.go
parent30d38557e9b442e8f2c705aee982ab0e70b1bc2b (diff)
Allow reading API key from default path when Auth0 is not configured
Diffstat (limited to 'client/go/cmd/config.go')
-rw-r--r--client/go/cmd/config.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
index 726676ce476..02477aecf28 100644
--- a/client/go/cmd/config.go
+++ b/client/go/cmd/config.go
@@ -20,7 +20,6 @@ import (
"github.com/spf13/pflag"
"github.com/vespa-engine/vespa/client/go/auth/auth0"
"github.com/vespa-engine/vespa/client/go/config"
- "github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -433,30 +432,21 @@ func (c *Config) authConfigPath() string {
return filepath.Join(c.homeDir, "auth.json")
}
-func (c *Config) readAPIKey(tenantName string) ([]byte, error) {
+func (c *Config) readAPIKey(cli *CLI, system vespa.System, tenantName string) ([]byte, error) {
if override, ok := c.apiKeyFromEnv(); ok {
return override, nil
}
- return os.ReadFile(c.apiKeyPath(tenantName))
-}
-
-// useAPIKey returns true if an API key should be used when authenticating with system.
-func (c *Config) useAPIKey(cli *CLI, system vespa.System, tenantName string) bool {
- if _, ok := c.apiKeyFromEnv(); ok {
- return true
- }
- if _, ok := c.apiKeyFileFromEnv(); ok {
- return true
+ if path, ok := c.apiKeyFileFromEnv(); ok {
+ return os.ReadFile(path)
}
if !cli.isCI() {
- // Fall back to API key, if present and Auth0 has not been configured
client, err := auth0.New(c.authConfigPath(), system.Name, system.URL)
- if err != nil || !client.HasCredentials() {
- cli.printWarning("Regular authentication is preferred over API key in a non-CI context", "Authenticate with 'vespa auth login'")
- return util.PathExists(c.apiKeyPath(tenantName))
+ if err == nil && client.HasCredentials() {
+ return nil, nil // use Auth0
}
+ cli.printWarning("Authenticating with API key. This is discouraged in non-CI environments", "Authenticate with 'vespa auth login'")
}
- return false
+ return os.ReadFile(c.apiKeyPath(tenantName))
}
func (c *Config) readSessionID(app vespa.ApplicationID) (int64, error) {