diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-06-13 14:24:49 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-06-13 14:24:49 +0200 |
commit | 17579280e419347d76ff950ebac88844c27a4d8e (patch) | |
tree | 7c40f096cef1cec6529eaacfbd9f250cf9c8b261 /tenant-cd | |
parent | 2bb71582b979a83a39260f3f11466737b94ee47f (diff) |
Separate API and deployment authenticators
Diffstat (limited to 'tenant-cd')
3 files changed, 37 insertions, 18 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java index fa09d7037c9..c6560e10665 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/TestRuntime.java @@ -1,18 +1,20 @@ package ai.vespa.hosted.cd; -import ai.vespa.hosted.api.Authenticator; +import ai.vespa.hosted.api.ApiAuthenticator; +import ai.vespa.hosted.api.EndpointAuthenticator; import ai.vespa.hosted.api.ControllerHttpClient; import ai.vespa.hosted.api.Properties; import ai.vespa.hosted.api.TestConfig; +import ai.vespa.hosted.cd.http.HttpDeployment; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.zone.ZoneId; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Map; -import static ai.vespa.hosted.api.TestConfig.fromJson; +import static java.util.stream.Collectors.toUnmodifiableMap; /** * The place to obtain environment-dependent configuration for test of a Vespa deployment. @@ -24,11 +26,16 @@ public class TestRuntime { private static TestRuntime theRuntime; private final TestConfig config; - private final Authenticator authenticator; + private final Map<String, Deployment> productionDeployments; + private final Deployment deploymentToTest; - private TestRuntime(TestConfig config, Authenticator authenticator) { + private TestRuntime(TestConfig config, EndpointAuthenticator authenticator) { this.config = config; - this.authenticator = authenticator; + this.productionDeployments = config.deployments().entrySet().stream() + .filter(zoneDeployment -> zoneDeployment.getKey().environment() == Environment.prod) + .collect(toUnmodifiableMap(zoneDeployment -> zoneDeployment.getKey().region().value(), + zoneDeployment -> new HttpDeployment(zoneDeployment.getValue(), authenticator))); + this.deploymentToTest = new HttpDeployment(config.deployments().get(config.zone()), authenticator); } /** @@ -44,18 +51,30 @@ public class TestRuntime { public static synchronized TestRuntime get() { if (theRuntime == null) { String configPath = System.getProperty("vespa.test.config"); - Authenticator authenticator = new ai.vespa.hosted.auth.Authenticator(); - theRuntime = new TestRuntime(configPath != null ? fromFile(configPath) : fromController(authenticator), - authenticator); + TestConfig config = configPath != null ? fromFile(configPath) : fromController(); + theRuntime = new TestRuntime(config, + new ai.vespa.hosted.auth.EndpointAuthenticator(config.system())); } return theRuntime; } - /** Returns a copy of this runtime, with the given authenticator. */ - public TestRuntime with(Authenticator authenticator) { + /** Returns a copy of this runtime, with the given endpoint authenticator. */ + public TestRuntime with(EndpointAuthenticator authenticator) { return new TestRuntime(config, authenticator); } + /** Returns the full id of the application this is testing. */ + public ApplicationId application() { return config.application(); } + + /** Returns the zone of the deployment this is testing. */ + public ZoneId zone() { return config.zone(); } + + /** Returns all production deployments of the application this is testing. */ + public Map<String, Deployment> productionDeployments() { return productionDeployments; } + + /** Returns the deployment this is testing. */ + public Deployment deploymentToTest() { return deploymentToTest; } + private static TestConfig fromFile(String path) { try { return TestConfig.fromJson(Files.readAllBytes(Paths.get(path))); @@ -65,8 +84,8 @@ public class TestRuntime { } } - private static TestConfig fromController(Authenticator authenticator) { - ControllerHttpClient controller = authenticator.controller(); + private static TestConfig fromController() { + ControllerHttpClient controller = new ai.vespa.hosted.auth.ApiAuthenticator().controller(); ApplicationId id = Properties.application(); Environment environment = Properties.environment().orElse(Environment.dev); ZoneId zone = Properties.region().map(region -> ZoneId.from(environment, region)) diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java index 6234b54c0a1..d53e08863f7 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpDeployment.java @@ -1,6 +1,6 @@ package ai.vespa.hosted.cd.http; -import ai.vespa.hosted.api.Authenticator; +import ai.vespa.hosted.api.EndpointAuthenticator; import ai.vespa.hosted.cd.Deployment; import ai.vespa.hosted.cd.Endpoint; import ai.vespa.hosted.cd.TestDeployment; @@ -19,7 +19,7 @@ public class HttpDeployment implements Deployment { private final Map<String, HttpEndpoint> endpoints; /** Creates a representation of the given deployment endpoints, using the authenticator for data plane access. */ - public HttpDeployment(Map<String, URI> endpoints, Authenticator authenticator) { + public HttpDeployment(Map<String, URI> endpoints, EndpointAuthenticator authenticator) { this.endpoints = endpoints.entrySet().stream() .collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(), entry -> new HttpEndpoint(entry.getValue(), authenticator))); diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java index 798eb1e692b..7a61c06c738 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java @@ -1,6 +1,6 @@ package ai.vespa.hosted.cd.http; -import ai.vespa.hosted.api.Authenticator; +import ai.vespa.hosted.api.EndpointAuthenticator; import com.yahoo.slime.Inspector; import com.yahoo.slime.JsonDecoder; import com.yahoo.slime.Slime; @@ -34,9 +34,9 @@ public class HttpEndpoint implements TestEndpoint { private final URI endpoint; private final HttpClient client; - private final ai.vespa.hosted.api.Authenticator authenticator; + private final EndpointAuthenticator authenticator; - public HttpEndpoint(URI endpoint, Authenticator authenticator) { + public HttpEndpoint(URI endpoint, EndpointAuthenticator authenticator) { this.endpoint = requireNonNull(endpoint); this.authenticator = requireNonNull(authenticator); this.client = HttpClient.newBuilder() |