upstream_rs/models/upstream/
app_config.rs1use crate::models::common::enums::CompressionLevel;
2use crate::services::trust::{CosignPublicKey, MinisignPublicKey, TrustedSignatureKeys};
3use serde::{Deserialize, Serialize};
4
5const MB: u64 = 1024 * 1024;
6
7const LOW_PARALLEL_DOWNLOAD_SIZE_MB: u64 = 16;
8const HIGH_PARALLEL_DOWNLOAD_SIZE_MB: u64 = 64;
9const LOW_PARALLEL_DOWNLOADS: usize = 2;
10const HIGH_PARALLEL_DOWNLOADS: usize = 4;
11
12#[derive(Debug, Clone, Serialize, Deserialize, Default)]
13#[serde(default)]
14pub struct ProviderConfig {
15 pub api_token: Option<String>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, Default)]
19#[serde(default)]
20pub struct MinisignKeyConfig {
21 pub id: Option<String>,
22 pub key: String,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, Default)]
26#[serde(default)]
27pub struct TrustConfig {
28 pub minisign_public_keys: Vec<MinisignKeyConfig>,
29 pub cosign_public_keys: Vec<CosignKeyConfig>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33#[serde(default)]
34pub struct CosignKeyConfig {
35 pub id: Option<String>,
36 pub key: String,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(default)]
41pub struct RollbackConfig {
42 pub compression_level: CompressionLevel,
43 pub stored_artifacts: u32,
44}
45
46impl Default for RollbackConfig {
47 fn default() -> Self {
48 Self {
49 compression_level: CompressionLevel::None,
50 stored_artifacts: 1,
51 }
52 }
53}
54
55#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
56#[serde(default)]
57pub struct DownloadConfig {
58 pub low_threshold_mb: u64,
59 pub high_threshold_mb: u64,
60 pub low_threads: usize,
61 pub high_threads: usize,
62}
63
64impl Default for DownloadConfig {
65 fn default() -> Self {
66 Self {
67 low_threshold_mb: LOW_PARALLEL_DOWNLOAD_SIZE_MB,
68 high_threshold_mb: HIGH_PARALLEL_DOWNLOAD_SIZE_MB,
69 low_threads: LOW_PARALLEL_DOWNLOADS,
70 high_threads: HIGH_PARALLEL_DOWNLOADS,
71 }
72 }
73}
74
75impl DownloadConfig {
76 pub fn low_threshold_bytes(self) -> u64 {
77 self.low_threshold_mb.saturating_mul(MB)
78 }
79
80 pub fn high_threshold_bytes(self) -> u64 {
81 self.high_threshold_mb.saturating_mul(MB)
82 }
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize, Default)]
86#[serde(default)]
87pub struct AppConfig {
88 pub github: ProviderConfig,
89 pub gitlab: ProviderConfig,
90 pub gitea: ProviderConfig,
91 pub download: DownloadConfig,
92 pub trust: TrustConfig,
93 pub rollback: RollbackConfig,
94}
95
96impl AppConfig {
97 pub fn trusted_signature_keys(&self) -> TrustedSignatureKeys {
98 let minisign_public_keys = self
99 .trust
100 .minisign_public_keys
101 .iter()
102 .map(|k| MinisignPublicKey {
103 id: k.id.clone(),
104 key: k.key.clone(),
105 })
106 .collect();
107
108 let cosign_public_keys = self
109 .trust
110 .cosign_public_keys
111 .iter()
112 .map(|k| CosignPublicKey {
113 id: k.id.clone(),
114 key: k.key.clone(),
115 })
116 .collect();
117
118 TrustedSignatureKeys {
119 minisign_public_keys,
120 cosign_public_keys,
121 }
122 }
123}