refget_server/state.rs
1//! Shared application state for the refget server.
2
3use std::sync::Arc;
4
5use refget_store::{SeqColStore, SequenceStore};
6use serde::{Deserialize, Serialize};
7
8/// Configuration for the refget server.
9///
10/// Loaded from a YAML config file via `--config` or constructed with defaults.
11///
12/// # Example YAML
13///
14/// ```yaml
15/// # Required refget protocol settings
16/// circular_supported: true
17/// algorithms:
18/// - md5
19/// - ga4gh
20/// subsequence_limit: 0 # 0 = no limit
21///
22/// # Sequences to treat as circular (by FASTA name)
23/// circular_sequences:
24/// - NC_001422.1
25/// - chrM
26///
27/// # Optional GA4GH service-info fields
28/// service_info:
29/// organization:
30/// name: "My Organization"
31/// url: "https://example.org"
32/// contact_url: "mailto:admin@example.org"
33/// documentation_url: "https://example.org/docs"
34/// environment: "production"
35/// ```
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(default)]
38pub struct RefgetConfig {
39 /// Whether circular sequence retrieval is supported.
40 pub circular_supported: bool,
41 /// Supported hash algorithms.
42 pub algorithms: Vec<String>,
43 /// Maximum length of a subsequence request (0 = no limit).
44 pub subsequence_limit: u64,
45 /// Sequence names that should be treated as circular.
46 pub circular_sequences: Vec<String>,
47 /// Optional GA4GH service-info fields.
48 pub service_info: ServiceInfoConfig,
49}
50
51/// Optional GA4GH service-info metadata fields.
52///
53/// When set, these are included in the `/sequence/service-info` response.
54/// All fields are optional; unset fields are omitted from the response.
55#[derive(Debug, Clone, Default, Serialize, Deserialize)]
56#[serde(default)]
57pub struct ServiceInfoConfig {
58 /// Organization that runs this service.
59 pub organization: Option<OrganizationConfig>,
60 /// URL to contact the service operator.
61 pub contact_url: Option<String>,
62 /// URL to documentation for this service.
63 pub documentation_url: Option<String>,
64 /// Deployment environment (e.g., "production", "staging").
65 pub environment: Option<String>,
66}
67
68/// Organization metadata for service-info.
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct OrganizationConfig {
71 /// Organization name.
72 pub name: String,
73 /// Organization URL.
74 pub url: String,
75}
76
77impl Default for RefgetConfig {
78 fn default() -> Self {
79 Self {
80 circular_supported: true,
81 algorithms: vec!["md5".to_string(), "ga4gh".to_string(), "trunc512".to_string()],
82 subsequence_limit: 0,
83 circular_sequences: vec![],
84 service_info: ServiceInfoConfig::default(),
85 }
86 }
87}
88
89/// Shared application state passed to all handlers.
90#[derive(Clone)]
91pub struct RefgetState {
92 pub sequence_store: Arc<dyn SequenceStore>,
93 pub seqcol_store: Arc<dyn SeqColStore>,
94 pub config: RefgetConfig,
95}