upstream_rs/models/upstream/
app_config.rs1use crate::models::common::enums::CompressionLevel;
2use serde::{Deserialize, Serialize};
3
4pub const CONFIG_STORAGE_VERSION: u32 = 2;
5
6const MB: u64 = 1024 * 1024;
7
8const LOW_PARALLEL_DOWNLOAD_SIZE_MB: u64 = 16;
9const HIGH_PARALLEL_DOWNLOAD_SIZE_MB: u64 = 64;
10const LOW_PARALLEL_DOWNLOADS: usize = 2;
11const HIGH_PARALLEL_DOWNLOADS: usize = 4;
12
13#[derive(Debug, Clone, Serialize, Deserialize, Default)]
14#[serde(default)]
15pub struct ProviderConfig {
16 pub api_token: Option<String>,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(default)]
21pub struct RollbackConfig {
22 pub compression_level: CompressionLevel,
23 pub stored_artifacts: u32,
24}
25
26impl Default for RollbackConfig {
27 fn default() -> Self {
28 Self {
29 compression_level: CompressionLevel::High,
30 stored_artifacts: 1,
31 }
32 }
33}
34
35#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
36#[serde(default)]
37pub struct DownloadConfig {
38 pub low_threshold_mb: u64,
39 pub high_threshold_mb: u64,
40 pub low_threads: usize,
41 pub high_threads: usize,
42}
43
44impl Default for DownloadConfig {
45 fn default() -> Self {
46 Self {
47 low_threshold_mb: LOW_PARALLEL_DOWNLOAD_SIZE_MB,
48 high_threshold_mb: HIGH_PARALLEL_DOWNLOAD_SIZE_MB,
49 low_threads: LOW_PARALLEL_DOWNLOADS,
50 high_threads: HIGH_PARALLEL_DOWNLOADS,
51 }
52 }
53}
54
55impl DownloadConfig {
56 pub fn low_threshold_bytes(self) -> u64 {
57 self.low_threshold_mb.saturating_mul(MB)
58 }
59
60 pub fn high_threshold_bytes(self) -> u64 {
61 self.high_threshold_mb.saturating_mul(MB)
62 }
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(default, deny_unknown_fields)]
67pub struct AppConfig {
68 pub version: u32,
69 pub github: ProviderConfig,
70 pub gitlab: ProviderConfig,
71 pub gitea: ProviderConfig,
72 pub download: DownloadConfig,
73 pub rollback: RollbackConfig,
74}
75
76impl Default for AppConfig {
77 fn default() -> Self {
78 Self {
79 version: CONFIG_STORAGE_VERSION,
80 github: ProviderConfig::default(),
81 gitlab: ProviderConfig::default(),
82 gitea: ProviderConfig::default(),
83 download: DownloadConfig::default(),
84 rollback: RollbackConfig::default(),
85 }
86 }
87}