From babbfbc671a47545aaa335ff3c9b80d246ed10c8 Mon Sep 17 00:00:00 2001 From: Simon Dumas Date: Thu, 28 Nov 2024 12:45:18 +0100 Subject: [PATCH] Scalafmt --- .../BlazegraphServiceDependency.scala | 4 +- .../ElasticSearchServiceDependency.scala | 4 +- .../storage/files/model/FileRejection.scala | 12 ++-- .../storage/files/routes/FilesRoutes.scala | 4 +- .../storages/StorageDeletionTask.scala | 4 +- .../storage/storages/StoragesConfig.scala | 12 ++-- .../storages/access/StorageAccess.scala | 4 +- .../storage/storages/model/Storage.scala | 2 +- .../storage/storages/model/StorageState.scala | 6 +- .../storages/operations/FileOperations.scala | 8 +-- .../storages/operations/UploadingFile.scala | 4 +- .../plugins/storage/files/FilesSpec.scala | 70 ++++++++++++++----- .../plugins/storage/files/FilesStmSpec.scala | 12 ++-- .../storage/storages/StorageFixtures.scala | 8 +-- .../storage/storages/StoragesStmSpec.scala | 54 +++++++------- .../storages/model/StorageFieldsSpec.scala | 2 +- .../model/StorageSerializationSuite.scala | 6 +- .../storage/storages/model/StorageSpec.scala | 18 ++--- .../disk/DiskStorageSaveFileSpec.scala | 2 +- .../storages/routes/StoragesRoutesSpec.scala | 10 +-- 20 files changed, 142 insertions(+), 104 deletions(-) diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphServiceDependency.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphServiceDependency.scala index 87917300ed..de20d1af9c 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphServiceDependency.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphServiceDependency.scala @@ -6,8 +6,8 @@ import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient /** - * Describes the Blazegraph [[ServiceDependency]] providing a way to extract the [[ServiceDescription]] from - * its ''/status'' endpoint + * Describes the Blazegraph [[ServiceDependency]] providing a way to extract the [[ServiceDescription]] from its + * ''/status'' endpoint */ class BlazegraphServiceDependency(client: BlazegraphClient) extends ServiceDependency { diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchServiceDependency.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchServiceDependency.scala index 0cc3229ee3..019a96b519 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchServiceDependency.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchServiceDependency.scala @@ -6,8 +6,8 @@ import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.client.ElasticSearchClient /** - * Describes the Elasticsearch [[ServiceDependency]] providing a way to extract the [[ServiceDescription]] - * from Elasticsearch + * Describes the Elasticsearch [[ServiceDependency]] providing a way to extract the [[ServiceDescription]] from + * Elasticsearch */ class ElasticSearchServiceDependency(client: ElasticSearchClient) extends ServiceDependency { diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileRejection.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileRejection.scala index 01f67d1ea4..d0e6923d5a 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileRejection.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileRejection.scala @@ -186,14 +186,14 @@ object FileRejection { val tpe = ClassUtils.simpleName(r) val obj = JsonObject(keywords.tpe -> tpe.asJson, "reason" -> r.reason.asJson) r match { - case WrappedAkkaRejection(rejection) => rejection.asJsonObject - case SaveRejection(_, _, rejection) => + case WrappedAkkaRejection(rejection) => rejection.asJsonObject + case SaveRejection(_, _, rejection) => obj.add(keywords.tpe, ClassUtils.simpleName(rejection).asJson).add("details", rejection.loggedDetails.asJson) - case FetchRejection(_, _, rejection) => + case FetchRejection(_, _, rejection) => obj.add(keywords.tpe, ClassUtils.simpleName(rejection).asJson).add("details", rejection.loggedDetails.asJson) - case IncorrectRev(provided, expected) => obj.add("provided", provided.asJson).add("expected", expected.asJson) - case _: FileNotFound => obj.add(keywords.tpe, "ResourceNotFound".asJson) - case _ => obj + case IncorrectRev(provided, expected) => obj.add("provided", provided.asJson).add("expected", expected.asJson) + case _: FileNotFound => obj.add(keywords.tpe, "ResourceNotFound".asJson) + case _ => obj } } diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/routes/FilesRoutes.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/routes/FilesRoutes.scala index 73868b28dc..d8b2789679 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/routes/FilesRoutes.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/routes/FilesRoutes.scala @@ -2,7 +2,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.storage.files.routes import akka.http.scaladsl.model.MediaRange import akka.http.scaladsl.model.StatusCodes.Created -import akka.http.scaladsl.model.headers.{Accept, `Content-Length`} +import akka.http.scaladsl.model.headers.{`Content-Length`, Accept} import akka.http.scaladsl.server.Directives.{extractRequestEntity, optionalHeaderValueByName, provide, reject} import akka.http.scaladsl.server._ import cats.effect.IO @@ -13,7 +13,7 @@ import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model._ import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.permissions.{read => Read, write => Write} import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.routes.FileUriDirectives._ import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.routes.FilesRoutes._ -import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.{FileResource, Files, schemas} +import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.{schemas, FileResource, Files} import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragePluginExceptionHandler.handleStorageExceptions import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.ShowFileLocation import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageDeletionTask.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageDeletionTask.scala index 417775cfc6..63248013a9 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageDeletionTask.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageDeletionTask.scala @@ -25,9 +25,9 @@ final class StorageDeletionTask(currentStorages: ProjectRef => Stream[IO, Storag private def run(project: ProjectRef) = currentStorages(project) .evalScan(init) { - case (acc, disk: DiskStorageValue) => + case (acc, disk: DiskStorageValue) => deleteRecursively(project, disk).map(acc ++ _) - case (acc, s3: S3StorageValue) => + case (acc, s3: S3StorageValue) => val message = s"Deletion of files for S3 storages is yet to be implemented. Files in bucket '${s3.bucket}' will remain." logger.warn(message).as(acc ++ message) diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesConfig.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesConfig.scala index cd0a2a9d65..a9846db5ad 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesConfig.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesConfig.scala @@ -57,8 +57,8 @@ object StoragesConfig { amazon: Option[S3StorageConfig] ) { def showFileLocation: ShowFileLocation = { - val diskType = if (disk.showLocation) Set(StorageType.DiskStorage) else Set() - val s3Type = if (amazon.exists(_.showLocation)) Set(StorageType.S3Storage) else Set() + val diskType = if (disk.showLocation) Set(StorageType.DiskStorage) else Set() + val s3Type = if (amazon.exists(_.showLocation)) Set(StorageType.S3Storage) else Set() ShowFileLocation(diskType ++ s3Type) } } @@ -73,10 +73,10 @@ object StoragesConfig { implicit val storageTypeConfigReader: ConfigReader[StorageTypeConfig] = ConfigReader.fromCursor { cursor => for { - obj <- cursor.asObjectCursor - diskCursor <- obj.atKey("disk") - disk <- ConfigReader[DiskStorageConfig].from(diskCursor) - _ <- + obj <- cursor.asObjectCursor + diskCursor <- obj.atKey("disk") + disk <- ConfigReader[DiskStorageConfig].from(diskCursor) + _ <- Option .when(disk.allowedVolumes.contains(disk.defaultVolume))(()) .toRight( diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/StorageAccess.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/StorageAccess.scala index 3a60f694db..73d27ad420 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/StorageAccess.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/StorageAccess.scala @@ -19,8 +19,8 @@ trait StorageAccess { object StorageAccess { def apply(s3Access: S3StorageAccess): StorageAccess = { - case d: DiskStorageValue => DiskStorageAccess.checkVolumeExists(d.volume) - case s: S3StorageValue => s3Access.checkBucketExists(s.bucket) + case d: DiskStorageValue => DiskStorageAccess.checkVolumeExists(d.volume) + case s: S3StorageValue => s3Access.checkBucketExists(s.bucket) } } diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/Storage.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/Storage.scala index 12368bf39c..4e3cc4c2d7 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/Storage.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/Storage.scala @@ -2,7 +2,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.Storage.Metadata import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.{DiskStorageValue, S3StorageValue} -import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{Storages, contexts} +import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{contexts, Storages} import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageState.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageState.scala index 0311aebcd0..e05ef0f2d5 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageState.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageState.scala @@ -2,7 +2,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.Storage.{DiskStorage, S3Storage} import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.{DiskStorageValue, S3StorageValue} -import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{StorageResource, schemas} +import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{schemas, StorageResource} import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri import ch.epfl.bluebrain.nexus.delta.sdk.model.{ResourceF, ResourceUris} import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer @@ -59,8 +59,8 @@ final case class StorageState( def storage: Storage = value match { - case value: DiskStorageValue => DiskStorage(id, project, value, source) - case value: S3StorageValue => S3Storage(id, project, value, source) + case value: DiskStorageValue => DiskStorage(id, project, value, source) + case value: S3StorageValue => S3Storage(id, project, value, source) } def toResource: StorageResource = diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/FileOperations.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/FileOperations.scala index 41a0fb89ee..4d59ad5fbc 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/FileOperations.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/FileOperations.scala @@ -38,13 +38,13 @@ object FileOperations { contentLength: Option[Long] ): IO[FileStorageMetadata] = IO.fromEither(UploadingFile(storage, info, contentLength)).flatMap { - case d: DiskUploadingFile => diskFileOps.save(d) - case s: S3UploadingFile => s3FileOps.save(s) + case d: DiskUploadingFile => diskFileOps.save(d) + case s: S3UploadingFile => s3FileOps.save(s) } override def fetch(storage: Storage, attributes: FileAttributes): IO[AkkaSource] = storage match { - case _: DiskStorage => diskFileOps.fetch(attributes.location.path) - case s: S3Storage => s3FileOps.fetch(s.value.bucket, attributes.path) + case _: DiskStorage => diskFileOps.fetch(attributes.location.path) + case s: S3Storage => s3FileOps.fetch(s.value.bucket, attributes.path) } override def delegate(storage: Storage, filename: String): IO[FileDelegationRequest.TargetLocation] = diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/UploadingFile.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/UploadingFile.scala index 2ca4af387c..f8c96a176c 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/UploadingFile.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/UploadingFile.scala @@ -57,9 +57,9 @@ object UploadingFile { contentLengthOpt: Option[Long] ): Either[SaveFileRejection, UploadingFile] = storage match { - case s: DiskStorage => + case s: DiskStorage => Right(DiskUploadingFile(s.project, s.value.volume, s.value.algorithm, info.filename, info.contents)) - case s: S3Storage => + case s: S3Storage => contentLengthOpt.toRight(FileContentLengthIsMissing).map { contentLength => S3UploadingFile( s.project, diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesSpec.scala index f6f87204fb..829d07fcf5 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesSpec.scala @@ -77,7 +77,7 @@ class FilesSpec FileDescription(filename, None, Some(FileCustomMetadata(Some(name), Some(description), Some(keywords)))) "The Files operations bundle" when { - implicit val caller: Caller = Caller(bob, Set(bob, Group("mygroup", realm), Authenticated(realm))) + implicit val caller: Caller = Caller(bob, Set(bob, Group("mygroup", realm), Authenticated(realm))) val tag = UserTag.unsafe("tag") val otherRead = Permission.unsafe("other/read") @@ -90,13 +90,13 @@ class FilesSpec otherWrite ) - val defaultStorageIri = nxv + "default" - val defaultStorageId = IriSegment(defaultStorageIri) - val defaultStorageRef = ResourceRef.Revision(defaultStorageIri, 1) + val defaultStorageIri = nxv + "default" + val defaultStorageId = IriSegment(defaultStorageIri) + val defaultStorageRef = ResourceRef.Revision(defaultStorageIri, 1) val defaultStorageFolder = FileGen.mkTempDir("default") - val customStorageIri = nxv + "custom" - val customStorageId = IriSegment(customStorageIri) + val customStorageIri = nxv + "custom" + val customStorageId = IriSegment(customStorageIri) val customStorageFolder = FileGen.mkTempDir("default") val storageIri = nxv + "other-storage" @@ -118,7 +118,8 @@ class FilesSpec val cfg = config.copy( disk = config.disk.copy( defaultMaxFileSize = maxFileSize, - allowedVolumes = config.disk.allowedVolumes ++ Set(defaultStorageFolder, customStorageFolder)) + allowedVolumes = config.disk.allowedVolumes ++ Set(defaultStorageFolder, customStorageFolder) + ) ) lazy val storages: Storages = Storages( @@ -159,7 +160,8 @@ class FilesSpec "creating a file" should { "create storages for files" in { - val defaultStoragePayload = diskFieldsJson deepMerge json"""{"maxFileSize": 300, "volume": "$defaultStorageFolder"}""" + val defaultStoragePayload = + diskFieldsJson deepMerge json"""{"maxFileSize": 300, "volume": "$defaultStorageFolder"}""" storages.create(defaultStorageId, projectRef, defaultStoragePayload).accepted val customStoragePayload = diskFieldsJson deepMerge @@ -210,7 +212,8 @@ class FilesSpec } "succeed with randomly generated id" in { - val expected = mkResource(generatedId, projectRef, defaultStorageRef, attributes(defaultStorageFolder, "myfile2.txt")) + val expected = + mkResource(generatedId, projectRef, defaultStorageRef, attributes(defaultStorageFolder, "myfile2.txt")) val request = FileUploadRequest.from(entity("myfile2.txt")) val actual = files.create(None, projectRef, request, None).accepted val fetched = files.fetch(FileId(actual.id, projectRef)).accepted @@ -256,7 +259,9 @@ class FilesSpec "reject if the file exceeds max file size for the storage" in { val id = fileId("file-too-large") val request = FileUploadRequest.from(randomEntity("large_file", (maxFileSize + 1).toInt)) - files.create(id, Some(customStorageId), request, None)(aliceCaller).rejected shouldEqual FileTooLarge(maxFileSize) + files.create(id, Some(customStorageId), request, None)(aliceCaller).rejected shouldEqual FileTooLarge( + maxFileSize + ) } "reject if storage does not exist" in { @@ -282,7 +287,15 @@ class FilesSpec "succeed" in { val request = FileUploadRequest.from(entity()) files.update(fileId("file1"), None, 1, request, None).accepted shouldEqual - FileGen.resourceFor(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 2, createdBy = bob, updatedBy = bob) + FileGen.resourceFor( + file1, + projectRef, + defaultStorageRef, + attributes(defaultStorageFolder), + rev = 2, + createdBy = bob, + updatedBy = bob + ) } "succeed with custom metadata" in { @@ -392,7 +405,14 @@ class FilesSpec "tagging a file" should { "succeed" in { - val expected = mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 3, tags = Tags(tag -> 1)) + val expected = mkResource( + file1, + projectRef, + defaultStorageRef, + attributes(defaultStorageFolder), + rev = 3, + tags = Tags(tag -> 1) + ) val actual = files.tag(fileIdIri(file1), tag, tagRev = 1, 2).accepted actual shouldEqual expected } @@ -432,7 +452,8 @@ class FilesSpec "deprecating a file" should { "succeed" in { - val expected = mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 5, deprecated = true) + val expected = + mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 5, deprecated = true) val actual = files.deprecate(fileIdIri(file1), 4).accepted actual shouldEqual expected } @@ -458,7 +479,15 @@ class FilesSpec "allow tagging after deprecation" in { val expected = - mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 6, tags = Tags(tag -> 4), deprecated = true) + mkResource( + file1, + projectRef, + defaultStorageRef, + attributes(defaultStorageFolder), + rev = 6, + tags = Tags(tag -> 4), + deprecated = true + ) val actual = files.tag(fileIdIri(file1), tag, tagRev = 4, 5).accepted actual shouldEqual expected } @@ -504,10 +533,19 @@ class FilesSpec } "fetching a file" should { - val resourceRev1 = mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder, "myfile.txt")) + val resourceRev1 = + mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder, "myfile.txt")) val resourceRev4 = mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 4) val resourceRev6 = - mkResource(file1, projectRef, defaultStorageRef, attributes(defaultStorageFolder), rev = 6, tags = Tags(tag -> 4), deprecated = true) + mkResource( + file1, + projectRef, + defaultStorageRef, + attributes(defaultStorageFolder), + rev = 6, + tags = Tags(tag -> 4), + deprecated = true + ) "succeed" in { files.fetch(fileIdIri(file1)).accepted shouldEqual resourceRev6 diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesStmSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesStmSpec.scala index 1b1646980f..bcecbfef16 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesStmSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/FilesStmSpec.scala @@ -29,13 +29,13 @@ class FilesStmSpec extends CatsEffectSpec with FileFixtures with StorageFixtures private val bob = User("Bob", realm) private val alice = User("Alice", realm) - private val id = nxv + "files" - private val myTag = UserTag.unsafe("myTag") - private val storageRef = ResourceRef.Revision(nxv + "disk", 1) + private val id = nxv + "files" + private val myTag = UserTag.unsafe("myTag") + private val storageRef = ResourceRef.Revision(nxv + "disk", 1) private val s3StorageRef = ResourceRef.Revision(nxv + "s3", 1) - private val mediaType = Some(ContentTypes.`text/plain(UTF-8)`) - private val dig = ComputedDigest(DigestAlgorithm.default, "something") - private val attributes = FileAttributes( + private val mediaType = Some(ContentTypes.`text/plain(UTF-8)`) + private val dig = ComputedDigest(DigestAlgorithm.default, "something") + private val attributes = FileAttributes( uuid, location = "http://localhost/my/file.txt", path = Uri.Path("my/file.txt"), diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageFixtures.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageFixtures.scala index cead7930d5..b910864cfc 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageFixtures.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StorageFixtures.scala @@ -45,9 +45,9 @@ trait StorageFixtures extends CirceLiteral { s3Fields.writePermission.get ) - val diskJson = jsonContentOf("storages/disk-storage.json") - val s3Json = jsonContentOf("storages/s3-storage.json") + val diskJson = jsonContentOf("storages/disk-storage.json") + val s3Json = jsonContentOf("storages/s3-storage.json") - val diskFieldsJson = diskJson.removeKeys("@id", "@context", "_algorithm") - val s3FieldsJson = s3Json.removeKeys("@id", "@context", "_algorithm") + val diskFieldsJson = diskJson.removeKeys("@id", "@context", "_algorithm") + val s3FieldsJson = s3Json.removeKeys("@id", "@context", "_algorithm") } diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesStmSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesStmSpec.scala index d959a15d8f..b83e8b9b1c 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesStmSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/StoragesStmSpec.scala @@ -34,9 +34,9 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { private val accessibleDisk = Set(diskFields.volume.value, tmp2) private val access: StorageAccess = { - case disk: DiskStorageValue => + case disk: DiskStorageValue => IO.whenA(!accessibleDisk.contains(disk.volume))(IO.raiseError(StorageNotAccessible("wrong volume"))) - case s3: S3StorageValue => + case s3: S3StorageValue => IO.whenA(!s3Fields.bucket.contains(s3.bucket))(IO.raiseError(StorageNotAccessible("wrong bucket"))) } @@ -49,8 +49,8 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { "evaluating an incoming command" should { "create a new event from a CreateStorage command" in { - val disk = CreateStorage(dId, project, diskFields.copy(maxFileSize = Some(1)), diskFieldsJson, bob) - val s3 = CreateStorage(s3Id, project, s3Fields.copy(maxFileSize = Some(2)), s3FieldsJson, bob) + val disk = CreateStorage(dId, project, diskFields.copy(maxFileSize = Some(1)), diskFieldsJson, bob) + val s3 = CreateStorage(s3Id, project, s3Fields.copy(maxFileSize = Some(2)), s3FieldsJson, bob) forAll(List(disk, s3)) { cmd => eval(None, cmd).accepted shouldEqual @@ -59,11 +59,11 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { } "create a new event from a UpdateStorage command" in { - val disk = UpdateStorage(dId, project, diskFields, diskFieldsJson, 1, alice) - val diskCurrent = storageState(dId, project, diskVal.copy(maxFileSize = 1)) - val s3 = UpdateStorage(s3Id, project, s3Fields, s3FieldsJson, 1, alice) - val s3Current = storageState(s3Id, project, s3Val.copy(maxFileSize = 2)) - val list = List((diskCurrent, disk), (s3Current, s3)) + val disk = UpdateStorage(dId, project, diskFields, diskFieldsJson, 1, alice) + val diskCurrent = storageState(dId, project, diskVal.copy(maxFileSize = 1)) + val s3 = UpdateStorage(s3Id, project, s3Fields, s3FieldsJson, 1, alice) + val s3Current = storageState(s3Id, project, s3Val.copy(maxFileSize = 2)) + val list = List((diskCurrent, disk), (s3Current, s3)) forAll(list) { case (state, cmd) => eval(Some(state), cmd).accepted shouldEqual @@ -96,12 +96,12 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { } "reject with StorageNotAccessible" in { - val notAllowedDiskVal = diskFields.copy(volume = Some(tmp2)) - val inaccessibleDiskVal = + val notAllowedDiskVal = diskFields.copy(volume = Some(tmp2)) + val inaccessibleDiskVal = diskFields.copy(volume = Some(AbsolutePath(Files.createTempDirectory("other")).rightValue)) - val inaccessibleS3Val = s3Fields.copy(bucket = Some("other")) - val diskCurrent = storageState(dId, project, diskVal) - val s3Current = storageState(s3Id, project, s3Val) + val inaccessibleS3Val = s3Fields.copy(bucket = Some("other")) + val diskCurrent = storageState(dId, project, diskVal) + val s3Current = storageState(s3Id, project, s3Val) forAll( List( @@ -116,8 +116,8 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { forAll( List( - diskCurrent -> inaccessibleDiskVal, - s3Current -> inaccessibleS3Val + diskCurrent -> inaccessibleDiskVal, + s3Current -> inaccessibleS3Val ) ) { case (state, value) => val updateCmd = UpdateStorage(state.id, project, value, Json.obj(), 1, alice) @@ -126,10 +126,10 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { } "reject with InvalidMaxFileSize" in { - val exceededSizeDiskVal = diskFields.copy(maxFileSize = Some(100)) - val exceededSizeS3Val = s3Fields.copy(maxFileSize = Some(100)) - val diskCurrent = storageState(dId, project, diskVal) - val s3Current = storageState(s3Id, project, s3Val) + val exceededSizeDiskVal = diskFields.copy(maxFileSize = Some(100)) + val exceededSizeS3Val = s3Fields.copy(maxFileSize = Some(100)) + val diskCurrent = storageState(dId, project, diskVal) + val s3Current = storageState(s3Id, project, s3Val) forAll( List( @@ -190,11 +190,11 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { } "reject with DifferentStorageType" in { - val diskCurrent = storageState(dId, project, diskVal) - val s3Current = storageState(s3Id, project, s3Val) - val list = List( - diskCurrent -> UpdateStorage(dId, project, s3Fields, Json.obj(), 1, alice), - s3Current -> UpdateStorage(s3Id, project, diskFields, Json.obj(), 1, alice), + val diskCurrent = storageState(dId, project, diskVal) + val s3Current = storageState(s3Id, project, s3Val) + val list = List( + diskCurrent -> UpdateStorage(dId, project, s3Fields, Json.obj(), 1, alice), + s3Current -> UpdateStorage(s3Id, project, diskFields, Json.obj(), 1, alice) ) forAll(list) { case (state, cmd) => eval(Some(state), cmd).rejectedWith[DifferentStorageType] @@ -219,8 +219,8 @@ class StoragesStmSpec extends CatsEffectSpec with StorageFixtures { "reject with InvalidStorageType" in { val s3Current = storageState(s3Id, project, s3Val) val list = List( - None -> CreateStorage(s3Id, project, s3Fields, Json.obj(), bob), - Some(s3Current) -> UpdateStorage(s3Id, project, s3Fields, Json.obj(), 1, alice), + None -> CreateStorage(s3Id, project, s3Fields, Json.obj(), bob), + Some(s3Current) -> UpdateStorage(s3Id, project, s3Fields, Json.obj(), 1, alice) ) val diskVolume = AbsolutePath(Files.createTempDirectory("disk")).rightValue // format: off diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageFieldsSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageFieldsSpec.scala index bf349a8de1..5ec40a7b24 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageFieldsSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageFieldsSpec.scala @@ -3,7 +3,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF import ch.epfl.bluebrain.nexus.delta.plugins.storage.RemoteContextResolutionFixture import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageFields._ -import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{StorageDecoderConfiguration, StorageFixtures, contexts} +import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.{contexts, StorageDecoderConfiguration, StorageFixtures} import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.decoder.Configuration import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdSourceProcessor.JsonLdSourceDecoder diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSerializationSuite.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSerializationSuite.scala index bd136625fd..c9d0f95f3b 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSerializationSuite.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSerializationSuite.scala @@ -22,7 +22,7 @@ class StorageSerializationSuite extends SerializationSuite with StorageFixtures private val tag = UserTag.unsafe("mytag") private val projectRef = ProjectRef.unsafe("myorg", "myproj") - private val s3ValUpdate = s3Val.copy(bucket = "mybucket2", maxFileSize = 41) + private val s3ValUpdate = s3Val.copy(bucket = "mybucket2", maxFileSize = 41) private val diskCreated = StorageCreated(dId, projectRef, diskVal, diskFieldsJson, 1, instant, subject) private val s3Created = StorageCreated(s3Id, projectRef, s3Val, s3FieldsJson, 1, instant, subject) @@ -79,8 +79,8 @@ class StorageSerializationSuite extends SerializationSuite with StorageFixtures } private val statesMapping = VectorMap( - (dId, diskVal, diskFieldsJson) -> jsonContentOf("storages/storage-disk-state.json"), - (s3Id, s3Val, s3FieldsJson) -> jsonContentOf("storages/storage-s3-state.json") + (dId, diskVal, diskFieldsJson) -> jsonContentOf("storages/storage-disk-state.json"), + (s3Id, s3Val, s3FieldsJson) -> jsonContentOf("storages/storage-s3-state.json") ).map { case ((id, value, source), v) => StorageState( id, diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSpec.scala index e9477fe164..1549c9bad1 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/model/StorageSpec.scala @@ -11,16 +11,16 @@ import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec class StorageSpec extends CatsEffectSpec with RemoteContextResolutionFixture with StorageFixtures { "A Storage" should { - val project = ProjectRef(Label.unsafe("org"), Label.unsafe("project")) - val diskStorage = + val project = ProjectRef(Label.unsafe("org"), Label.unsafe("project")) + val diskStorage = DiskStorage(nxv + "disk", project, diskVal, json"""{"disk": "value"}""") - val s3Storage = S3Storage(nxv + "s3", project, s3Val, json"""{"s3": "value"}""") + val s3Storage = S3Storage(nxv + "s3", project, s3Val, json"""{"s3": "value"}""") "be compacted" in { forAll( List( - diskStorage -> diskJson.deepMerge(json"""{"@type": ["Storage", "DiskStorage"]}"""), - s3Storage -> s3Json + diskStorage -> diskJson.deepMerge(json"""{"@type": ["Storage", "DiskStorage"]}"""), + s3Storage -> s3Json .deepMerge(json"""{"@type": ["Storage", "S3Storage"]}""") .removeKeys("accessKey", "secretKey") ) @@ -30,11 +30,11 @@ class StorageSpec extends CatsEffectSpec with RemoteContextResolutionFixture wit } "be expanded" in { - val diskJson = jsonContentOf("storages/disk-storage-expanded.json") - val s3Json = jsonContentOf("storages/s3-storage-expanded.json") + val diskJson = jsonContentOf("storages/disk-storage-expanded.json") + val s3Json = jsonContentOf("storages/s3-storage-expanded.json") - forAll(List(diskStorage -> diskJson, s3Storage -> s3Json)) { - case (value, expanded) => value.toExpandedJsonLd.accepted.json shouldEqual expanded + forAll(List(diskStorage -> diskJson, s3Storage -> s3Json)) { case (value, expanded) => + value.toExpandedJsonLd.accepted.json shouldEqual expanded } } } diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/disk/DiskStorageSaveFileSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/disk/DiskStorageSaveFileSpec.scala index 367acef65c..a2807918e4 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/disk/DiskStorageSaveFileSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/disk/DiskStorageSaveFileSpec.scala @@ -32,7 +32,7 @@ class DiskStorageSaveFileSpec "A DiskStorage saving operations" should { val project = ProjectRef.unsafe("org", "project") val content = "file content" - val digest = "e0ac3601005dfa1864f5392aabaf7d898b1b5bab854f1acb4491bcd806b76b0c" + val digest = "e0ac3601005dfa1864f5392aabaf7d898b1b5bab854f1acb4491bcd806b76b0c" val entity = HttpEntity(content) val uploading = DiskUploadingFile(project, volume, DigestAlgorithm.default, "myfile.txt", entity) diff --git a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/routes/StoragesRoutesSpec.scala b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/routes/StoragesRoutesSpec.scala index effe943d6c..4e1d2776ad 100644 --- a/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/routes/StoragesRoutesSpec.scala +++ b/delta/plugins/storage/src/test/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/routes/StoragesRoutesSpec.scala @@ -67,12 +67,12 @@ class StoragesRoutesSpec extends BaseRouteSpec with StorageFixtures with UUIDFFi ProjectGen.project("myorg", "myproject", uuid = randomUuid, orgUuid = randomUuid, base = projBase, mappings = am) private val projectRef = project.ref - private val s3IdEncoded = UrlUtils.encode(s3Id.toString) + private val s3IdEncoded = UrlUtils.encode(s3Id.toString) - private val diskRead = Permission.unsafe("disk/read") - private val diskWrite = Permission.unsafe("disk/write") - private val s3Read = Permission.unsafe("s3/read") - private val s3Write = Permission.unsafe("s3/write") + private val diskRead = Permission.unsafe("disk/read") + private val diskWrite = Permission.unsafe("disk/write") + private val s3Read = Permission.unsafe("s3/read") + private val s3Write = Permission.unsafe("s3/write") override val allowedPerms = Seq( permissions.read,