Skip to content

Commit

Permalink
Use director-v1 response format
Browse files Browse the repository at this point in the history
This is the wrong format to return but it's the cleanest way to
implement a backwards compatible that ota-app can use until we finish
deploying director-lite

Signed-off-by: Simão Mata <[email protected]>
  • Loading branch information
simao committed Jan 28, 2020
1 parent f552eef commit 009a945
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
10 changes: 0 additions & 10 deletions src/main/scala/com/advancedtelematic/director/Settings.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.advancedtelematic.director

import com.advancedtelematic.libtuf.data.TufDataType.KeyType
import com.typesafe.config.ConfigFactory

import scala.util.Try

trait Settings {
import Util._

Expand All @@ -14,11 +11,4 @@ trait Settings {
val port = _config.getInt("server.port")

val tufUri = mkUri(_config, "keyserver.uri")
val tufBinaryUri = mkUri(_config, "tuf.binary.uri")

val defaultKeyType: Try[KeyType] = {
Try(_config.getString("daemon.defaultKeyType")).map { defaultKeyTypeName =>
namedType[KeyType](defaultKeyTypeName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import com.advancedtelematic.director.data.Codecs._
import com.advancedtelematic.director.db.MultiTargetUpdates
import com.advancedtelematic.libats.data.DataType.Namespace

import scala.concurrent.{ExecutionContext, Future}


import scala.concurrent.ExecutionContext
import com.advancedtelematic.libats.codecs.CirceCodecs._

class MultiTargetUpdatesResource(extractNamespace: Directive1[Namespace])(implicit val db: Database, val ec: ExecutionContext) {
import Directives._
Expand All @@ -23,7 +21,10 @@ class MultiTargetUpdatesResource(extractNamespace: Directive1[Namespace])(implic
val route = extractNamespace { ns =>
pathPrefix("multi_target_updates") {
(get & pathPrefix(UpdateId.Path)) { uid =>
complete(multiTargetUpdates.find(ns, uid))
// For some reason director-v1 accepts `{targets: ...}` but returns `{...}`
// To make app compatible with director-v2, for now we do the same, but we should be returning what we accept:
// complete(multiTargetUpdates.find(ns, uid))
complete(multiTargetUpdates.find(ns, uid).map(_.targets))
} ~
(post & pathEnd) {
entity(as[MultiTargetUpdate]) { mtuRequest =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.advancedtelematic.director.http
import cats.syntax.show._
import akka.http.scaladsl.model.StatusCodes
import com.advancedtelematic.director.data.AdminDataType.MultiTargetUpdate
import cats.syntax.show._
import com.advancedtelematic.director.data.AdminDataType.{MultiTargetUpdate, TargetUpdateRequest}
import com.advancedtelematic.director.data.Codecs._
import com.advancedtelematic.director.data.Generators
import com.advancedtelematic.director.util.{DefaultPatience, DirectorSpec, RouteResourceSpec}
import com.advancedtelematic.libats.codecs.CirceCodecs._
import com.advancedtelematic.libats.data.ErrorCodes.MissingEntity
import com.advancedtelematic.libats.data.ErrorRepresentation
import com.advancedtelematic.libats.messaging_datatype.DataType.UpdateId
import com.advancedtelematic.libats.data.ErrorCodes.MissingEntity
import com.advancedtelematic.libtuf.data.TufDataType.HardwareIdentifier
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import com.advancedtelematic.director.data.GeneratorOps._
import com.advancedtelematic.director.data.Codecs._
import com.advancedtelematic.director.http.AdminResources

class MultiTargetUpdatesResourceSpec extends DirectorSpec
with Generators with DefaultPatience with RouteResourceSpec with AdminResources {
Expand All @@ -24,7 +24,18 @@ class MultiTargetUpdatesResourceSpec extends DirectorSpec
}
}

testWithNamespace("Legacy API: can GET multi-target updates") { implicit ns =>
val mtu = createMtuOk()

Get(apiUri(s"multi_target_updates/${mtu.show}")).namespaced ~> routes ~> check {
status shouldBe StatusCodes.OK
responseAs[Map[HardwareIdentifier, TargetUpdateRequest]] // This should be responseAs[MultiTargetUpdate], see comments on resource
}
}

testWithNamespace("can GET multi-target updates") { implicit ns =>
pending // due to legacy api support

val mtu = createMtuOk()

Get(apiUri(s"multi_target_updates/${mtu.show}")).namespaced ~> routes ~> check {
Expand All @@ -33,6 +44,7 @@ class MultiTargetUpdatesResourceSpec extends DirectorSpec
}
}


testWithNamespace("accepts mtu with an update") { implicit ns =>
createMtuOk()
}
Expand Down

0 comments on commit 009a945

Please sign in to comment.