From e8bdcbda5c8e0e382660044d84cf3792b09e00c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=A3o=20Mata?= Date: Mon, 6 Mar 2017 13:54:08 +0100 Subject: [PATCH] Remove admin routes from `mydevice` routes --- .../treehub/http/ObjectResource.scala | 14 +++++++++++++- .../treehub/http/TreeHubRoutes.scala | 14 ++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/scala/com/advancedtelematic/treehub/http/ObjectResource.scala b/src/main/scala/com/advancedtelematic/treehub/http/ObjectResource.scala index 0aa6a01..0f4d30c 100644 --- a/src/main/scala/com/advancedtelematic/treehub/http/ObjectResource.scala +++ b/src/main/scala/com/advancedtelematic/treehub/http/ObjectResource.scala @@ -31,7 +31,7 @@ class ObjectResource(namespace: Directive1[Namespace], objectStore: ObjectStore, usageHandler ! UpdateBandwidth(namespace, usageBytes, objectId) } - val route = namespace { ns => + val deviceRoutes = namespace { ns => path("objects" / PrefixedObjectId) { objectId => head { val f = objectStore.exists(ns, objectId).map { @@ -60,4 +60,16 @@ class ObjectResource(namespace: Directive1[Namespace], objectStore: ObjectStore, } } } + + val adminRoutes = + path("objects" / PrefixedObjectId) { objectId => + namespace { ns => + (post & hintNamespaceStorage(ns)) { + fileUpload("file") { case (_, content) => + val f = objectStore.store(ns, objectId, content).map(_ => StatusCodes.OK) + complete(f) + } + } + } + } } diff --git a/src/main/scala/com/advancedtelematic/treehub/http/TreeHubRoutes.scala b/src/main/scala/com/advancedtelematic/treehub/http/TreeHubRoutes.scala index 381a15c..dd335e6 100644 --- a/src/main/scala/com/advancedtelematic/treehub/http/TreeHubRoutes.scala +++ b/src/main/scala/com/advancedtelematic/treehub/http/TreeHubRoutes.scala @@ -23,24 +23,30 @@ class TreeHubRoutes(tokenValidator: Directive0, import Directives._ - def allRoutes(nsExtract: Directive1[Namespace], coreClient: Core): Route = { + def deviceRoutes(nsExtract: Directive1[Namespace], coreClient: Core): Route = { new ConfResource().route ~ - new ObjectResource(nsExtract, objectStore, usageHandler).route ~ + new ObjectResource(nsExtract, objectStore, usageHandler).deviceRoutes ~ new RefResource(nsExtract, coreClient, objectStore).route } + def allRoutes(nsExtract: Directive1[Namespace], coreClient: Core): Route = { + deviceRoutes(nsExtract, coreClient) ~ + new ObjectResource(nsExtract, objectStore, usageHandler).adminRoutes + } + val routes: Route = handleRejections(rejectionHandler) { ErrorHandler.handleErrors { (pathPrefix("api" / "v2") & tokenValidator) { allRoutes(namespaceExtractor, coreHttpClient) ~ pathPrefix("mydevice") { - allRoutes(deviceNamespace, coreHttpClient) + deviceRoutes(deviceNamespace, coreHttpClient) } } ~ (pathPrefix("api" / "v3") & tokenValidator) { allRoutes(namespaceExtractor, coreBusClient) - } ~ new HealthResource(db, versionMap).route + } ~ + new HealthResource(db, versionMap).route } } }