Skip to content

Commit 5d13fc4

Browse files
committed
feat(config): add an option to forward the id of the path segment
1 parent a39be58 commit 5d13fc4

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

htsget-config/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,13 @@ The authorization server should respond with a rule set that htsget-rs can use t
430430

431431
The following additional options can be configured under the `auth` table to enable this:
432432

433-
| Option | Description | Type | Default |
434-
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|----------|
435-
| `authorization_url` | The URL which will be called to authorize the user. A GET request will be issued to the url. Alternatively, this can be a file path to authorize users based on static config. | URL | Not set. |
436-
| `forward_headers` | For each header specified, forward any headers from the client to the authorization server. Headers are forwarded with the `Htsget-Context-` as a prefix. | Array of header names | Not set. |
437-
| `forward_endpoint_type` | Forwards the type of endpoint that the request used in a header called `Htsget-Context-Endpoint-Type`. The value of this header will either be `reads` or `variants`, depending on whether the user requested the reads or variants endpoint. | Boolean | `false` |
438-
| `passthrough_auth` | Forward the authorization header to the authorization server directly without renaming it to a `Htsget-Context-` custom header. If this is true, then the `Authorization` header is required with the request. | Boolean | `false` |
433+
| Option | Description | Type | Default |
434+
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|----------|
435+
| `authorization_url` | The URL which will be called to authorize the user. A GET request will be issued to the url. Alternatively, this can be a file path to authorize users based on static config. | URL | Not set. |
436+
| `forward_headers` | For each header specified, forward any headers from the client to the authorization server. Headers are forwarded with the `Htsget-Context-` as a prefix. | Array of header names | Not set. |
437+
| `forward_endpoint_type` | Forwards the type of endpoint that the request used in a header called `Htsget-Context-Endpoint-Type`. The value of this header will either be `reads` or `variants`, depending on whether the user requested the reads or variants endpoint. | Boolean | `false` |
438+
| `forward_id` | Forwards the id of the request in a header called `Htsget-Context-Id`. The value of this header will be request path without the `/reads` or `/variants` component. For example, if a request path is `/reads/<id>`, this header will have the same value as `<id>`. | Boolean | `false` |
439+
| `passthrough_auth` | Forward the authorization header to the authorization server directly without renaming it to a `Htsget-Context-` custom header. If this is true, then the `Authorization` header is required with the request. | Boolean | `false` |
439440

440441
When using the `authorization_url`, the [authentication](#jwt-authentication) config must also be set as htsget-rs will
441442
forward the JWT token to the authorization server so that it can make decisions about the user's authorization. If the

htsget-config/docs/examples/auth.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ passthrough_auth = true
2424
#forward_headers = ["Content-Type"]
2525
## Forward the endpoint type to the auth service.
2626
#forward_endpoint_type = true
27+
## Forward the request id.
28+
#forward_id = true
2729

2830
## Set client authentication
2931
#http.key = "key.pem"

htsget-config/src/config/advanced/auth/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct AuthConfig {
2929
authorization_url: Option<UrlOrStatic>,
3030
forward_headers: Vec<String>,
3131
forward_endpoint_type: bool,
32+
forward_id: bool,
3233
passthrough_auth: bool,
3334
forward_extensions: Vec<ForwardExtensions>,
3435
http_client: HttpClient,
@@ -101,6 +102,11 @@ impl AuthConfig {
101102
self.forward_endpoint_type
102103
}
103104

105+
/// Get whether to forward the id of the request.
106+
pub fn forward_id(&self) -> bool {
107+
self.forward_id
108+
}
109+
104110
/// Get whether to pass through the auth header.
105111
pub fn passthrough_auth(&self) -> bool {
106112
self.passthrough_auth
@@ -133,6 +139,7 @@ pub struct AuthConfigBuilder {
133139
authorization_url: Option<UrlOrStatic>,
134140
forward_headers: Vec<String>,
135141
forward_endpoint_type: bool,
142+
forward_id: bool,
136143
passthrough_auth: bool,
137144
forward_extensions: Vec<ForwardExtensions>,
138145
#[serde(rename = "http", alias = "tls", skip_serializing)]
@@ -206,6 +213,12 @@ impl AuthConfigBuilder {
206213
self
207214
}
208215

216+
/// Set whether to forward the id
217+
pub fn forward_id(mut self, forward_id: bool) -> Self {
218+
self.forward_id = forward_id;
219+
self
220+
}
221+
209222
/// Set whether to pass through auth.
210223
pub fn passthrough_auth(mut self, passthrough_auth: bool) -> Self {
211224
self.passthrough_auth = passthrough_auth;
@@ -228,6 +241,7 @@ impl AuthConfigBuilder {
228241
authorization_url: self.authorization_url,
229242
forward_headers: self.forward_headers,
230243
forward_endpoint_type: self.forward_endpoint_type,
244+
forward_id: self.forward_id,
231245
passthrough_auth: self.passthrough_auth,
232246
forward_extensions: self.forward_extensions,
233247
http_client: self
@@ -254,6 +268,7 @@ impl Default for AuthConfigBuilder {
254268
authorization_url,
255269
forward_headers: vec![],
256270
forward_endpoint_type: false,
271+
forward_id: false,
257272
passthrough_auth: false,
258273
forward_extensions: vec![],
259274
http_client: None,
@@ -394,6 +409,7 @@ mod tests {
394409
passthrough_auth = true
395410
forward_headers = ["header"]
396411
forward_endpoint_type = true
412+
forward_id = true
397413
forward_extensions = [ { json_path = '$.extension', name = 'Extension'} ]
398414
"#,
399415
)
@@ -418,6 +434,7 @@ mod tests {
418434
assert!(config.passthrough_auth());
419435
assert_eq!(config.forward_headers(), ["header".to_string()]);
420436
assert!(config.forward_endpoint_type());
437+
assert!(config.forward_id());
421438
assert_eq!(
422439
config.forward_extensions(),
423440
[ForwardExtensions::new(

0 commit comments

Comments
 (0)