Skip to content

Commit

Permalink
Scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Nov 28, 2024
1 parent 8b0a412 commit babbfbc
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading

0 comments on commit babbfbc

Please sign in to comment.