Skip to content

Commit

Permalink
Remove the ability to tag storages
Browse files Browse the repository at this point in the history
  • Loading branch information
dantb committed Jan 18, 2024
1 parent 84be090 commit e8a5346
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.Storages._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.StorageTypeConfig
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageCommand._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageEvent.{StorageCreated, StorageDeprecated, StorageTagAdded, StorageUndeprecated, StorageUpdated}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageEvent._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.DiskStorageValue
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model._
Expand All @@ -29,7 +29,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sourcing.ScopedEntityDefinition.Tagger
import ch.epfl.bluebrain.nexus.delta.sourcing._
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, ProjectRef}
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem
import fs2.Stream
Expand Down Expand Up @@ -183,34 +182,6 @@ final class Storages private (
} yield res
}.span("updateStorage")

/**
* Add a tag to an existing storage
*
* @param id
* the storage identifier to expand as the id of the storage
* @param projectRef
* the project where the storage belongs
* @param tag
* the tag name
* @param tagRev
* the tag revision
* @param rev
* the current revision of the storage
*/
def tag(
id: IdSegment,
projectRef: ProjectRef,
tag: UserTag,
tagRev: Int,
rev: Int
)(implicit subject: Subject): IO[StorageResource] = {
for {
pc <- fetchContext.onModify(projectRef)
iri <- expandIri(id, pc)
res <- eval(TagStorage(iri, projectRef, tagRev, tag, rev, subject))
} yield res
}.span("tagStorage")

/**
* Deprecate an existing storage
*
Expand Down Expand Up @@ -464,16 +435,6 @@ object Storages {
} yield StorageUpdated(c.id, c.project, value, c.source, s.rev + 1, instant, c.subject)
}

def tag(c: TagStorage) = state match {
case None => IO.raiseError(StorageNotFound(c.id, c.project))
case Some(s) if s.rev != c.rev => IO.raiseError(IncorrectRev(c.rev, s.rev))
case Some(s) if c.targetRev <= 0 || c.targetRev > s.rev => IO.raiseError(RevisionNotFound(c.targetRev, s.rev))
case Some(s) =>
clock.realTimeInstant.map(
StorageTagAdded(c.id, c.project, s.value.tpe, c.targetRev, c.tag, s.rev + 1, _, c.subject)
)
}

def deprecate(c: DeprecateStorage) = state match {
case None => IO.raiseError(StorageNotFound(c.id, c.project))
case Some(s) if s.rev != c.rev => IO.raiseError(IncorrectRev(c.rev, s.rev))
Expand All @@ -493,7 +454,6 @@ object Storages {
cmd match {
case c: CreateStorage => create(c)
case c: UpdateStorage => update(c)
case c: TagStorage => tag(c)
case c: DeprecateStorage => deprecate(c)
case c: UndeprecateStorage => undeprecate(c)
}
Expand All @@ -510,15 +470,7 @@ object Storages {
StateMachine(None, evaluate(access, fetchPermissions, config, clock)(_, _), next),
StorageEvent.serializer,
StorageState.serializer,
Tagger[StorageEvent](
{
case r: StorageTagAdded => Some(r.tag -> r.targetRev)
case _ => None
},
{ _ =>
None
}
),
Tagger.noop[StorageEvent],
_ => None,
onUniqueViolation = (id: Iri, c: StorageCommand) =>
c match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import io.circe.Json

/**
Expand Down Expand Up @@ -87,25 +86,6 @@ object StorageCommand {
subject: Subject
) extends StorageCommand

/**
* Command to tag a storage
*
* @param id
* the storage identifier
* @param project
* the project the storage belongs to
* @param targetRev
* the revision that is being aliased with the provided ''tag''
* @param tag
* the tag of the alias for the provided ''tagRev''
* @param rev
* the last known revision of the storage
* @param subject
* the identity associated to this command
*/
final case class TagStorage(id: Iri, project: ProjectRef, targetRev: Int, tag: UserTag, rev: Int, subject: Subject)
extends StorageCommand

/**
* Command to deprecate a storage
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.RdfMarshalling
import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.model.routes.Tag
import io.circe.Json
import kamon.instrumentation.akka.http.TracingDirectives.operationName

Expand Down Expand Up @@ -175,21 +174,6 @@ final class StoragesRoutes(
.attemptNarrow[StorageRejection]
.rejectOn[StorageNotFound]
)
},
// Tag a storage
(post & parameter("rev".as[Int])) { rev =>
authorizeFor(project, Write).apply {
entity(as[Tag]) { case Tag(tagRev, tag) =>
emit(
Created,
storages
.tag(id, project, tag, tagRev, rev)
.flatTap(index(project, _, mode))
.mapValue(_.metadata)
.attemptNarrow[StorageRejection]
)
}
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,6 @@ private class StoragesSpec
}
}

"tagging a storage" should {

"succeed" in {
storages.tag(rdId, projectRef, tag, tagRev = 1, 1).accepted shouldEqual
resourceFor(
rdId,
projectRef,
remoteVal,
remoteFieldsJson,
rev = 2,
createdBy = bob,
updatedBy = bob,
tags = Tags(tag -> 1)
)
}

"reject if it doesn't exists" in {
storages.tag(nxv + "other", projectRef, tag, tagRev = 1, 1).rejectedWith[StorageNotFound]
}

"reject if project does not exist" in {
val projectRef = ProjectRef(org, Label.unsafe("other"))

storages.tag(rdId, projectRef, tag, tagRev = 2, 2).rejectedWith[ProjectContextRejection]
}

"reject if project is deprecated" in {
storages.tag(rdId, deprecatedProject.ref, tag, tagRev = 2, 2).rejectedWith[ProjectContextRejection]
}
}

"deprecating a storage" should {

"succeed" in {
Expand Down Expand Up @@ -202,23 +171,6 @@ private class StoragesSpec
"reject if project is deprecated" in {
storages.deprecate(s3Id, deprecatedProject.ref, 1).rejectedWith[ProjectContextRejection]
}

"allow tagging" in {
val payload = s3FieldsJson deepMerge json"""{"@id": "$s3Id", "default": false}"""
storages.tag(s3Id, projectRef, tag, tagRev = 3, 3).accepted shouldEqual
resourceFor(
s3Id,
projectRef,
s3Val.copy(default = false),
payload,
rev = 4,
deprecated = true,
createdBy = bob,
updatedBy = bob,
tags = Tags(tag -> 3)
)
}

}

"undeprecating a storage" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StorageGen.storageState
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.Storages.{evaluate, next}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.{DiskStorageConfig, StorageTypeConfig}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageCommand.{CreateStorage, DeprecateStorage, TagStorage, UndeprecateStorage, UpdateStorage}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageEvent.{StorageCreated, StorageDeprecated, StorageTagAdded, StorageUndeprecated, StorageUpdated}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.{DifferentStorageType, IncorrectRev, InvalidMaxFileSize, InvalidStorageType, PermissionsAreNotDefined, ResourceAlreadyExists, RevisionNotFound, StorageIsDeprecated, StorageIsNotDeprecated, StorageNotAccessible, StorageNotFound}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageCommand.{CreateStorage, DeprecateStorage, UndeprecateStorage, UpdateStorage}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageEvent._
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.{DifferentStorageType, InvalidMaxFileSize, InvalidStorageType, PermissionsAreNotDefined, ResourceAlreadyExists, StorageIsDeprecated, StorageIsNotDeprecated, StorageNotAccessible}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageType.{DiskStorage => DiskStorageType}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.{DiskStorageValue, RemoteDiskStorageValue, S3StorageValue}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.{AbsolutePath, DigestAlgorithm}
Expand Down Expand Up @@ -78,18 +78,6 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures {
}
}

"create a new event from a TagStorage command" in {
val state = storageState(dId, project, diskVal, rev = 3)
eval(Some(state), TagStorage(dId, project, 2, UserTag.unsafe("myTag"), 3, alice)).accepted shouldEqual
StorageTagAdded(dId, project, DiskStorageType, 2, UserTag.unsafe("myTag"), 4, epoch, alice)
}

"create a new event from a TagStorage command when storage is deprecated" in {
val state = storageState(dId, project, diskVal, rev = 3, deprecated = true)
eval(Some(state), TagStorage(dId, project, 2, UserTag.unsafe("myTag"), 3, alice)).accepted shouldEqual
StorageTagAdded(dId, project, DiskStorageType, 2, UserTag.unsafe("myTag"), 4, epoch, alice)
}

"create a new event from a DeprecateStorage command" in {
val state = storageState(dId, project, diskVal, rev = 3)
eval(Some(state), DeprecateStorage(dId, project, 3, alice)).accepted shouldEqual
Expand All @@ -102,19 +90,6 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures {
StorageUndeprecated(dId, project, DiskStorageType, 4, epoch, alice)
}

"reject with IncorrectRev" in {
val state = storageState(dId, project, diskVal)
val commands = List(
UpdateStorage(dId, project, diskFields, Json.obj(), 2, alice),
TagStorage(dId, project, 1, UserTag.unsafe("tag"), 2, alice),
DeprecateStorage(dId, project, 2, alice),
UndeprecateStorage(dId, project, 2, alice)
)
forAll(commands) { cmd =>
eval(Some(state), cmd).rejected shouldEqual IncorrectRev(provided = 2, expected = 1)
}
}

"reject with StorageNotAccessible" in {
val notAllowedDiskVal = diskFields.copy(volume = Some(tmp2))
val inaccessibleDiskVal =
Expand Down Expand Up @@ -186,17 +161,6 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures {
.rejectedWith[ResourceAlreadyExists]
}

"reject with StorageNotFound" in {
val commands = List(
UpdateStorage(dId, project, diskFields, Json.obj(), 2, alice),
TagStorage(dId, project, 1, UserTag.unsafe("tag"), 2, alice),
DeprecateStorage(dId, project, 2, alice)
)
forAll(commands) { cmd =>
eval(None, cmd).rejectedWith[StorageNotFound]
}
}

"reject with StorageIsDeprecated" in {
val state = storageState(dId, project, diskVal, rev = 2, deprecated = true)
val commands = List(
Expand All @@ -218,12 +182,6 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures {
}
}

"reject with RevisionNotFound" in {
val state = storageState(dId, project, diskVal)
eval(Some(state), TagStorage(dId, project, 3, UserTag.unsafe("myTag"), 1, alice)).rejected shouldEqual
RevisionNotFound(provided = 3, current = 1)
}

"reject with DifferentStorageType" in {
val diskCurrent = storageState(dId, project, diskVal)
val s3Current = storageState(s3Id, project, s3Val)
Expand Down
Loading

0 comments on commit e8a5346

Please sign in to comment.