summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-03-25 09:36:55 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-03-26 14:03:48 +0100
commit918eb4884dc5ccefa5d0a26ef0529442a8946deb (patch)
tree089c139ac506ff4ed2d3b774d11985e8997d079a /controller-server
parentbdcd9394cd33359197ae1c1d7ebd013f03581554 (diff)
Add skeleton handler and test
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiHandler.java88
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java3
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiTest.java22
3 files changed, 113 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiHandler.java
new file mode 100644
index 00000000000..f7693968b43
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiHandler.java
@@ -0,0 +1,88 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.restapi.user;
+
+import com.yahoo.container.jdisc.HttpRequest;
+import com.yahoo.container.jdisc.HttpResponse;
+import com.yahoo.container.jdisc.LoggingRequestHandler;
+import com.yahoo.restapi.Path;
+import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse;
+import com.yahoo.vespa.hosted.controller.restapi.application.EmptyJsonResponse;
+import com.yahoo.yolean.Exceptions;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * API for user management related to access control.
+ *
+ * @author jonmv
+ */
+@SuppressWarnings("unused") // Handler
+public class UserApiHandler extends LoggingRequestHandler {
+
+ private final static Logger log = Logger.getLogger(UserApiHandler.class.getName());
+
+ public UserApiHandler(Context parentCtx) {
+ super(parentCtx);
+ }
+
+ @Override
+ public HttpResponse handle(HttpRequest request) {
+ try {
+ switch (request.getMethod()) {
+ case GET: return handleGET(request);
+ case PUT: return handlePUT(request);
+ case POST: return handlePOST(request);
+ case DELETE: return handleDELETE(request);
+ case OPTIONS: return handleOPTIONS();
+ default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported");
+ }
+ }
+ catch (IllegalArgumentException e) {
+ return ErrorResponse.badRequest(Exceptions.toMessageString(e));
+ }
+ catch (RuntimeException e) {
+ log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
+ return ErrorResponse.internalServerError(Exceptions.toMessageString(e));
+ }
+ }
+
+ private HttpResponse handleGET(HttpRequest request) {
+ Path path = new Path(request.getUri().getPath());
+
+
+ return ErrorResponse.notFoundError(String.format("No '%s' handler at '%s'", request.getMethod(),
+ request.getUri().getPath()));
+ }
+
+ private HttpResponse handlePUT(HttpRequest request) {
+ Path path = new Path(request.getUri().getPath());
+
+
+ return ErrorResponse.notFoundError(String.format("No '%s' handler at '%s'", request.getMethod(),
+ request.getUri().getPath()));
+ }
+
+ private HttpResponse handlePOST(HttpRequest request) {
+ Path path = new Path(request.getUri().getPath());
+
+
+ return ErrorResponse.notFoundError(String.format("No '%s' handler at '%s'", request.getMethod(),
+ request.getUri().getPath()));
+ }
+
+ private HttpResponse handleDELETE(HttpRequest request) {
+ Path path = new Path(request.getUri().getPath());
+
+
+ return ErrorResponse.notFoundError(String.format("No '%s' handler at '%s'", request.getMethod(),
+ request.getUri().getPath()));
+ }
+
+ private HttpResponse handleOPTIONS() {
+ EmptyJsonResponse response = new EmptyJsonResponse();
+ response.headers().put("Allow", "GET,PUT,POST,PATCH,DELETE,OPTIONS");
+ return response;
+ }
+
+}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
index fce9d780d90..ab19ccf23d2 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java
@@ -101,6 +101,9 @@ public class ControllerContainerTest {
" <handler id='com.yahoo.vespa.hosted.controller.restapi.athenz.AthenzApiHandler'>\n" +
" <binding>http://*/athenz/v1/*</binding>\n" +
" </handler>\n" +
+ " <handler id='com.yahoo.vespa.hosted.controller.restapi.user.UserApiHandler'>\n" +
+ " <binding>http://*/user/v1/*</binding>\n" +
+ " </handler>\n" +
" <handler id='com.yahoo.vespa.hosted.controller.restapi.deployment.DeploymentApiHandler'>\n" +
" <binding>http://*/deployment/v1/*</binding>\n" +
" </handler>\n" +
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiTest.java
new file mode 100644
index 00000000000..9bba0ac0ab1
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/user/UserApiTest.java
@@ -0,0 +1,22 @@
+package com.yahoo.vespa.hosted.controller.restapi.user;
+
+import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester;
+import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
+import org.junit.Test;
+
+/**
+ * @author jonmv
+ */
+public class UserApiTest extends ControllerContainerTest {
+
+ private static final String responseFiles = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/user/responses/";
+
+ @Test
+ public void testBadgeApi() {
+ ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
+
+ tester.assertResponse(authenticatedRequest("http://localhost:8080/user/v1/"),
+ "{\"error-code\":\"NOT_FOUND\",\"message\":\"No 'GET' handler at '/user/v1/'\"}", 404);
+ }
+
+}