diff options
-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 | ||||
-rw-r--r-- | vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java | 4 | ||||
-rw-r--r-- | vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java | 3 |
6 files changed, 36 insertions, 9 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) diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java index c01286a8064..1ea7266ab12 100644 --- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java +++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/VespaCliTestRunner.java @@ -26,7 +26,6 @@ import java.util.stream.Stream; import static com.yahoo.vespa.testrunner.TestRunner.Status.ERROR; import static com.yahoo.vespa.testrunner.TestRunner.Status.FAILURE; -import static com.yahoo.vespa.testrunner.TestRunner.Status.INCONCLUSIVE; import static com.yahoo.vespa.testrunner.TestRunner.Status.NO_TESTS; import static com.yahoo.vespa.testrunner.TestRunner.Status.RUNNING; import static com.yahoo.vespa.testrunner.TestRunner.Status.SUCCESS; @@ -119,6 +118,9 @@ public class VespaCliTestRunner implements TestRunner { "--zone", config.zone().value(), "--target", "cloud"); builder.redirectErrorStream(true); + // The CI environment variables tells Vespa CLI to omit certain warnings that do not apply to CI environments + builder.environment().put("CI", "true"); + builder.environment().put("VESPA_CLI_CLOUD_CI", "true"); builder.environment().put("VESPA_CLI_HOME", ensureHomeDirectoryForVespaCli().toString()); builder.environment().put("VESPA_CLI_ENDPOINTS", toEndpointsConfig(config)); builder.environment().put("VESPA_CLI_DATA_PLANE_KEY_FILE", artifactsPath.resolve("key").toAbsolutePath().toString()); diff --git a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java index 5fd73bb4494..8b02575b950 100644 --- a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java +++ b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/VespaCliTestRunnerTest.java @@ -12,6 +12,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jonmv @@ -55,6 +56,8 @@ class VespaCliTestRunnerTest { "--zone", "dev.aws-us-east-1c", "--target", "cloud"), builder.command()); + assertTrue(builder.environment().containsKey("CI")); + assertTrue(builder.environment().containsKey("VESPA_CLI_CLOUD_CI")); assertEquals("{\"endpoints\":[{\"cluster\":\"default\",\"url\":\"https://dev.endpoint:443/\"}]}", builder.environment().get("VESPA_CLI_ENDPOINTS")); assertEquals(artifacts.resolve("key").toAbsolutePath().toString(), |