summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-02-03 10:16:23 +0100
committerMartin Polden <mpolden@mpolden.no>2022-02-03 10:32:27 +0100
commit10446fafad7096e6f890c74792f2f343665bc32e (patch)
treee2875ab83ae0ef95023b04a05a64bf87efe5d795 /client
parente263fd38593e92caf1003216a7e7f6e2eda95149 (diff)
Support passing API key as environment variable
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/api_key.go24
-rw-r--r--client/go/cmd/config.go6
2 files changed, 28 insertions, 2 deletions
diff --git a/client/go/cmd/api_key.go b/client/go/cmd/api_key.go
index 032d98c96fe..0f665007107 100644
--- a/client/go/cmd/api_key.go
+++ b/client/go/cmd/api_key.go
@@ -15,13 +15,31 @@ import (
var overwriteKey bool
+const apiKeyLongDoc = `Create a new user API key for authentication with Vespa Cloud.
+
+The API key will be stored in the Vespa CLI home directory
+(see 'vespa help config'). Other commands will then automatically load the API
+key as necessary.
+
+It's possible to override the API key used through environment variables. This
+can be useful in continuous integration systems.
+
+* VESPA_CLI_API_KEY containing the key directly:
+
+ export VESPA_CLI_API_KEY="my api key"
+
+* VESPA_CLI_API_KEY_FILE containing path to the key:
+
+ export VESPA_CLI_API_KEY_FILE=/path/to/api-key
+
+Note that when overriding API key through environment variables, that key will
+always be used. It's not possible to specify a tenant-specific key.`
+
func init() {
apiKeyCmd.Flags().BoolVarP(&overwriteKey, "force", "f", false, "Force overwrite of existing API key")
apiKeyCmd.MarkPersistentFlagRequired(applicationFlag)
}
-var example string
-
func apiKeyExample() string {
if vespa.Auth0AccessTokenEnabled() {
return "$ vespa auth api-key -a my-tenant.my-app.my-instance"
@@ -33,6 +51,7 @@ func apiKeyExample() string {
var apiKeyCmd = &cobra.Command{
Use: "api-key",
Short: "Create a new user API key for authentication with Vespa Cloud",
+ Long: apiKeyLongDoc,
Example: apiKeyExample(),
DisableAutoGenTag: true,
Args: cobra.ExactArgs(0),
@@ -42,6 +61,7 @@ var apiKeyCmd = &cobra.Command{
var deprecatedApiKeyCmd = &cobra.Command{
Use: "api-key",
Short: "Create a new user API key for authentication with Vespa Cloud",
+ Long: apiKeyLongDoc,
Example: apiKeyExample(),
DisableAutoGenTag: true,
Args: cobra.ExactArgs(0),
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
index 7e7a2de27e8..e375e2c66b9 100644
--- a/client/go/cmd/config.go
+++ b/client/go/cmd/config.go
@@ -181,10 +181,16 @@ func (c *Config) X509KeyPair(app vespa.ApplicationID) (KeyPair, error) {
}
func (c *Config) APIKeyPath(tenantName string) string {
+ if override, ok := os.LookupEnv("VESPA_CLI_API_KEY_FILE"); ok {
+ return override
+ }
return filepath.Join(c.Home, tenantName+".api-key.pem")
}
func (c *Config) ReadAPIKey(tenantName string) ([]byte, error) {
+ if override, ok := os.LookupEnv("VESPA_CLI_API_KEY"); ok {
+ return []byte(override), nil
+ }
return ioutil.ReadFile(c.APIKeyPath(tenantName))
}