Skip to content

Commit

Permalink
Merge pull request #265 from umccr/feat/c4gh-misc
Browse files Browse the repository at this point in the history
refactor: C4GH and storage changes
  • Loading branch information
mmalenic committed Sep 19, 2024
2 parents 73d230c + bca364f commit c653daa
Show file tree
Hide file tree
Showing 47 changed files with 2,199 additions and 1,727 deletions.
1,236 changes: 699 additions & 537 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions htsget-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ repository = "https://github.com/umccr/htsget-rs"
[features]
s3-storage = ["htsget-config/s3-storage", "htsget-search/s3-storage", "htsget-http/s3-storage", "htsget-axum/s3-storage", "htsget-test/s3-storage"]
url-storage = ["htsget-config/url-storage", "htsget-search/url-storage", "htsget-http/url-storage", "htsget-axum/url-storage", "htsget-test/url-storage"]
c4gh-experimental = [
"htsget-config/c4gh-experimental",
"htsget-search/c4gh-experimental",
"htsget-http/c4gh-experimental",
"htsget-axum/c4gh-experimental",
"htsget-test/c4gh-experimental"
experimental = [
"htsget-config/experimental",
"htsget-search/experimental",
"htsget-http/experimental",
"htsget-axum/experimental",
"htsget-test/experimental"
]
default = []

Expand Down
5 changes: 3 additions & 2 deletions htsget-actix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This crate is used for running a local instance of htsget-rs. It is based on:

## Usage

This application has the same functionality as [htsget-axum]. To use it, following the [htsget-axum][htsget-axum-usage] instructions, and
This application has the same functionality as [htsget-axum]. To use it, following the [htsget-axum][htsget-axum] instructions, and
replace any calls to `htsget-axum` with `htsget-actix`.

It is recommended to use [htsget-axum] because it better fits with the rest of [htsget-rs]. For example [htsget-actix]
Expand All @@ -50,7 +50,7 @@ are exposed in the public API.
This crate has the following features:
* `s3-storage`: used to enable `S3Storage` functionality.
* `url-storage`: used to enable `UrlStorage` functionality.
* `c4gh-experimental`: used to enable `C4GHStorage` functionality.
* `experimental`: used to enable `C4GHStorage` functionality.

## Benchmarks
Benchmarks for this crate written using [Criterion.rs][criterion-rs], and aim to compare the performance of this crate with the
Expand All @@ -76,6 +76,7 @@ cargo bench -p htsget-axum -- HEAVY
[criterion-rs]: https://github.com/bheisler/criterion.rs
[htsget-refserver]: https://github.com/ga4gh/htsget-refserver
[data-vcf]: ../data/vcf
[htsget-axum]: ../htsget-axum/README.md#usage

## License

Expand Down
4 changes: 2 additions & 2 deletions htsget-actix/src/handlers/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::handle_response;

/// GET request reads endpoint
#[instrument(skip(app_state))]
pub async fn reads<H: HtsGet + Send + Sync + 'static>(
pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
path: Path<String>,
http_request: HttpRequest,
Expand All @@ -32,7 +32,7 @@ pub async fn reads<H: HtsGet + Send + Sync + 'static>(

/// GET request variants endpoint
#[instrument(skip(app_state))]
pub async fn variants<H: HtsGet + Send + Sync + 'static>(
pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
path: Path<String>,
http_request: HttpRequest,
Expand Down
4 changes: 2 additions & 2 deletions htsget-actix/src/handlers/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::handle_response;

/// POST request reads endpoint
#[instrument(skip(app_state))]
pub async fn reads<H: HtsGet + Send + Sync + 'static>(
pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
body: Json<PostRequest>,
path: Path<String>,
Expand All @@ -42,7 +42,7 @@ pub async fn reads<H: HtsGet + Send + Sync + 'static>(

/// POST request variants endpoint
#[instrument(skip(app_state))]
pub async fn variants<H: HtsGet + Send + Sync + 'static>(
pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
body: Json<PostRequest>,
path: Path<String>,
Expand Down
6 changes: 3 additions & 3 deletions htsget-actix/src/handlers/service_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::AppState;

/// Gets the JSON to return for a service-info endpoint
#[instrument(skip(app_state))]
pub fn get_service_info_json<H: HtsGet + Send + Sync + 'static>(
pub fn get_service_info_json<H: HtsGet + Clone + Send + Sync + 'static>(
app_state: &AppState<H>,
endpoint: Endpoint,
) -> impl Responder {
Expand All @@ -26,14 +26,14 @@ pub fn get_service_info_json<H: HtsGet + Send + Sync + 'static>(
}

/// Gets the JSON to return for the reads service-info endpoint
pub async fn reads_service_info<H: HtsGet + Send + Sync + 'static>(
pub async fn reads_service_info<H: HtsGet + Clone + Send + Sync + 'static>(
app_state: Data<AppState<H>>,
) -> impl Responder {
get_service_info_json(app_state.get_ref(), Endpoint::Reads)
}

/// Gets the JSON to return for the variants service-info endpoint
pub async fn variants_service_info<H: HtsGet + Send + Sync + 'static>(
pub async fn variants_service_info<H: HtsGet + Clone + Send + Sync + 'static>(
app_state: Data<AppState<H>>,
) -> impl Responder {
get_service_info_json(app_state.get_ref(), Endpoint::Variants)
Expand Down
8 changes: 3 additions & 5 deletions htsget-actix/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use actix_cors::Cors;
use actix_web::dev::Server;
use actix_web::{web, App, HttpServer};
Expand All @@ -18,19 +16,19 @@ pub mod handlers;

/// Represents the actix app state.
pub struct AppState<H: HtsGet> {
pub htsget: Arc<H>,
pub htsget: H,
pub config_service_info: ServiceInfo,
}

/// Configure the query server.
pub fn configure_server<H: HtsGet + Send + Sync + 'static>(
pub fn configure_server<H: HtsGet + Clone + Send + Sync + 'static>(
service_config: &mut web::ServiceConfig,
htsget: H,
config_service_info: ServiceInfo,
) {
service_config
.app_data(web::Data::new(AppState {
htsget: Arc::new(htsget),
htsget,
config_service_info,
}))
.service(
Expand Down
12 changes: 6 additions & 6 deletions htsget-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ url-storage = [
"htsget-test/url-storage",
"htsget-http/url-storage"
]
c4gh-experimental = [
"htsget-config/c4gh-experimental",
"htsget-search/c4gh-experimental",
"htsget-test/c4gh-experimental",
"htsget-http/c4gh-experimental"
experimental = [
"htsget-config/experimental",
"htsget-search/experimental",
"htsget-test/experimental",
"htsget-http/experimental"
]
default = []

Expand All @@ -40,7 +40,7 @@ tower-http = { version = "0.5", features = ["trace", "cors", "fs"] }
http = "1"
axum = { version = "0.7", features = ["http2"] }
axum-extra = { version = "0.9", features = ["erased-json"] }
tower = { version = "0.4", features = ["make"] }
tower = { version = "0.5", features = ["make", "util"] }

# Async
tokio-rustls = "0.26"
Expand Down
4 changes: 2 additions & 2 deletions htsget-axum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ for more details on how to configure this.
Run the server with the following to enable Crypt4GH support using the [example config][example-config]:

```sh
cargo run -p htsget-axum --features c4gh-experimental -- --config htsget-config/examples/config-files/c4gh.toml
cargo run -p htsget-axum --features experimental -- --config htsget-config/examples/config-files/c4gh.toml
```

Crypt4GH encrypted byte ranges can be queried:
Expand Down Expand Up @@ -171,7 +171,7 @@ htsget-rs. It also contains the data block server which fetches data from a `Loc
This crate has the following features:
* `s3-storage`: used to enable `S3Storage` functionality.
* `url-storage`: used to enable `UrlStorage` functionality.
* `c4gh-experimental`: used to enable `C4GHStorage` functionality.
* `experimental`: used to enable `C4GHStorage` functionality.

## License

Expand Down
4 changes: 2 additions & 2 deletions htsget-axum/src/handlers/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::server::AppState;
use super::handle_response;

/// POST request reads endpoint.
pub async fn reads<H: HtsGet + Send + Sync + 'static>(
pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
path: Path<String>,
headers: HeaderMap,
Expand All @@ -27,7 +27,7 @@ pub async fn reads<H: HtsGet + Send + Sync + 'static>(
}

/// POST request variants endpoint.
pub async fn variants<H: HtsGet + Send + Sync + 'static>(
pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
request: Query<HashMap<String, String>>,
path: Path<String>,
headers: HeaderMap,
Expand Down
4 changes: 2 additions & 2 deletions htsget-axum/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ use crate::server::ticket::TicketServer;
/// Represents the axum app state.
#[derive(Debug, Clone)]
pub struct AppState<H: HtsGet> {
pub(crate) htsget: Arc<H>,
pub(crate) htsget: H,
pub(crate) service_info: ServiceInfo,
}

impl<H: HtsGet> AppState<H> {
/// Create a new app state.
pub fn new(htsget: Arc<H>, service_info: ServiceInfo) -> Self {
pub fn new(htsget: H, service_info: ServiceInfo) -> Self {
Self {
htsget,
service_info,
Expand Down
3 changes: 1 addition & 2 deletions htsget-axum/src/server/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use htsget_config::config::cors::CorsConfig;
use htsget_config::config::{Config, ServiceInfo, TicketServerConfig};
use htsget_search::HtsGet;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::task::JoinHandle;
use tower::ServiceBuilder;
use tower_http::trace::TraceLayer;
Expand Down Expand Up @@ -79,7 +78,7 @@ where
.layer(TraceLayer::new_for_http())
.layer(configure_cors(cors)),
)
.with_state(AppState::new(Arc::new(htsget), service_info))
.with_state(AppState::new(htsget, service_info))
}

/// Get the local address the server has bound to.
Expand Down
4 changes: 2 additions & 2 deletions htsget-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ repository = "https://github.com/umccr/htsget-rs"
[features]
s3-storage = []
url-storage = ["dep:reqwest"]
c4gh-experimental = ["dep:crypt4gh"]
experimental = ["dep:crypt4gh"]
default = []

[dependencies]
thiserror = "1"
async-trait = "0.1"
noodles = { version = "0.80", features = ["core"] }
noodles = { version = "0.82", features = ["core"] }
serde = { version = "1", features = ["derive"] }
serde_with = "3"
serde_regex = "1"
Expand Down
4 changes: 2 additions & 2 deletions htsget-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ See the MinIO deployment [example][minio-deployment] for more information on how
### Crypt4GH

There is experimental support for serving [Crypt4GH][c4gh] encrypted files. This can be enabled by compiling with the
`c4gh-experimental` feature flag.
`experimental` feature flag.

This allows htsget-rs to read Crypt4GH files and serve them encrypted, directly to the client. In the process of
serving the data, htsget-rs will decrypt the headers of the Crypt4GH files and reencrypt them so that the client can read
Expand Down Expand Up @@ -535,7 +535,7 @@ regex, and changing it by using a substitution string.
This crate has the following features:
* `s3-storage`: used to enable `S3Storage` functionality.
* `url-storage`: used to enable `UrlStorage` functionality.
* `c4gh-experimental`: used to enable `C4GHStorage` functionality.
* `experimental`: used to enable `C4GHStorage` functionality.

## License

Expand Down
2 changes: 1 addition & 1 deletion htsget-config/examples/config-files/c4gh.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# An example of running htsget-rs with Crypt4GH enabled.
# Run with `cargo run -p htsget-axum --features c4gh-experimental -- --config htsget-config/examples/config-files/c4gh.toml`
# Run with `cargo run -p htsget-axum --features experimental -- --config htsget-config/examples/config-files/c4gh.toml`

ticket_server_addr = "127.0.0.1:8080"
data_server_addr = "127.0.0.1:8081"
Expand Down
6 changes: 3 additions & 3 deletions htsget-config/src/storage/object/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Defines the type of object used by storage.
//!

#[cfg(feature = "c4gh-experimental")]
#[cfg(feature = "experimental")]
pub mod c4gh;

#[cfg(feature = "c4gh-experimental")]
#[cfg(feature = "experimental")]
use crate::storage::object::c4gh::C4GHKeys;
use serde::{Deserialize, Serialize};

Expand All @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
pub enum ObjectType {
#[default]
Regular,
#[cfg(feature = "c4gh-experimental")]
#[cfg(feature = "experimental")]
C4GH {
#[serde(flatten, skip_serializing)]
keys: C4GHKeys,
Expand Down
2 changes: 1 addition & 1 deletion htsget-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository = "https://github.com/umccr/htsget-rs"
[features]
s3-storage = ["htsget-config/s3-storage", "htsget-search/s3-storage", "htsget-test/s3-storage"]
url-storage = ["htsget-config/url-storage", "htsget-search/url-storage", "htsget-test/url-storage"]
c4gh-experimental = ["htsget-config/c4gh-experimental", "htsget-search/c4gh-experimental", "htsget-test/c4gh-experimental"]
experimental = ["htsget-config/experimental", "htsget-search/experimental", "htsget-test/experimental"]
default = []

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion htsget-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These functions take query and endpoint information, and process it using [htsge
This crate has the following features:
* `s3-storage`: used to enable `S3Storage` functionality.
* `url-storage`: used to enable `UrlStorage` functionality.
* `c4gh-experimental`: used to enable `C4GHStorage` functionality.
* `experimental`: used to enable `C4GHStorage` functionality.

[warp]: https://github.com/seanmonstar/warp
[htsget-search]: ../htsget-search
Expand Down
6 changes: 2 additions & 4 deletions htsget-http/src/http_core.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use futures::stream::FuturesOrdered;
use futures::StreamExt;
use tokio::select;
Expand All @@ -19,7 +17,7 @@ use crate::{
/// consulted [here](https://samtools.github.io/hts-specs/htsget.html)
#[instrument(level = "debug", skip_all, ret)]
pub async fn get(
searcher: Arc<impl HtsGet + Send + Sync + 'static>,
searcher: impl HtsGet + Send + Sync + 'static,
request: Request,
endpoint: Endpoint,
) -> Result<JsonResponse> {
Expand All @@ -39,7 +37,7 @@ pub async fn get(
/// The parameters can be consulted [here](https://samtools.github.io/hts-specs/htsget.html)
#[instrument(level = "debug", skip_all, ret)]
pub async fn post(
searcher: Arc<impl HtsGet + Send + Sync + 'static>,
searcher: impl HtsGet + Clone + Send + Sync + 'static,
body: PostRequest,
request: Request,
endpoint: Endpoint,
Expand Down
7 changes: 3 additions & 4 deletions htsget-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn merge_responses(responses: Vec<Response>) -> Option<Response> {
mod tests {
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;

use http::uri::Authority;

Expand Down Expand Up @@ -270,8 +269,8 @@ mod tests {
.join("data")
}

fn get_searcher() -> Arc<impl HtsGet> {
Arc::new(HtsGetFromStorage::new(Storage::new(
fn get_searcher() -> impl HtsGet + Clone {
HtsGetFromStorage::new(Storage::new(
LocalStorage::new(
get_base_path(),
ConfigLocalStorage::new(
Expand All @@ -283,6 +282,6 @@ mod tests {
),
)
.unwrap(),
)))
))
}
}
4 changes: 1 addition & 3 deletions htsget-http/src/service_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use serde::{Deserialize, Serialize};
use tracing::debug;
use tracing::instrument;
Expand Down Expand Up @@ -97,7 +95,7 @@ pub fn get_service_info_with(
#[instrument(level = "debug", skip_all)]
pub fn get_service_info_json(
endpoint: Endpoint,
searcher: Arc<impl HtsGet + Send + Sync + 'static>,
searcher: impl HtsGet + Send + Sync + 'static,
config: &ConfigServiceInfo,
) -> ServiceInfo {
debug!(endpoint = ?endpoint,"getting service-info response for endpoint");
Expand Down
12 changes: 6 additions & 6 deletions htsget-lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ repository = "https://github.com/umccr/htsget-rs"
[features]
s3-storage = ["htsget-axum/s3-storage", "htsget-config/s3-storage", "htsget-search/s3-storage", "htsget-http/s3-storage", "htsget-test/s3-storage"]
url-storage = ["htsget-axum/url-storage", "htsget-config/url-storage", "htsget-search/url-storage", "htsget-http/url-storage", "htsget-test/url-storage"]
c4gh-experimental = [
"htsget-axum/c4gh-experimental",
"htsget-config/c4gh-experimental",
"htsget-search/c4gh-experimental",
"htsget-http/c4gh-experimental",
"htsget-test/c4gh-experimental"
experimental = [
"htsget-axum/experimental",
"htsget-config/experimental",
"htsget-search/experimental",
"htsget-http/experimental",
"htsget-test/experimental"
]
default = []

Expand Down
Loading

0 comments on commit c653daa

Please sign in to comment.