diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-03-02 16:00:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 16:00:11 +0100 |
commit | 60c5b5e0a91e35e61dc82222df74df2ad42d3caa (patch) | |
tree | bea59c886cb62e85ed3ba4eed6d086cf92118033 /client/go | |
parent | 199da0293ac98b41b0f1094bc338cc4fb7b2ac5d (diff) | |
parent | ed08bd51ee579a4a9bb047f1158e7d740ce0cf7c (diff) |
Merge pull request #21500 from vespa-engine/mpolden/tweak-warnings
Reduce warnings when using Vespa CLI in CI
Diffstat (limited to 'client/go')
-rw-r--r-- | client/go/cmd/config.go | 10 | ||||
-rw-r--r-- | client/go/cmd/config_test.go | 7 | ||||
-rw-r--r-- | client/go/cmd/helpers.go | 18 | ||||
-rw-r--r-- | client/go/cmd/prod.go | 3 |
4 files changed, 30 insertions, 8 deletions
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go index 30db45c2bd2..1680e1d32b5 100644 --- a/client/go/cmd/config.go +++ b/client/go/cmd/config.go @@ -206,10 +206,12 @@ func (c *Config) UseAPIKey(system vespa.System, tenantName string) bool { } // If no Auth0 token is created, fall back to tenant api key, but warn that this functionality is deprecated // TODO: Remove this when users have had time to migrate over to Auth0 device flow authentication - a, err := auth0.GetAuth0(c.AuthConfigPath(), system.Name, system.URL) - if err != nil || !a.HasSystem() { - printWarning("Defaulting to tenant API key is deprecated.", "Use Auth0 device flow: 'vespa auth login' instead") - return util.PathExists(c.APIKeyPath(tenantName)) + if !isCI() { + a, err := auth0.GetAuth0(c.AuthConfigPath(), system.Name, system.URL) + if err != nil || !a.HasSystem() { + printWarning("Use of API key is deprecated", "Authenticate with Auth0 instead: 'vespa auth login'") + return util.PathExists(c.APIKeyPath(tenantName)) + } } return false } diff --git a/client/go/cmd/config_test.go b/client/go/cmd/config_test.go index 2183de6b2f2..1ca51652340 100644 --- a/client/go/cmd/config_test.go +++ b/client/go/cmd/config_test.go @@ -101,10 +101,17 @@ func TestUseAPIKey(t *testing.T) { } }` withEnv("VESPA_CLI_CLOUD_SYSTEM", "public", func() { + ci, ok := os.LookupEnv("CI") + if ok { + os.Unsetenv("CI") // Test depends on unset variable + } _, err := os.Create(filepath.Join(homeDir, "t2.api-key.pem")) require.Nil(t, err) assert.True(t, c.UseAPIKey(vespa.PublicSystem, "t2")) require.Nil(t, ioutil.WriteFile(filepath.Join(homeDir, "auth.json"), []byte(authContent), 0600)) assert.False(t, c.UseAPIKey(vespa.PublicSystem, "t2")) + if ok { + os.Setenv("CI", ci) + } }) } diff --git a/client/go/cmd/helpers.go b/client/go/cmd/helpers.go index 831cd110762..0fcb0f6b113 100644 --- a/client/go/cmd/helpers.go +++ b/client/go/cmd/helpers.go @@ -194,8 +194,10 @@ func getTarget() (vespa.Target, error) { if err != nil { return nil, err } - if err := target.CheckVersion(clientVersion); err != nil { - printErrHint(err, "This is not a fatal error, but this version may not work as expected", "Try 'vespa version' to check for a new version") + if !isCloudCI() { // Vespa Cloud always runs an up-to-date version + if err := target.CheckVersion(clientVersion); err != nil { + printErrHint(err, "This is not a fatal error, but this version may not work as expected", "Try 'vespa version' to check for a new version") + } } return target, nil } @@ -342,6 +344,18 @@ func getEndpointsFromEnv() (map[string]string, error) { return urlsByCluster, nil } +// isCI returns true if running inside a continuous integration environment. +func isCI() bool { + _, ok := os.LookupEnv("CI") + return ok +} + +// isCloudCI returns true if running inside a Vespa Cloud deployment job. +func isCloudCI() bool { + _, ok := os.LookupEnv("VESPA_CLI_CLOUD_CI") + return ok +} + type endpoints struct { Endpoints []endpoint `json:"endpoints"` } diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go index b30f2e8551d..5b30a7a9b89 100644 --- a/client/go/cmd/prod.go +++ b/client/go/cmd/prod.go @@ -155,8 +155,7 @@ $ vespa prod submit`, if err := verifyTests(pkg, target); err != nil { return err } - isCI := os.Getenv("CI") != "" - if !isCI { + if !isCI() { printWarning("We recommend doing this only from a CD job", "See https://cloud.vespa.ai/en/getting-to-production") } opts, err := getDeploymentOptions(cfg, pkg, target) |