From 71c2f102e3eb84c7008943cd469f95be164ed89d Mon Sep 17 00:00:00 2001 From: Ben Clouser Date: Wed, 8 Nov 2023 12:22:21 -0500 Subject: [PATCH] [OTA-2068] Add reposerverClient method for updating targets metadata expiration Signed-off-by: Ben Clouser --- deploy/ci_setup.sh | 5 +++-- .../libtuf_server/data/Requests.scala | 11 +++++++++-- .../repo/client/ReposerverClient.scala | 14 +++++++++++++- .../tuf/reposerver/http/RepoResource.scala | 10 ---------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/deploy/ci_setup.sh b/deploy/ci_setup.sh index 573a6c5d..5c02447f 100755 --- a/deploy/ci_setup.sh +++ b/deploy/ci_setup.sh @@ -2,6 +2,7 @@ set -u +MARIADB_VERSION=10.11 docker rm --force ota_tuf-mariadb # Some jobs don't behave, nuke them all @@ -18,7 +19,7 @@ function start_mariadb() { -e MYSQL_ROOT_PASSWORD=root \ -e MYSQL_USER=ota_tuf \ -e MYSQL_PASSWORD=ota_tuf \ - mariadb:10.2 \ + mariadb:${MARIADB_VERSION} \ --character-set-server=utf8 --collation-server=utf8_unicode_ci \ --max_connections=1000 } @@ -27,7 +28,7 @@ function mysqladmin_alive { docker run \ --rm \ --link ota_tuf-mariadb \ - mariadb:10.2 \ + mariadb:${MARIADB_VERSION} \ mysqladmin ping --protocol=TCP -h ota_tuf-mariadb -P 3306 -u root -proot } diff --git a/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/data/Requests.scala b/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/data/Requests.scala index daeb8fa0..ab5c7d80 100644 --- a/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/data/Requests.scala +++ b/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/data/Requests.scala @@ -1,12 +1,14 @@ package com.advancedtelematic.libtuf_server.data -import com.advancedtelematic.libats.codecs.CirceCodecs._ -import com.advancedtelematic.libtuf.data.TufCodecs._ +import com.advancedtelematic.libats.codecs.CirceCodecs.* +import com.advancedtelematic.libtuf.data.TufCodecs.* import com.advancedtelematic.libtuf.data.TufDataType.{KeyType, TargetFilename} import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.deriveEncoder import io.circe.generic.semiauto.deriveDecoder +import java.time.Instant + object Requests { case class CreateRepositoryRequest(keyType: KeyType) @@ -28,4 +30,9 @@ object Requests { implicit val filenameCommentEncoder: Encoder[FilenameComment] = deriveEncoder implicit val filenameCommentDecoder: Decoder[FilenameComment] = deriveDecoder + + case class ExpireNotBeforeRequest(expireAt: Instant) + + implicit val refreshRequestEncoder: Encoder[ExpireNotBeforeRequest] = io.circe.generic.semiauto.deriveEncoder[ExpireNotBeforeRequest] + implicit val refreshRequestDecoder: Decoder[ExpireNotBeforeRequest] = io.circe.generic.semiauto.deriveDecoder[ExpireNotBeforeRequest] } diff --git a/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/repo/client/ReposerverClient.scala b/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/repo/client/ReposerverClient.scala index 4c7631f4..60278e95 100644 --- a/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/repo/client/ReposerverClient.scala +++ b/libtuf-server/src/main/scala/com/advancedtelematic/libtuf_server/repo/client/ReposerverClient.scala @@ -5,6 +5,7 @@ import akka.http.scaladsl.marshalling.Marshal import akka.http.scaladsl.model.* import akka.http.scaladsl.model.Uri.Path.Slash import akka.http.scaladsl.model.Uri.{Path, Query} +import akka.http.scaladsl.model.* import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller import akka.http.scaladsl.util.FastFuture import akka.stream.Materializer @@ -15,6 +16,7 @@ import com.advancedtelematic.libats.data.DataType.{Checksum, Namespace} import com.advancedtelematic.libats.data.{ErrorCode, PaginationResult} import com.advancedtelematic.libats.http.Errors.{RawError, RemoteServiceError} import com.advancedtelematic.libats.http.ServiceHttpClientSupport +import com.advancedtelematic.libats.http.HttpCodecs.* import com.advancedtelematic.libats.http.tracing.Tracing.ServerRequestTracing import com.advancedtelematic.libats.http.tracing.TracingHttpClient import com.advancedtelematic.libtuf.data.ClientCodecs.* @@ -22,10 +24,12 @@ import com.advancedtelematic.libtuf.data.ClientDataType.{ClientTargetItem, Deleg import com.advancedtelematic.libtuf.data.TufCodecs.* import com.advancedtelematic.libtuf.data.TufDataType.TargetFormat.TargetFormat import com.advancedtelematic.libtuf.data.TufDataType.{HardwareIdentifier, JsonSignedPayload, KeyType, RepoId, SignedPayload, TargetFilename, TargetName, TargetVersion} -import com.advancedtelematic.libtuf_server.data.Requests.{CommentRequest, CreateRepositoryRequest, FilenameComment, TargetComment} +import com.advancedtelematic.libtuf_server.data.Requests.{CommentRequest, CreateRepositoryRequest, ExpireNotBeforeRequest, FilenameComment, TargetComment} import com.advancedtelematic.libtuf_server.repo.client.ReposerverClient.{DelegationInfo, KeysNotReady, NotFound, RootNotInKeyserver} import io.circe.generic.semiauto.* import io.circe.{Codec, Decoder, Encoder, Json} +import com.advancedtelematic.libats.codecs.CirceCodecs.* +import com.advancedtelematic.libtuf.data.ClientCodecs.* import org.slf4j.LoggerFactory import java.net.URI @@ -104,6 +108,8 @@ trait ReposerverClient { def fetchTargets(namespace: Namespace): Future[SignedPayload[TargetsRole]] def setTargetComments(namespace: Namespace, targetFilename: TargetFilename, comment: String): Future[Unit] + + def setTargetsMetadataExpiration(namespace: Namespace, expiry: Instant): Future[Unit] def fetchSingleTargetComments(namespace: Namespace, targetFilename: TargetFilename): Future[FilenameComment] def fetchTargetsComments(namespace: Namespace, targetNameContains: Option[String], offset: Option[Long], limit: Option[Long]): Future[PaginationResult[FilenameComment]] def fetchTargetsCommentsByFilename(namespace: Namespace, filenames: Seq[TargetFilename]): Future[Seq[FilenameComment]] @@ -298,6 +304,12 @@ class ReposerverHttpClient(reposerverUri: Uri, httpClient: HttpRequest => Future execHttpUnmarshalledWithNamespace[Unit](namespace, req).ok } + override def setTargetsMetadataExpiration(namespace: Namespace, expiry: Instant): Future[Unit] = { + val body = HttpEntity(ContentTypes.`application/json`, ExpireNotBeforeRequest(expiry).asJson.noSpaces) + val req = HttpRequest(HttpMethods.PUT, uri = apiUri(Path(s"user_repo/targets/expire/not-before")), entity = body) + execHttpUnmarshalledWithNamespace[Unit](namespace, req).ok + } + override def fetchTargetsComments(namespace: Namespace, targetNameContains: Option[String], offset: Option[Long], diff --git a/reposerver/src/main/scala/com/advancedtelematic/tuf/reposerver/http/RepoResource.scala b/reposerver/src/main/scala/com/advancedtelematic/tuf/reposerver/http/RepoResource.scala index 5c037fb7..1a3c6c5f 100644 --- a/reposerver/src/main/scala/com/advancedtelematic/tuf/reposerver/http/RepoResource.scala +++ b/reposerver/src/main/scala/com/advancedtelematic/tuf/reposerver/http/RepoResource.scala @@ -590,13 +590,3 @@ class RepoResource(keyserverClient: KeyserverClient, namespaceValidation: Namesp modifyRepoRoutes(repoId) } } - -object ExpireNotBeforeRequest { - import io.circe.{Encoder, Decoder} - - implicit val refreshRequestEncoder: Encoder[ExpireNotBeforeRequest] = io.circe.generic.semiauto.deriveEncoder[ExpireNotBeforeRequest] - implicit val refreshRequestDecoder: Decoder[ExpireNotBeforeRequest] = io.circe.generic.semiauto.deriveDecoder[ExpireNotBeforeRequest] -} - - -case class ExpireNotBeforeRequest(expireAt: Instant)