summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2022-08-15 12:00:44 +0200
committerOla Aunrønning <olaa@verizonmedia.com>2022-08-15 12:04:11 +0200
commit437b56d8e7bccb814fa1aa8f7038c0828004b7bc (patch)
treeb7289aeb95cbc2cdb3e8b86ea860adf2a7978574 /controller-server
parent5c15236363db05ce5d469c9f37ff39bb0127023f (diff)
Add handler for serving well known directory
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandler.java44
-rw-r--r--controller-server/src/main/resources/configdefinitions/vespa.hosted.controller.config.well-known-folder.def5
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandlerTest.java50
3 files changed, 99 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandler.java
new file mode 100644
index 00000000000..a8af9692bd6
--- /dev/null
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandler.java
@@ -0,0 +1,44 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.restapi.controller;
+
+import com.yahoo.container.jdisc.HttpRequest;
+import com.yahoo.container.jdisc.HttpResponse;
+import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
+import com.yahoo.restapi.ErrorResponse;
+import com.yahoo.restapi.Path;
+import com.yahoo.restapi.StringResponse;
+import com.yahoo.vespa.hosted.controller.config.WellKnownFolderConfig;
+
+
+/**
+ * Responsible for serving contents from the RFC 8615 well-known directory
+ * @author olaa
+ */
+public class WellKnownApiHandler extends ThreadedHttpRequestHandler {
+
+ private final String securityTxt;
+
+ public WellKnownApiHandler(Context context, WellKnownFolderConfig wellKnownFolderConfig) {
+ super(context);
+ this.securityTxt = wellKnownFolderConfig.securityTxt();
+ }
+
+ @Override
+ public HttpResponse handle(HttpRequest request) {
+ switch (request.getMethod()) {
+ case GET: return get(request);
+ default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported");
+ }
+ }
+
+ private HttpResponse get(HttpRequest request) {
+ Path path = new Path(request.getUri());
+ if (path.matches("/.well-known/security.txt")) return securityTxt();
+ return ErrorResponse.notFoundError("Nothing at " + path);
+ }
+
+ private HttpResponse securityTxt() {
+ return new StringResponse(securityTxt);
+ }
+
+}
diff --git a/controller-server/src/main/resources/configdefinitions/vespa.hosted.controller.config.well-known-folder.def b/controller-server/src/main/resources/configdefinitions/vespa.hosted.controller.config.well-known-folder.def
new file mode 100644
index 00000000000..655d570bc58
--- /dev/null
+++ b/controller-server/src/main/resources/configdefinitions/vespa.hosted.controller.config.well-known-folder.def
@@ -0,0 +1,5 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Config for serving content from .well-known directory
+namespace=vespa.hosted.controller.config
+
+securityTxt string \ No newline at end of file
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandlerTest.java
new file mode 100644
index 00000000000..d46fc3f18cc
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/WellKnownApiHandlerTest.java
@@ -0,0 +1,50 @@
+package com.yahoo.vespa.hosted.controller.restapi.controller;
+
+import com.yahoo.application.container.handler.Request;
+import com.yahoo.vespa.hosted.controller.restapi.ContainerTester;
+import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author olaa
+ */
+class WellKnownApiHandlerTest extends ControllerContainerTest {
+
+ private ContainerTester tester;
+ private final String SECURITY_TXT = "Mocked security txt";
+
+ @BeforeEach
+ public void before() {
+ tester = new ContainerTester(container, "src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/");
+ }
+
+ @Test
+ void securityTxt() {
+ tester.assertResponse(new Request("http://localhost:8080/.well-known/security.txt"), SECURITY_TXT);
+ }
+
+ @Override
+ protected String variablePartXml() {
+ return String.format("""
+ <component id='com.yahoo.vespa.hosted.controller.security.CloudAccessControlRequests'/>
+ <component id='com.yahoo.vespa.hosted.controller.security.CloudAccessControl'/>
+ <handler id="com.yahoo.vespa.hosted.controller.restapi.controller.WellKnownApiHandler" bundle="controller-clients" >
+ <config name="vespa.hosted.controller.config.well-known-folder">
+ <securityTxt>%s</securityTxt>
+ </config>
+ <binding>http://*/.well-known/*</binding>
+ </handler>
+ <http>
+ <server id='default' port='8080' />
+ <filtering>
+ <request-chain id='default'>
+ <filter id='com.yahoo.jdisc.http.filter.security.misc.NoopFilter'/>
+ <binding>http://*/*</binding>
+ </request-chain>
+ </filtering>
+ </http>
+ """, SECURITY_TXT);
+ }
+
+} \ No newline at end of file