Commit Graph
33 Commits
Author SHA1 Message Date
José Manuel Domínguez 6fe92643af Merge branch 'dev' into file_sources_assign_paths 2024-11-28 13:11:29 +01:00
José Manuel Domínguez 53012bf059 Let file sources choose a path for uploaded files
The method `write_from()` of `SingleFileSource` and `BaseFilesSource` reads a local file from `native_path` and saves it to `target_path` on a file source.

This commit allows the service backing the file source to choose which will be the path of the saved file, meaning that `target_path` and the actual path where the file can be recovered later do not have to match. The latter is the return value of `write_from()`.

Therefore, all usages of `write_from()` have also been refactored to consider the paths chosen by the file source's backing service. In addition, when exporting a history, the URI that the service backing the file source assigns to it will be saved to the history export result metadata object.
2024-11-18 17:02:29 +01:00
John Chilton eea3909cb0 Fixes and expansion of webdav unit tests. 2024-10-05 17:23:26 -04:00
David LópezandJohn Davis 03d9d12f22 Apply suggestions from code review
Replace unused tuple value with `_`

Co-authored-by: John Davis <jdavcs@gmail.com>
2024-05-21 10:45:17 +02:00
davelopez dd60362aa6 Add total_matches header to file sources listing
This is necessary to handle pagination properly in the UI.
2024-05-21 10:45:09 +02:00
John Chilton f95da89b3d Implement file source templates 2024-05-20 12:18:47 -04:00
John Chilton 076fff8302 Update s3fs dependency. 2024-05-14 08:50:44 -04:00
John Chilton e03d162429 Update Azure infrastructure. 2024-05-03 13:57:58 -04:00
davelopez 4a6958e059 Refactoring + stronger type annotations in file sources 2024-04-26 10:21:26 +02:00
John Chilton ac197e7f25 Refactor galaxy.files plugin + config handling.
- Downstream I want a way to load plugins from outside the ConfiguredFileSources class.
- Adds some more typing as I went in there and refactored things.
2024-04-25 13:05:02 -04:00
Nicola Soranzo 330599c70f Fixes for new errors from ruff 0.3.2 2024-03-12 11:06:57 +00:00
Nicola Soranzo e975ca3754 Update to black 2024 stable style 2024-01-30 18:09:51 +00:00
nuwang 0c0ed2a4e3 Fix test failures 2023-02-09 18:14:18 +05:30
nuwang c8803f49b2 Add chained resolution of drs access urls 2023-02-09 18:13:32 +05:30
nuwang 129425abb5 Add support for injecting user headers to http file source 2023-02-09 18:13:31 +05:30
Dannon Baker 623a5e165a Apply black formatting.
Apply isort.
2022-02-03 07:42:20 -05:00
Nuwan Goonasekera 0924628d10 Refactor file source tests 2021-12-21 00:56:17 +05:30
Nuwan Goonasekera 15b7b88d8b Streamline access tokens needed to run gcsfs and gdrive storage tests 2021-12-20 11:08:42 +05:30
Nuwan Goonasekera cb22970426 Added support for illumina basespace filesource 2021-12-20 11:08:42 +05:30
Nuwan Goonasekera d1185fcd18 Added one data 2021-12-20 11:08:42 +05:30
Nuwan Goonasekera b8bdb6878e Added file source for google cloud storage 2021-12-20 11:08:42 +05:30
Nuwan Goonasekera 71862f540c Use separate env vars for each required param in google drive credentials 2021-12-20 11:08:42 +05:30
Nuwan Goonasekera ae8a832b7b Added unit tests for google drive file source 2021-12-20 11:08:42 +05:30
Nicola Soranzo 90a729e431 New pyupgrade fixes
Found by running `ack --type=python -f | grep -v '^tools/' | xargs pyupgrade --py36-plus`
2021-10-24 12:10:34 +01:00
John Chilton c791fea0cf Formalize dependency of galaxy-data on galaxy.files package.
- Create a new project galaxy-files that does not depend on anything but galaxy-util.
- Add a dependency in galaxy-data on galaxy-files, use typing in galaxy.data.sniff to make this clear.
- Cleanup the galaxy-files unit tests to not depend on galaxy.datatypes.sniff code - this wasn't ideal to start with.
- Add a small integration-ish unit test test_sniff_file_sources.py to test that piece of sniff.py that depends on galaxy-files.
2021-10-11 13:16:30 -04:00
John Chilton fe0c4ab4e2 Migrate more unit tests into galaxy-app's test suite. 2021-10-07 11:05:03 -04:00
davelopez 6ef54d73c6 Add file sources access unit tests 2021-04-06 11:17:55 +02:00
John Chilton 9831e66fca More flushing to file source posix tests pass consistently. 2021-02-24 12:36:18 -05:00
John Chilton f5929f8e06 Allow anonymous access to S3 buckets via file sources plugins.
```yaml
- type: s3fs
  id: genomeark
  doc: Access to Genome Ark open data on AWS..
  bucket: genomeark
  anon: true
```

0;95;0c# Please enter the commit message for your changes. Lines starting
2021-02-23 19:20:52 -05:00
mvdbeek ccdb6c3f10 Replace usage of mkstemp with NamedTemporaryFile 2020-12-07 22:31:53 +01:00
Nicola Soranzo 9d74bba7fb Drop support for retired Python 3.5
Upgrade syntax using `pyupgrade --py36-plus` .

Manually drop several `six` imports.

Also:
- Remove broken pr_cache in scripts/bootstrap_history.py
- Fix broken prefix removal in lib/galaxy/tool_util/deps/mulled/mulled_build.py
2020-10-07 11:52:13 +01:00
John Chilton 9fb3a490dc Add infrastructure for writing to pluggable galaxy file sources. 2020-09-10 09:37:50 -04:00
John Chilton f93cc11e66 Pluggable URI handling across upload components.
*Overview*

This work defines an interface for interacting with "filesystem"-like entities during "upload". In addition to being a pluggable framework adding important new capabilities to Galaxy, this is a generalization and formalization of existing file sources (e.g. the directories described by `library_import_dir`, `user_library_dir`, and `ftp_upload_dir`).

*Plugin Infrastructure*

This introduces a new plugin `FilesSource` to represent sources of directories and files during "upload". A `FilesSource` plugin should be able to index directories and download (called 'realize' to be generic) files to local posix directories. Indexing is used by the remote_files API to provide the client with hierarchies to navigate and to build URIs for the files. The 'realize' operation is used by the 'upload1' and '__DATA_FETCH__' and tools during upload to bring the files into Galaxy as datasets.

An instance of the `ConfiguredFileSources` class is responsible for managing individual instances of `FilesSource` plugins. It has methods to map URIs to the appropriate plugin instance.

The `ConfiguredFileSources` class tracks the loaded plugins and reuses the go to `galaxy.util.plugin_config` module for loading YAML (or XML) definitions of plugins (the same dependency resolvers, job metrics, auth backends, etc. do). A `ConfiguredFileSources` object can serialize itself to a file and re-materialize it during job execution to allow using this abstraction during uploads.

When operating within the Galaxy app, the `ConfiguredFileSources` uses an adapter pattern to parse user-level information from Galaxy's `trans` object. During serialization, the `ConfiguredFileSources` object is expected to encode all the required information about the user that is needed into the output JSON description of the file sources. This is because the web transaction won't be available remotely during the upload job. These objects working in such different ways between the Galaxy process and in the remote job is mildly jarring - so unit tests have been written to ensure this all functions properly.

*Plugin Implementations*

The `FilesSource` interface has a helper implementation base class `BaseFilesSource` that provides some assistance for plugin development. Additionally, the base class `PyFilesystem2FilesSource` extends `BaseFilesSource` but assumes a PyFilesystem2 implementation exists to target the file source of interest - so the plugin author need only provide a PyFilesystem `FS` object describing the target. This commit includes three concrete implementations - posix, webdav, and dropbox. `posix` extends `BaseFilesSource` while the others are light-weight extensions of `PyFilesystem2FilesSource`.

**posix**

While one could imagine a very lightweight implementation based on `PyFilesystem2FilesSource` this fully worked through plugin is implemented directly to ensure we respect Galaxy's strong security checks on paths containing symlinks and preserve the semantics `user_library_import_symlink_allowlist`.

**webdav**

Galaxy tools for integrating OwnCloud exist - see https://github.com/shiltemann/Galaxy-Owncloud-Integration, part of the driver for this work was extending that idea to provide more integrated UX for uploading that data. So this work includes a WebDav plugin (and associated test cases) that could potentially target OwnCloud.

This plugin was a good exercise in flushing and testing the PyFilesystem2 interface but the PyFilesystem2 WebDAV implementation seems a bit fragile... we might want to replace it with more direct APIs but we can take a wait and see approach.

The config YAML for a webdav plugin that lets user's target their own OwnCloud servers configured via user preferences might look something like:

```
- type: webdav
  id: owncloud1
  label: OwnCloud
  doc: User-configured OwnCloud files
  url: ${user.preferences['owncloud|url']}
  login: ${user.preferences['owncloud|username']}
  password: ${user.preferences['webdav|password']}
```

The configuration would provide a user's OwnCloud files at `gxfiles://owncloud1/`.

If instead, a big centralized WebDav server is made available with public data for all users (mirroring use cases of `library_import_dir`) - a simpler configuration not requiring user preferences might be something like:

```
- type: webdav
  id: lab
  label: Lab WebDAV server
  doc: Our lab's research files managed at ourlab.org.
  url: http://ourlab.org:7083
  login: ${environ.get('WEBDAV_LOGIN')}
  password: ${environ.get('WEBDAV_PASSWORD')}
```

The configuration would provide a these WebDAV files at `gxfiles://lab/`.

These two examples demonstrate basic templating is allowed inside the YAML configuration. These are Cheetah templates exposing very specific views of the 'user', 'config', and the whole 'environ' available to the Galaxy server.

**dropbox**

The Dropbox PyFilesystem2 plugin is even easier to configure, all that is needed is a Dropbox access token (this can be configured from the settings menu and may be isolated to a specific app specific folder for added security on the user's part).

An example of such a plugin might be:

```
- type: dropbox
  id: dropbox1
  label: Dropbox Files
  doc: Your Dropbox files - configure an access token via the user preferences
  accessToken: ${user.preferences['dropbox|access_token']}
```

The configuration would provide a user's Dropbox files at `gxfiles://dropbox1/`.

**gxftp**

This is an automatically populated plugin (if `ftp_upload_dir` is configured in Galaxy) that provides the user's FTP files at `gxftp://`.

**gximport**

This is an automatically populated plugin (if `library_import_dir` is configured in Galaxy) that provides Galaxy's library import files at `gximport://`.

**gxuserimport**

This is an automatically populated plugin (if `user_library_import_dir` is configured in Galaxy) that provides the requesting user's Galaxy's user library import files at `gximportfiles://`.

*Why not a tool?*

One could imagine a tool - but the upload dialog has many advanced options for selecting how to ingest files (convert tabs and newlines, select format vs. detect, select dbkey, organize into collections, organize via rules, etc...). It would be next to impossible to provide all these same options via a normal tool and the user experience would be very different than using the upload components in Galaxy - which have been optimized and designed for this task.

That said - one future direction I would like to take this is to be able to mark plugins as writable and implement a new tool form input type "export_directory" or something like that. This could then be used to write data export tools. This could be used to write generalizations of the the cloud send tool.

*`ObjectStore` vs `FilesSource`*

ObjectStores provide datasets not files, the files are organized logically in a very flat way around a dataset. `FilesSource` s instead provide files and directories, not datasets. A `FilesSource` is meant to be browsed in hierarchical fashion - and also has no concept of extra files, etc..

*Future Work*

- This is hopefully going to serve as the basis of a first pass at Terra integration with Galaxy using the FISS lib. Having an implementation based on `PyFilesytem2` means we could potentially integrate support for S3, Basespace, Google Drive, OneDrive, etc..
- Tool form support for selecting files for import and directories for export.
- Allow writing collection archives, history export, etc.. to the `FilesSource` - this would really enhance the UI around getting big stuff out of Galaxy potentially I think.

Rebase into galaxy.files...
2020-07-14 10:09:50 -04:00