Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exploring remote datasets with no credentials #6764

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed a bug where deleting a dataset would fail if its representation on disk was already missing. [#6720](https://github.com/scalableminds/webknossos/pull/6720)
- Fixed a bug where a user with multiple organizations could not log in anymore after one of their organization accounts got deactivated. [#6719](https://github.com/scalableminds/webknossos/pull/6719)
- Fixed rare crash in new Datasets tab in dashboard. [#6750](https://github.com/scalableminds/webknossos/pull/6750) and [#6753](https://github.com/scalableminds/webknossos/pull/6753)
- Fixed a bug where remote datasets without authentication could not be explored. [#6764](https://github.com/scalableminds/webknossos/pull/6764)

### Removed

Expand Down
18 changes: 10 additions & 8 deletions app/models/binary/credential/CredentialService.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package models.binary.credential

import com.scalableminds.util.tools.Fox
import com.scalableminds.webknossos.datastore.storage.{HttpBasicAuthCredential, S3AccessKeyCredential}
import com.scalableminds.webknossos.datastore.storage.{
FileSystemsHolder,
HttpBasicAuthCredential,
S3AccessKeyCredential
}
import utils.ObjectId

import java.net.URI
Expand All @@ -17,19 +21,18 @@ class CredentialService @Inject()(credentialDao: CredentialDAO) {
organization: String)(implicit ec: ExecutionContext): Fox[Option[ObjectId]] = {
val scheme = uri.getScheme
scheme match {
case "https" =>
case FileSystemsHolder.schemeHttps =>
username match {
case Some(u) =>
val _id = ObjectId.generate
for {
_ <- credentialDao.insertOne(
_id,
HttpBasicAuthCredential(uri.toString, u, password.getOrElse(""), user, organization))
_ <- credentialDao.findOne(_id)
} yield Some(_id)
case None => Fox.empty
case None => Fox.successful(None)
}
case "s3" =>
case FileSystemsHolder.schemeS3 =>
username match {
case Some(keyId) =>
password match {
Expand All @@ -39,11 +42,10 @@ class CredentialService @Inject()(credentialDao: CredentialDAO) {
_ <- credentialDao.insertOne(
_id,
S3AccessKeyCredential(uri.toString, keyId, secretKey, user, organization))
_ <- credentialDao.findOne(_id)
} yield Some(_id)
case None => Fox.empty
case None => Fox.successful(None)
}
case None => Fox.empty
case None => Fox.successful(None)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions app/models/binary/explore/ExploreRemoteLayerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ class ExploreRemoteLayerService @Inject()(credentialService: CredentialService)
requestingUser: User)(implicit ec: ExecutionContext): Fox[List[(DataLayer, Vec3Double)]] =
for {
remoteSource <- tryo(RemoteSourceDescriptor(new URI(normalizeUri(layerUri)), user, password)).toFox ?~> s"Received invalid URI: $layerUri"
credentialId <- credentialService.createCredential(new URI(normalizeUri(layerUri)),
user,
password,
requestingUser._id.toString,
requestingUser._organization.toString)
credentialId <- credentialService.createCredential(
new URI(normalizeUri(layerUri)),
user,
password,
requestingUser._id.toString,
requestingUser._organization.toString) ?~> "Failed to set up remote file system credentaial"
fileSystem <- FileSystemsHolder.getOrCreate(remoteSource).toFox ?~> "Failed to set up remote file system"
remotePath <- tryo(fileSystem.getPath(remoteSource.remotePath)) ?~> "Failed to get remote path"
layersWithVoxelSizes <- exploreRemoteLayersForRemotePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class FileSystemsProvidersCache(val maxEntries: Int) extends LRUConcurrentCache[

object FileSystemsHolder extends LazyLogging {

private val schemeS3 = "s3"
private val schemeHttps = "https"
private val schemeHttp = "http"
val schemeS3: String = "s3"
val schemeHttps: String = "https"
val schemeHttp: String = "http"

private val fileSystemsCache = new FileSystemsCache(maxEntries = 100)
private val fileSystemsProvidersCache = new FileSystemsProvidersCache(maxEntries = 100)
Expand Down