-
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.
Separate access check from other operations (#5190)
* Separate access check from other operations --------- Co-authored-by: Simon Dumas <simon.dumas@epfl.ch>
- Loading branch information
Showing
27 changed files
with
212 additions
and
202 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
26 changes: 26 additions & 0 deletions
26
...ala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/DiskStorageAccess.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.access | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.AbsolutePath | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.StorageNotAccessible | ||
|
||
import java.nio.file.Files | ||
|
||
object DiskStorageAccess { | ||
|
||
def checkVolumeExists(path: AbsolutePath): IO[Unit] = { | ||
def failWhen(condition: Boolean, err: => String) = { | ||
IO.raiseWhen(condition)(StorageNotAccessible(err)) | ||
} | ||
|
||
for { | ||
exists <- IO.blocking(Files.exists(path.value)) | ||
_ <- failWhen(!exists, s"Volume '${path.value}' does not exist.") | ||
isDirectory <- IO.blocking(Files.isDirectory(path.value)) | ||
_ <- failWhen(!isDirectory, s"Volume '${path.value}' is not a directory.") | ||
isWritable <- IO.blocking(Files.isWritable(path.value)) | ||
_ <- failWhen(!isWritable, s"Volume '${path.value}' does not have write access.") | ||
} yield () | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...a/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/RemoteStorageAccess.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.access | ||
|
||
import cats.syntax.all._ | ||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.StorageNotAccessible | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.remote.client.RemoteDiskStorageClient | ||
import ch.epfl.bluebrain.nexus.delta.sdk.http.HttpClientError | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label | ||
|
||
trait RemoteStorageAccess { | ||
|
||
def checkFolderExists(folder: Label): IO[Unit] | ||
|
||
} | ||
|
||
object RemoteStorageAccess { | ||
|
||
def apply(client: RemoteDiskStorageClient): RemoteStorageAccess = | ||
(folder: Label) => | ||
client | ||
.exists(folder) | ||
.adaptError { case err: HttpClientError => | ||
StorageNotAccessible( | ||
err.details.fold(s"Folder '$folder' does not exist")(d => s"${err.reason}: $d") | ||
) | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.access | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageRejection.StorageNotAccessible | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.client.S3StorageClient | ||
|
||
trait S3StorageAccess { | ||
|
||
def checkBucketExists(bucket: String): IO[Unit] | ||
|
||
} | ||
|
||
object S3StorageAccess { | ||
|
||
def apply(client: S3StorageClient): S3StorageAccess = | ||
(bucket: String) => | ||
client.bucketExists(bucket).flatMap { exists => | ||
IO.raiseUnless(exists)(StorageNotAccessible(s"Bucket $bucket does not exist")) | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...n/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/access/StorageAccess.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.access | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.{DiskStorageValue, RemoteDiskStorageValue, S3StorageValue} | ||
|
||
trait StorageAccess { | ||
|
||
/** | ||
* Checks whether the system has access to the passed ''storage'' | ||
* | ||
* @return | ||
* a [[Unit]] if access has been verified successfully or signals an error [[StorageNotAccessible]] with the | ||
* details about why the storage is not accessible | ||
*/ | ||
def validateStorageAccess(storage: StorageValue): IO[Unit] | ||
} | ||
|
||
object StorageAccess { | ||
|
||
def apply(remoteAccess: RemoteStorageAccess, s3Access: S3StorageAccess): StorageAccess = { | ||
case d: DiskStorageValue => DiskStorageAccess.checkVolumeExists(d.volume) | ||
case s: RemoteDiskStorageValue => remoteAccess.checkFolderExists(s.folder) | ||
case s: S3StorageValue => s3Access.checkBucketExists(s.bucket) | ||
} | ||
|
||
} |
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
16 changes: 0 additions & 16 deletions
16
...ala/ch/epfl/bluebrain/nexus/delta/plugins/storage/storages/operations/StorageAccess.scala
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.