Skip to content

Commit 100566a

Browse files
author
Ben Clouser
committed
Merge branch 'bug/1803' into 'master'
[OTA-1803] Actually use offset and limit params in reposerverClient when fetching targets Closes OTA-1803 See merge request torizon-platform/ota-tuf!317
2 parents 789c4a8 + 381348c commit 100566a

File tree

8 files changed

+110
-44
lines changed

8 files changed

+110
-44
lines changed

build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ lazy val commonConfigs = Seq(ItTest, UnitTest)
1313
lazy val commonDeps = libraryDependencies ++= {
1414
val scalaTestV = "3.2.16"
1515
lazy val libatsV = libatsVersion.value
16-
lazy val catsV = "2.9.0"
16+
lazy val catsV = "2.10.0"
1717

1818
Seq(
1919
"org.scala-lang.modules" %% "scala-async" % "1.0.1",
@@ -59,7 +59,7 @@ lazy val commonSettings = Seq(
5959
Compile / console / scalacOptions ~= (_.filterNot(_ == "-Ywarn-unused-import")),
6060
resolvers += "sonatype-snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots",
6161
resolvers += "sonatype-releases" at "https://s01.oss.sonatype.org/content/repositories/releases",
62-
libatsVersion := "2.1.1",
62+
libatsVersion := "2.1.2",
6363
licenses += ("MPL-2.0", url("http://mozilla.org/MPL/2.0/")),
6464
description := "scala tuf implementation support",
6565
buildInfoOptions += BuildInfoOption.ToMap,

cli/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0"
22

33
libraryDependencies += "org.slf4j" % "slf4j-api" % "2.0.7"
44

5-
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.4.8"
5+
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.4.11"
66

77
libraryDependencies += "io.circe" %% "circe-generic-extras" % "0.14.3"
88

libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/repo/client/ReposerverClient.scala

+6-10
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,10 @@ class ReposerverHttpClient(reposerverUri: Uri, httpClient: HttpRequest => Future
261261
nameContains: Option[String] = None,
262262
offset: Option[Long] = None,
263263
limit: Option[Long] = None): Future[PaginationResult[ClientTargetItem]] = {
264-
val reqUri = if (nameContains.isDefined)
265-
apiUri(Path(s"user_repo/target_items")).withQuery(Query("nameContains" -> nameContains.get))
266-
else
267-
apiUri(Path(s"user_repo/target_items"))
268-
val req = HttpRequest(HttpMethods.GET, uri = reqUri)
269-
execHttpUnmarshalledWithNamespace[PaginationResult[ClientTargetItem]](namespace, req).ok
264+
val nameContainsMap = nameContains.map(n => Map("nameContains" -> n)).getOrElse(Map.empty)
265+
266+
val reqUri = apiUri(Path(s"user_repo/target_items")).withQuery(Query(paginationParams(offset, limit) ++ (nameContainsMap)))
267+
execHttpUnmarshalledWithNamespace[PaginationResult[ClientTargetItem]](namespace, HttpRequest(HttpMethods.GET, uri = reqUri)).ok
270268
}
271269

272270
override def fetchDelegationMetadata(namespace: Namespace, roleName: String): Future[JsonSignedPayload] = {
@@ -309,12 +307,10 @@ class ReposerverHttpClient(reposerverUri: Uri, httpClient: HttpRequest => Future
309307
offset: Option[Long],
310308
limit: Option[Long]): Future[PaginationResult[FilenameComment]] = {
311309

312-
val nameContainsMap = if (targetNameContains.isDefined)
313-
Map[String, String]("nameContains" -> targetNameContains.getOrElse(""))
314-
else Map.empty[String, String]
310+
val nameContainsMap = targetNameContains.map(c => Map("nameContains" -> c)).getOrElse(Map.empty)
315311

316312
val commentUri = apiUri(Path("user_repo/comments")).withQuery(
317-
Query(paginationParams(offset, limit) .++ (nameContainsMap))
313+
Query(paginationParams(offset, limit) ++ (nameContainsMap))
318314
)
319315
val req = HttpRequest(HttpMethods.GET, uri = commentUri)
320316

libtuf/build.sbt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
libraryDependencies ++= {
2-
val bouncyCastleV = "1.75"
2+
val bouncyCastleV = "1.76"
33

44
Seq(
55
"org.bouncycastle" % "bcprov-jdk18on" % bouncyCastleV,
@@ -9,7 +9,7 @@ libraryDependencies ++= {
99
"com.softwaremill.sttp.client" %% "slf4j-backend" % "2.3.0",
1010
"com.softwaremill.sttp.client" %% "async-http-client-backend-future" % "2.3.0",
1111
"org.slf4j" % "slf4j-api" % "1.7.16" % "provided",
12-
"com.azure" % "azure-storage-blob" % "12.22.3",
13-
"com.azure" % "azure-identity" % "1.9.1"
12+
"com.azure" % "azure-storage-blob" % "12.23.0",
13+
"com.azure" % "azure-identity" % "1.10.0"
1414
)
1515
}

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
sbt.version=1.9.1
1+
sbt.version=1.9.3
22

33

project/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.12.501"
2+
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.12.533"
33

44
libraryDependencies += "org.apache.commons" % "commons-compress" % "1.23.0"
55

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
22
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
33
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
4-
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.7")
4+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.9")
55
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1")
66
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
77
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")

reposerver/src/test/scala/com/advancedtelematic/tuf/reposerver/http/RepoResourceSpec.scala

+95-25
Original file line numberDiff line numberDiff line change
@@ -1392,69 +1392,139 @@ class RepoResourceSpec extends TufReposerverSpec with RepoResourceSpecUtil
13921392
withRandomNamepace { implicit ns =>
13931393
createRepo()
13941394
// create packages
1395-
Put(apiUri(s"user_repo/targets/cheerios-0.0.5?name=cheerios&version=0.0.5"), form).namespaced ~> routes ~> check {
1396-
status shouldBe StatusCodes.OK
1397-
responseAs[SignedPayload[TargetsRole]]
1398-
}
1399-
Put(apiUri(s"user_repo/targets/cheerios-0.0.6?name=cheerios&version=0.0.6"), form).namespaced ~> routes ~> check {
1400-
status shouldBe StatusCodes.OK
1401-
responseAs[SignedPayload[TargetsRole]]
1395+
(1 to 100 by 1).foreach { idx =>
1396+
Put(apiUri(s"user_repo/targets/riceKrispies-0.0."+idx+"?name=riceKrispies&version=0.0."+idx), form).namespaced ~> routes ~> check {
1397+
status shouldBe StatusCodes.OK
1398+
responseAs[SignedPayload[TargetsRole]]
1399+
}
14021400
}
1403-
Put(apiUri(s"user_repo/targets/riceKrispies-0.0.1?name=riceKrispies&version=0.0.1"), form).namespaced ~> routes ~> check {
1401+
Get(apiUri(s"user_repo/target_items")).namespaced ~> routes ~> check {
14041402
status shouldBe StatusCodes.OK
1405-
responseAs[SignedPayload[TargetsRole]]
1403+
val paged = responseAs[PaginationResult[ClientTargetItem]]
1404+
println(paged)
1405+
paged.total shouldBe 100
1406+
paged.offset shouldBe 0 // default
1407+
paged.limit shouldBe 50 // default
1408+
paged.values.length shouldEqual (paged.limit)
1409+
val targetCustoms = paged.map { clientTargetItem =>
1410+
clientTargetItem.custom.asJson.as[TargetCustom] match {
1411+
case Right(custom) => custom
1412+
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
1413+
}
1414+
}
1415+
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1416+
(1 to 50 by 1).foreach { idx =>
1417+
nameVersionTuple should contain("riceKrispies", "0.0." + idx)
1418+
}
1419+
(51 to 100 by 1).foreach { idx =>
1420+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1421+
}
14061422
}
14071423
Get(apiUri(s"user_repo/target_items?offset=1")).namespaced ~> routes ~> check {
14081424
status shouldBe StatusCodes.OK
14091425
val paged = responseAs[PaginationResult[ClientTargetItem]]
14101426
println(paged)
1411-
paged.total shouldBe 3
1427+
paged.total shouldBe 100
14121428
paged.offset shouldBe 1
1413-
paged.limit shouldBe 50
1429+
paged.limit shouldBe 50 // default
1430+
paged.values.length shouldEqual(paged.limit)
14141431
val targetCustoms = paged.map { clientTargetItem =>
14151432
clientTargetItem.custom.asJson.as[TargetCustom] match {
14161433
case Right(custom) => custom
14171434
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
14181435
}
14191436
}
14201437
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1421-
nameVersionTuple should not contain("cheerios", "0.0.5")
1422-
nameVersionTuple should contain("cheerios", "0.0.6")
1423-
nameVersionTuple should contain("riceKrispies", "0.0.1")
1438+
nameVersionTuple should not contain("riceKrispies", "0.0.1")
1439+
(2 to 51 by 1).foreach { idx =>
1440+
nameVersionTuple should contain("riceKrispies", "0.0." + idx)
1441+
}
1442+
(52 to 100 by 1).foreach { idx =>
1443+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1444+
}
14241445
}
14251446
Get(apiUri(s"user_repo/target_items?limit=2")).namespaced ~> routes ~> check {
14261447
status shouldBe StatusCodes.OK
14271448
val paged = responseAs[PaginationResult[ClientTargetItem]]
1428-
paged.total shouldBe 3
1449+
paged.total shouldBe 100
14291450
paged.offset shouldBe 0
14301451
paged.limit shouldBe 2
1452+
paged.values.length shouldEqual(paged.limit)
14311453
val targetCustoms = paged.map { clientTargetItem =>
14321454
clientTargetItem.custom.asJson.as[TargetCustom] match {
14331455
case Right(custom) => custom
14341456
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
14351457
}
14361458
}
14371459
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1438-
nameVersionTuple should contain("cheerios", "0.0.5")
1439-
nameVersionTuple should contain("cheerios", "0.0.6")
1440-
nameVersionTuple should not contain("riceKrispies", "0.0.1")
1460+
nameVersionTuple should contain("riceKrispies", "0.0.1")
1461+
nameVersionTuple should contain("riceKrispies", "0.0.2")
1462+
(3 to 100 by 1).foreach { idx =>
1463+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1464+
}
14411465
}
1442-
Get(apiUri(s"user_repo/target_items?offset=1&limit=1")).namespaced ~> routes ~> check {
1466+
Get(apiUri(s"user_repo/target_items?offset=30&limit=30")).namespaced ~> routes ~> check {
14431467
status shouldBe StatusCodes.OK
14441468
val paged = responseAs[PaginationResult[ClientTargetItem]]
1445-
paged.total shouldBe 3
1446-
paged.offset shouldBe 1
1447-
paged.limit shouldBe 1
1469+
paged.total shouldBe 100
1470+
paged.offset shouldBe 30
1471+
paged.limit shouldBe 30
1472+
paged.values.length shouldEqual(paged.limit)
14481473
val targetCustoms = paged.map { clientTargetItem =>
14491474
clientTargetItem.custom.asJson.as[TargetCustom] match {
14501475
case Right(custom) => custom
14511476
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
14521477
}
14531478
}
14541479
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1455-
nameVersionTuple should not contain("cheerios", "0.0.5")
1456-
nameVersionTuple should contain("cheerios", "0.0.6")
1457-
nameVersionTuple should not contain("riceKrispies", "0.0.1")
1480+
(1 to 30 by 1).foreach { idx =>
1481+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1482+
}
1483+
(31 to 60 by 1).foreach { idx =>
1484+
nameVersionTuple should contain("riceKrispies", "0.0." + idx)
1485+
}
1486+
}
1487+
Get(apiUri(s"user_repo/target_items?offset=30&limit=60")).namespaced ~> routes ~> check {
1488+
status shouldBe StatusCodes.OK
1489+
val paged = responseAs[PaginationResult[ClientTargetItem]]
1490+
paged.total shouldBe 100
1491+
paged.offset shouldBe 30
1492+
paged.limit shouldBe 60
1493+
paged.values.length shouldEqual (paged.limit)
1494+
val targetCustoms = paged.map { clientTargetItem =>
1495+
clientTargetItem.custom.asJson.as[TargetCustom] match {
1496+
case Right(custom) => custom
1497+
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
1498+
}
1499+
}
1500+
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1501+
(1 to 30 by 1).foreach { idx =>
1502+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1503+
}
1504+
(31 to 90 by 1).foreach { idx =>
1505+
nameVersionTuple should contain("riceKrispies", "0.0." + idx)
1506+
}
1507+
}
1508+
Get(apiUri(s"user_repo/target_items?offset=30&limit=90")).namespaced ~> routes ~> check {
1509+
status shouldBe StatusCodes.OK
1510+
val paged = responseAs[PaginationResult[ClientTargetItem]]
1511+
paged.total shouldBe 100
1512+
paged.offset shouldBe 30
1513+
paged.limit shouldBe 90
1514+
paged.values.length shouldEqual(70) // 100 (total) - 30 (offset)
1515+
val targetCustoms = paged.map { clientTargetItem =>
1516+
clientTargetItem.custom.asJson.as[TargetCustom] match {
1517+
case Right(custom) => custom
1518+
case Left(err) => println(s"Failed to parse json. Error: ${err.toString}"); throw err
1519+
}
1520+
}
1521+
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1522+
(1 to 30 by 1).foreach { idx =>
1523+
nameVersionTuple should not contain("riceKrispies", "0.0." + idx)
1524+
}
1525+
(31 to 100 by 1).foreach { idx =>
1526+
nameVersionTuple should contain("riceKrispies", "0.0." + idx)
1527+
}
14581528
}
14591529
}
14601530
}

0 commit comments

Comments
 (0)