From a329853e8f77b5eb151b7f3f67a3453fe91974e3 Mon Sep 17 00:00:00 2001 From: Joel Thibault Date: Wed, 27 Mar 2024 12:05:09 -0400 Subject: [PATCH 1/2] Add a new hello-world endpoint --- .../leonardo/http/AppDependenciesBuilder.scala | 2 ++ .../dsde/workbench/leonardo/http/Boot.scala | 1 + .../http/CloudDependenciesBuilder.scala | 1 + .../leonardo/http/api/HelloRoutes.scala | 17 +++++++++++++++++ .../leonardo/http/api/HttpRoutes.scala | 5 ++++- .../leonardo/http/service/HelloService.scala | 7 +++++++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HelloRoutes.scala create mode 100644 http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/service/HelloService.scala diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/AppDependenciesBuilder.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/AppDependenciesBuilder.scala index a8ef483e520..7b811291664 100644 --- a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/AppDependenciesBuilder.scala +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/AppDependenciesBuilder.scala @@ -95,6 +95,7 @@ class AppDependenciesBuilder(baselineDependenciesBuilder: BaselineDependenciesBu as: ActorSystem, dbReference: DbReference[IO] ): Resource[IO, ServicesDependencies] = { + val helloService = new HelloService() val statusService = new StatusService(baselineDependencies.samDAO, dbReference) val diskV2Service = new DiskV2ServiceInterp[IO]( ConfigReader.appConfig.persistentDisk, @@ -125,6 +126,7 @@ class AppDependenciesBuilder(baselineDependenciesBuilder: BaselineDependenciesBu Resource.make[IO, ServicesDependencies]( IO( ServicesDependencies( + helloService, statusService, dependenciesRegistry, diskV2Service, diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/Boot.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/Boot.scala index 12c947d7df3..6a4c8bc6edb 100644 --- a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/Boot.scala +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/Boot.scala @@ -60,6 +60,7 @@ object Boot extends IOApp { val httpRoutes = new HttpRoutes( servicesDependencies.baselineDependencies.openIDConnectConfiguration, + servicesDependencies.helloService, servicesDependencies.statusService, servicesDependencies.cloudSpecificDependenciesRegistry, servicesDependencies.diskV2Service, diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/CloudDependenciesBuilder.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/CloudDependenciesBuilder.scala index 6edd2110ff1..e001f825289 100644 --- a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/CloudDependenciesBuilder.scala +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/CloudDependenciesBuilder.scala @@ -70,6 +70,7 @@ final case class LeoAppDependencies( * Contains all dependencies for the creation of the HTTP routes (services). */ final case class ServicesDependencies( + helloService: HelloService, statusService: StatusService, cloudSpecificDependenciesRegistry: ServicesRegistry, diskV2Service: DiskV2Service[IO], diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HelloRoutes.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HelloRoutes.scala new file mode 100644 index 00000000000..0355cb4ec71 --- /dev/null +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HelloRoutes.scala @@ -0,0 +1,17 @@ +package org.broadinstitute.dsde.workbench.leonardo.http.api + +import akka.http.scaladsl.model.StatusCodes +import akka.http.scaladsl.server +import akka.http.scaladsl.server.Directives.{complete, get, pathEndOrSingleSlash, pathPrefix} +import org.broadinstitute.dsde.workbench.leonardo.http.service.HelloService + +class HelloRoutes(helloService: HelloService) { + val routes: server.Route = + pathPrefix("hello") { + pathEndOrSingleSlash { + get { + complete(StatusCodes.OK -> helloService.getResponse) + } + } + } +} diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutes.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutes.scala index 6d11ebcf2cd..8421cc3d467 100644 --- a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutes.scala +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutes.scala @@ -29,6 +29,7 @@ import scala.concurrent.{ExecutionContext, Future} class HttpRoutes( oidcConfig: OpenIDConnectConfiguration, + helloService: HelloService, statusService: StatusService, gcpOnlyServicesRegistry: ServicesRegistry, diskV2Service: DiskV2Service[IO], @@ -41,6 +42,7 @@ class HttpRoutes( enableAzureOnlyRoutes: Boolean = false )(implicit ec: ExecutionContext, ac: ActorSystem, metrics: OpenTelemetryMetrics[IO], logger: StructuredLogger[IO]) { + private val helloRoutes = new HelloRoutes(helloService) private val statusRoutes = new StatusRoutes(statusService) private val corsSupport = new CorsSupport(contentSecurityPolicy, refererConfig) private val kubernetesRoutes = new AppRoutes(kubernetesService, userInfoDirectives) @@ -123,7 +125,8 @@ class HttpRoutes( "swagger/api-docs.yaml" ) ~ oidcConfig.oauth2Routes ~ proxyRoutes.get.route ~ statusRoutes.route ~ pathPrefix("api") { - runtimeRoutes.get.routes ~ runtimeV2Routes.routes ~ + helloRoutes.routes ~ + runtimeRoutes.get.routes ~ runtimeV2Routes.routes ~ diskRoutes.get.routes ~ kubernetesRoutes.routes ~ appV2Routes.routes ~ diskV2Routes.routes ~ adminRoutes.routes ~ resourcesRoutes.get.routes } diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/service/HelloService.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/service/HelloService.scala new file mode 100644 index 00000000000..c8a1eb2e269 --- /dev/null +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/service/HelloService.scala @@ -0,0 +1,7 @@ +package org.broadinstitute.dsde.workbench.leonardo.http.service; + +import cats.effect.IO + +class HelloService { + def getResponse: IO[String] = IO.pure("Hello, World!") +} From b12800403d0a0ff3defdc79303c2b4e277f05e9b Mon Sep 17 00:00:00 2001 From: Joel Thibault Date: Wed, 27 Mar 2024 13:14:14 -0400 Subject: [PATCH 2/2] fix tests --- .../dsde/workbench/leonardo/http/api/HttpRoutesSpec.scala | 7 +++++++ .../dsde/workbench/leonardo/http/api/ProxyRoutesSpec.scala | 2 ++ .../dsde/workbench/leonardo/http/api/TestLeoRoutes.scala | 3 +++ .../dsde/workbench/leonardo/provider/LeoProvider.scala | 2 ++ 4 files changed, 14 insertions(+) diff --git a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutesSpec.scala b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutesSpec.scala index 1ed93a49fcc..21c0156cfd0 100644 --- a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutesSpec.scala +++ b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/HttpRoutesSpec.scala @@ -60,6 +60,7 @@ class HttpRoutesSpec val routes = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, createGcpOnlyServicesRegistry(), MockDiskV2ServiceInterp, @@ -73,6 +74,7 @@ class HttpRoutesSpec val httpRoutesAzureOnly = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, createGcpOnlyServicesRegistry(), MockDiskV2ServiceInterp, @@ -88,6 +90,7 @@ class HttpRoutesSpec val routesWithStrictRefererConfig = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, createGcpOnlyServicesRegistry(), MockDiskV2ServiceInterp, @@ -102,6 +105,7 @@ class HttpRoutesSpec val routesWithWildcardReferer = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, createGcpOnlyServicesRegistry(), MockDiskV2ServiceInterp, @@ -116,6 +120,7 @@ class HttpRoutesSpec val routesWithDisabledRefererConfig = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, createGcpOnlyServicesRegistry(), MockDiskV2ServiceInterp, @@ -963,6 +968,7 @@ class HttpRoutesSpec new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, @@ -984,6 +990,7 @@ class HttpRoutesSpec new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, diff --git a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/ProxyRoutesSpec.scala b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/ProxyRoutesSpec.scala index c835322fd10..c182c232649 100644 --- a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/ProxyRoutesSpec.scala +++ b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/ProxyRoutesSpec.scala @@ -551,6 +551,7 @@ class ProxyRoutesSpec val httpRoutes = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, @@ -728,6 +729,7 @@ class ProxyRoutesSpec new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, diff --git a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/TestLeoRoutes.scala b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/TestLeoRoutes.scala index 8f1e8da4803..7445745914e 100644 --- a/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/TestLeoRoutes.scala +++ b/http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/TestLeoRoutes.scala @@ -173,6 +173,7 @@ trait TestLeoRoutes { MockGoogleOAuth2Service ) + val helloService = new HelloService() val statusService = new StatusService(mockSamDAO, testDbRef, pollInterval = 1.second) val timedUserInfo = defaultUserInfo.copy(tokenExpiresIn = tokenAge) @@ -208,6 +209,7 @@ trait TestLeoRoutes { val httpRoutes = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, @@ -222,6 +224,7 @@ trait TestLeoRoutes { val timedHttpRoutes = new HttpRoutes( openIdConnectionConfiguration, + helloService, statusService, gcpOnlyServicesRegistry, MockDiskV2ServiceInterp, diff --git a/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/LeoProvider.scala b/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/LeoProvider.scala index 95a8eea1dd1..41c0224b409 100644 --- a/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/LeoProvider.scala +++ b/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/LeoProvider.scala @@ -37,6 +37,7 @@ class LeoProvider extends AnyFlatSpec with BeforeAndAfterAll with PactVerifier { implicit val system: ActorSystem = ActorSystem("leotests") val mockOpenIDConnectConfiguration: OpenIDConnectConfiguration = mock[OpenIDConnectConfiguration] + val mockHelloService: HelloService = mock[HelloService] val mockStatusService: StatusService = mock[StatusService] val mockProxyService: ProxyService = mock[ProxyService] val mockRuntimeService: RuntimeService[IO] = mock[RuntimeService[IO]] @@ -63,6 +64,7 @@ class LeoProvider extends AnyFlatSpec with BeforeAndAfterAll with PactVerifier { val routes = new HttpRoutes( mockOpenIDConnectConfiguration, + mockHelloService, mockStatusService, gcpOnlyServicesRegistry, mockDiskV2Service,