polykit_core/remote_cache/
config.rs1use std::collections::BTreeSet;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct RemoteCacheConfig {
10 pub url: String,
12 pub token: Option<String>,
14 pub env_vars: BTreeSet<String>,
18 pub input_files: Vec<String>,
22 pub max_artifact_size: Option<u64>,
24 pub read_only: bool,
26}
27
28impl Default for RemoteCacheConfig {
29 fn default() -> Self {
30 Self {
31 url: String::new(),
32 token: None,
33 env_vars: BTreeSet::new(),
34 input_files: Vec::new(),
35 max_artifact_size: Some(1024 * 1024 * 1024), read_only: false,
37 }
38 }
39}
40
41impl RemoteCacheConfig {
42 pub fn new(url: impl Into<String>) -> Self {
44 Self {
45 url: url.into(),
46 ..Default::default()
47 }
48 }
49
50 pub fn with_token(mut self, token: impl Into<String>) -> Self {
52 self.token = Some(token.into());
53 self
54 }
55
56 pub fn add_env_var(mut self, var: impl Into<String>) -> Self {
58 self.env_vars.insert(var.into());
59 self
60 }
61
62 pub fn add_env_vars<I>(mut self, vars: I) -> Self
64 where
65 I: IntoIterator<Item = String>,
66 {
67 self.env_vars.extend(vars);
68 self
69 }
70
71 pub fn add_input_file(mut self, pattern: impl Into<String>) -> Self {
73 self.input_files.push(pattern.into());
74 self
75 }
76
77 pub fn read_only(mut self, read_only: bool) -> Self {
79 self.read_only = read_only;
80 self
81 }
82
83 pub fn max_artifact_size(mut self, size: u64) -> Self {
85 self.max_artifact_size = Some(size);
86 self
87 }
88
89 pub fn is_http(&self) -> bool {
91 self.url.starts_with("http://") || self.url.starts_with("https://")
92 }
93
94 pub fn is_filesystem(&self) -> bool {
96 !self.is_http()
97 }
98}