1use serde::{Deserialize, Serialize};
12use std::collections::HashMap;
13
14#[derive(Debug, Clone, Default, Serialize, Deserialize)]
16#[serde(rename_all = "PascalCase")]
17pub struct Api {
18 #[serde(default, rename = "HTTPHeaders")]
20 pub http_headers: HashMap<String, Vec<String>>,
21
22 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub authorizations: Option<HashMap<String, RpcAuthScope>>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "PascalCase")]
30pub struct RpcAuthScope {
31 pub auth_secret: String,
33
34 pub allowed_paths: Vec<String>,
36}
37
38impl Api {
39 pub fn default_http_headers() -> HashMap<String, Vec<String>> {
41 let mut headers = HashMap::new();
42 headers.insert(
43 "Access-Control-Allow-Origin".to_string(),
44 vec!["*".to_string()],
45 );
46 headers
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_api_default() {
56 let api = Api::default();
57 assert!(api.http_headers.is_empty());
58 assert!(api.authorizations.is_none());
59 }
60
61 #[test]
62 fn test_rpc_auth_scope() {
63 let scope = RpcAuthScope {
64 auth_secret: "bearer:mytoken".to_string(),
65 allowed_paths: vec!["/api/v0/id".to_string()],
66 };
67 let json = serde_json::to_string(&scope).unwrap();
68 assert!(json.contains("AuthSecret"));
69 assert!(json.contains("AllowedPaths"));
70 }
71}