-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
185 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 10 additions & 26 deletions
36
...h/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/s3/S3StorageAccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3 | ||
|
||
import akka.actor.ActorSystem | ||
import akka.stream.alpakka.s3.S3Attributes | ||
import akka.stream.alpakka.s3.scaladsl.S3 | ||
import akka.stream.scaladsl.Sink | ||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.StorageTypeConfig | ||
import ch.epfl.bluebrain.nexus.delta.kernel.Logger | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.StorageNotAccessible | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.S3StorageValue | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageAccess | ||
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.client.S3StorageClient | ||
|
||
final class S3StorageAccess(config: StorageTypeConfig)(implicit as: ActorSystem) extends StorageAccess { | ||
override type Storage = S3StorageValue | ||
final class S3StorageAccess(s3Client: S3StorageClient) { | ||
|
||
override def apply(id: Iri, storage: S3StorageValue): IO[Unit] = { | ||
val attributes = S3Attributes.settings(storage.alpakkaSettings(config)) | ||
private val log = Logger[S3StorageAccess] | ||
|
||
IO.fromFuture( | ||
IO.delay( | ||
S3.listBucket(storage.bucket, None) | ||
.withAttributes(attributes) | ||
.runWith(Sink.head) | ||
def apply(bucket: String): IO[Unit] = | ||
s3Client | ||
.listObjectsV2(bucket) | ||
.redeemWith( | ||
err => IO.raiseError(StorageNotAccessible(err.getMessage)), | ||
response => log.info(s"S3 bucket $bucket contains ${response.keyCount()} objects") | ||
) | ||
).redeemWith( | ||
{ | ||
case _: NoSuchElementException => IO.unit // // bucket is empty | ||
case err => | ||
IO.raiseError(StorageNotAccessible(id, err.getMessage)) | ||
}, | ||
_ => IO.unit | ||
) | ||
} | ||
} |
Oops, something went wrong.