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

feat: path-based locations #288

Merged
merged 6 commits into from
Jan 6, 2025
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
684 changes: 295 additions & 389 deletions htsget-config/README.md

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions htsget-config/examples/config-files/basic.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
# An example of running htsget-rs.
# Run with `cargo run --all-features -- --config htsget-config/examples/config-files/basic.toml`
# Run with `cargo run -p htsget-axum --all-features -- --config htsget-config/examples/config-files/basic.toml`

ticket_server_addr = "127.0.0.1:8080"
data_server_addr = "127.0.0.1:8081"

# Serve data locally from the `data` directory.
[[resolvers]]
regex = '.*'
substitution_string = '$0'
storage.backend = 'Local'

# Serve data from S3 if the id is prefixed with `example_bucket`.
[[resolvers]]
regex = '^(example_bucket)/(?P<key>.*)$'
substitution_string = '$key'
storage.backend = 'S3'
# Uses the first capture group in the regex as the bucket.
# Serve data locally from the `data` directory or from an S3 bucket called `bucket` depending on the prefix.
locations = [ "file://data/file_prefix", "s3://bucket/s3_prefix" ]
28 changes: 12 additions & 16 deletions htsget-config/examples/config-files/c4gh.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# An example of running htsget-rs with Crypt4GH enabled.
# Run with `cargo run -p htsget-axum --features experimental -- --config htsget-config/examples/config-files/c4gh.toml`
# Run with `cargo run -p htsget-axum --features experimental,s3-storage -- --config htsget-config/examples/config-files/c4gh.toml`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s3-storage shouldn't be required, IMHO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fair. It's required because the secrets manager has all the AWS dependencies, which s3-storage enables.

Originally, only S3 was required for any AWS-specific things, but now that's changed, maybe this feature should be called aws rather than s3-storage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to rename/simplify url-storage too? E.g.

s3-storage -> aws
url-storage -> url

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make this a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the renaming, but shouldn't we have a file:// for the secrets management part? I'm thinking about local testing and/or devving, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is kind = "File" for local keys:

backend.keys.kind = "File"
backend.keys.private = "data/c4gh/keys/bob.sec" # pragma: allowlist secret
backend.keys.public = "data/c4gh/keys/alice.pub"

And kind = "SecretsManager" for secrets manager keys:

backend.keys.kind = "SecretsManager"
backend.keys.private = "htsget/test_c4gh_private_key" # pragma: allowlist secret
backend.keys.public = "htsget/test_c4gh_public_key"

Is that what you mean? Or some sort of local SecretsManager option?

Copy link
Member

@brainstorm brainstorm Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm only concerned about being able to run c4gh infra locally, without requiring aws deps... that "Run with cargo run..." line change seems to imply that s3-storage is absolutely required? From what you just said it seems it's not, perhaps being explicit about both options (only via experimental and experimental+aws feature flags) should be explicitly stated?

Copy link
Member Author

@mmalenic mmalenic Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, it's not required. It's only required if you remove the comments in that file that use kind = "SecretsManager".

I'll make this clearer on the next PR. Maybe it should just be --all-features in all the examples to avoid any confusion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should just be --all-features in all the examples to avoid any confusion?

🤔 ... that'd exercise our error management logic and corresponding error messages, i.e: running with file:// paths and aws-related c4gh secrets management. It might make more sense this way if errors are clear, yeah!


ticket_server_addr = "127.0.0.1:8080"
data_server_addr = "127.0.0.1:8081"
ticket_server.addr = "127.0.0.1:8080"
data_server.addr = "127.0.0.1:8081"

[[resolvers]]
[[locations]]
regex = ".*"
substitution_string = "$0"
backend.kind = "File"

[resolvers.storage]
backend = 'Local'
backend.keys.kind = "File"
backend.keys.private = "data/c4gh/keys/bob.sec" # pragma: allowlist secret
backend.keys.public = "data/c4gh/keys/alice.pub"

[resolvers.storage.keys]
location = "Local"
private_key = "data/c4gh/keys/bob.sec" # pragma: allowlist secret
recipient_public_key = "data/c4gh/keys/alice.pub"

# Or, use AWS secrets manager to store keys.
#[resolvers.storage.keys]
#location = "SecretsManager"
#private_key = "htsget/test_c4gh_private_key" # pragma: allowlist secret
#recipient_public_key = "htsget/test_c4gh_public_key"
## Or, use AWS secrets manager to store keys.
#backend.keys.kind = "SecretsManager"
#backend.keys.private = "htsget/test_c4gh_private_key" # pragma: allowlist secret
#backend.keys.public = "htsget/test_c4gh_public_key"
71 changes: 34 additions & 37 deletions htsget-config/examples/config-files/default.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
# Config generated by running `cargo run -p htsget-axum -- -p`

formatting_style = "Full"
ticket_server_addr = "127.0.0.1:8080"
ticket_server_cors_allow_credentials = false
ticket_server_cors_allow_origins = ["http://localhost:8080"]
ticket_server_cors_allow_headers = "All"
ticket_server_cors_allow_methods = "All"
ticket_server_cors_max_age = 86400
ticket_server_cors_expose_headers = []
data_server_enabled = true
data_server_addr = "127.0.0.1:8081"
data_server_local_path = "./"
data_server_serve_at = ""
data_server_cors_allow_credentials = false
data_server_cors_allow_origins = ["http://localhost:8080"]
data_server_cors_allow_headers = "All"
data_server_cors_allow_methods = "All"
data_server_cors_max_age = 86400
data_server_cors_expose_headers = []

[[resolvers]]
regex = ".*"
substitution_string = "$0"
storage = "Local"

[resolvers.allow_guard]
allow_reference_names = "All"
allow_fields = "All"
allow_tags = "All"
allow_formats = [
"BAM",
"CRAM",
"VCF",
"BCF",
]
allow_classes = [
"body",
"header",
]

[ticket_server]
addr = "127.0.0.1:8080"

[ticket_server.cors]
allow_credentials = false
allow_origins = "Mirror"
allow_headers = "Mirror"
allow_methods = "Mirror"
max_age = 2592000
expose_headers = "All"

[data_server]
addr = "127.0.0.1:8081"
local_path = "./"

[data_server.cors]
allow_credentials = false
allow_origins = "Mirror"
allow_headers = "Mirror"
allow_methods = "Mirror"
max_age = 2592000
expose_headers = "All"

[service_info]

[[locations]]
prefix = ""

[locations.backend]
kind = "File"
scheme = "HTTP"
authority = "127.0.0.1:8081"
local_path = "./"
25 changes: 12 additions & 13 deletions htsget-config/examples/config-files/s3_storage.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# An example for a server which uses s3 storage with data located in "bucket".
# Run with `cargo run -p htsget-axum --features s3-storage -- --config htsget-config/examples/config-files/s3_storage.toml`

ticket_server_cors_allow_headers = "All"
ticket_server_cors_allow_methods = "All"
ticket_server_cors_allow_credentials = true
ticket_server_cors_max_age = 300
ticket_server.cors.allow_headers = "All"
ticket_server.cors.allow_methods = "All"
ticket_server.cors.allow_credentials = false
ticket_server.cors.max_age = 300

data_server_enabled = false
data_server = "None"

[[resolvers]]
regex = '^(bucket)/(?P<key>.*)$'
substitution_string = '$key'
storage.backend = 'S3'
locations = "s3://bucket"

# Or, set the bucket manually
#[resolvers.storage]
#backend = 'S3'
#bucket = 'bucket'
## Or, set using regex locations
#[[locations]]
#regex = "^(bucket)/(?P<key>.*)$"
#substitution_string = "$key"
#backend.kind = "S3"
#backend.bucket = "bucket"
23 changes: 12 additions & 11 deletions htsget-config/examples/config-files/tls_data_server.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# An example config file for a TLS data server that uses a local storage backend.
# Run with `cargo run -p htsget-axum -- --config htsget-config/examples/config-files/tls_data_server.toml`

ticket_server_addr = "0.0.0.0:8080"
data_server_addr = "0.0.0.0:8081"
data_server_cors_allow_origins = "All"
data_server_tls.cert = "cert.pem"
data_server_tls.key = "key.pem"
ticket_server.addr = "0.0.0.0:8080"
data_server.addr = "0.0.0.0:8081"
data_server.cors.allow_origins = "All"
data_server.tls.cert = "cert.pem"
data_server.tls.key = "key.pem"

[[resolvers]]
regex = ".*"
substitution_string = "$0"
locations = "file://data"

[resolvers.storage]
backend = 'Local'
use_data_server_config = true
## Or, set using regex locations
#[[locations]]
#regex = ".*"
#substitution_string = "$0"
#backend.kind = "File"
#backend.local_path = "data"
23 changes: 12 additions & 11 deletions htsget-config/examples/config-files/tls_ticket_server.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# An example config file for a TLS ticket server that uses S3 as a storage backend.
# Run with `cargo run -p htsget-axum --features s3-storage -- --config htsget-config/examples/config-files/tls_ticket_server.toml`

ticket_server_addr = "0.0.0.0:8080"
ticket_server_cors_allow_origins = "All"
ticket_server_tls.cert = "cert.pem"
ticket_server_tls.key = "key.pem"
data_server_addr = "0.0.0.0:8081"
ticket_server.addr = "0.0.0.0:8080"
ticket_server.cors_allow_origins = "All"
ticket_server.tls.cert = "cert.pem"
ticket_server.tls.key = "key.pem"
data_server.addr = "0.0.0.0:8081"

[[resolvers]]
regex = ".*"
substitution_string = "$0"
locations = "s3://bucket"

[resolvers.storage]
backend = 'S3'
bucket = "bucket"
## Or, set using regex locations
#[[locations]]
#regex = ".*"
#substitution_string = "$0"
#backend.kind = "S3"
#backend.bucket = "bucket"
42 changes: 22 additions & 20 deletions htsget-config/examples/config-files/url_storage.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
# `cargo run -p htsget-axum --features url-storage -- --config htsget-config/examples/config-files/url_storage.toml`
# in the project directory.

ticket_server_addr = "127.0.0.1:8082"
ticket_server_cors_allow_origins = "All"
ticket_server.addr = "127.0.0.1:8082"
ticket_server.cors.allow_origins = "All"

ticket_server_cert = "cert.pem"
ticket_server_key = "key.pem"
ticket_server.tls.cert = "cert.pem"
ticket_server.tls.key = "key.pem"

data_server_enabled = false
data_server = "None"

[[resolvers]]
regex = ".*"
substitution_string = "$0"
locations = "https://127.0.0.1:8081"

[resolvers.storage]
backend = 'Url'
url = "http://127.0.0.1:8081"
response_url = "https://127.0.0.1:8081"
forward_headers = true

# Set client authentication
#tls.key = "key.pem"
#tls.cert = "cert.pem"

# Set root certificates
#tls.root_store = "cert.pem"
## Or, set using regex locations
#[[locations]]
#regex = ".*"
#substitution_string = "$0"
#
#backend.kind = "Url"
#backend.url = "http://127.0.0.1:8081"
#backend.response_url = "https://127.0.0.1:8081"
#backend.forward_headers = true
#
## Set client authentication
#backend.tls.key = "key.pem"
#backend.tls.cert = "cert.pem"
#
## Set root certificates
#backend.tls.root_store = "root.crt"
Loading
Loading