everruns_local/
profile.rs1use std::path::{Path, PathBuf};
9
10use everruns_core::typed_id::PrincipalId;
11
12#[derive(Debug, Clone)]
14pub struct LocalProfile {
15 pub data_dir: PathBuf,
17 pub workspace_root: PathBuf,
19 pub base_url: String,
21 pub org_public_id: String,
23 pub owner_principal_id: PrincipalId,
25}
26
27impl Default for LocalProfile {
28 fn default() -> Self {
29 let data_dir = std::env::temp_dir().join("everruns-local");
30 Self {
31 workspace_root: data_dir.join("workspace"),
32 data_dir,
33 base_url: "http://localhost:9300".to_string(),
34 org_public_id: everruns_core::DEFAULT_ORG_PUBLIC_ID.to_string(),
35 owner_principal_id: PrincipalId::from_seed(1),
36 }
37 }
38}
39
40impl LocalProfile {
41 pub fn new(data_dir: impl Into<PathBuf>) -> Self {
44 let data_dir = data_dir.into();
45 Self {
46 workspace_root: data_dir.join("workspace"),
47 data_dir,
48 ..Self::default()
49 }
50 }
51
52 pub fn db_path(&self) -> PathBuf {
54 self.data_dir.join("local.db")
55 }
56
57 pub fn with_workspace_root(mut self, root: impl Into<PathBuf>) -> Self {
58 self.workspace_root = root.into();
59 self
60 }
61
62 pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
63 self.base_url = base_url.into();
64 self
65 }
66
67 pub fn with_org_public_id(mut self, org_public_id: impl Into<String>) -> Self {
68 self.org_public_id = org_public_id.into();
69 self
70 }
71
72 pub fn with_owner_principal_id(mut self, owner_principal_id: PrincipalId) -> Self {
73 self.owner_principal_id = owner_principal_id;
74 self
75 }
76
77 pub fn ensure_dirs(&self) -> std::io::Result<()> {
79 std::fs::create_dir_all(&self.data_dir)?;
80 std::fs::create_dir_all(&self.workspace_root)?;
81 Ok(())
82 }
83
84 pub fn data_dir(&self) -> &Path {
85 &self.data_dir
86 }
87}