diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-12 18:16:46 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-12 18:16:46 +0800 |
| commit | d104ee359c9b084705256cc6dd74a06a352c0f4e (patch) | |
| tree | 9bfc6845e5c98dd25b882ad7f0981d3dde1ea033 /crates/vcs_data/src | |
| parent | ffdc23d102faab74838a36a8044c6f11b289d760 (diff) | |
feat: Update data configuration structures
- Add new configuration fields for local and vault data
- Remove outdated todo.txt file
Diffstat (limited to 'crates/vcs_data/src')
| -rw-r--r-- | crates/vcs_data/src/data/local/config.rs | 25 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/vault/config.rs | 78 |
2 files changed, 99 insertions, 4 deletions
diff --git a/crates/vcs_data/src/data/local/config.rs b/crates/vcs_data/src/data/local/config.rs index 5444047..338d01b 100644 --- a/crates/vcs_data/src/data/local/config.rs +++ b/crates/vcs_data/src/data/local/config.rs @@ -5,6 +5,7 @@ use std::net::SocketAddr; use crate::constants::CLIENT_FILE_WORKSPACE; use crate::constants::PORT; use crate::data::member::MemberId; +use crate::data::vault::config::VaultUuid; #[derive(Serialize, Deserialize, ConfigFile)] #[cfg_file(path = CLIENT_FILE_WORKSPACE)] @@ -16,6 +17,14 @@ pub struct LocalConfig { /// The member ID used by the current local workspace. /// This ID will be used to verify access permissions when connecting to the upstream server. using_account: MemberId, + + /// Whether the local workspace is stained. + /// + /// If stained, it can only set an upstream server with the same identifier. + /// + /// If the value is None, it means not stained; + /// otherwise, it contains the stain identifier (i.e., the upstream vault's unique ID) + stained_uuid: Option<VaultUuid>, } impl Default for LocalConfig { @@ -26,6 +35,7 @@ impl Default for LocalConfig { PORT, )), using_account: "unknown".to_string(), + stained_uuid: None, } } } @@ -50,4 +60,19 @@ impl LocalConfig { pub fn current_account(&self) -> MemberId { self.using_account.clone() } + + /// Check if the local workspace is stained. + pub fn stained(&self) -> bool { + self.stained_uuid.is_some() + } + + /// Stain the local workspace with the given UUID. + pub fn stain(&mut self, uuid: VaultUuid) { + self.stained_uuid = Some(uuid); + } + + /// Unstain the local workspace. + pub fn unstain(&mut self) { + self.stained_uuid = None; + } } diff --git a/crates/vcs_data/src/data/vault/config.rs b/crates/vcs_data/src/data/vault/config.rs index 6eea25a..5586e1e 100644 --- a/crates/vcs_data/src/data/vault/config.rs +++ b/crates/vcs_data/src/data/vault/config.rs @@ -2,15 +2,22 @@ use std::net::{IpAddr, Ipv4Addr}; use cfg_file::ConfigFile; use serde::{Deserialize, Serialize}; +use uuid::Uuid; use crate::constants::{PORT, SERVER_FILE_VAULT}; use crate::data::member::{Member, MemberId}; +pub type VaultName = String; +pub type VaultUuid = Uuid; + #[derive(Serialize, Deserialize, ConfigFile)] #[cfg_file(path = SERVER_FILE_VAULT)] pub struct VaultConfig { + /// Vault uuid, unique identifier for the vault + vault_uuid: VaultUuid, + /// Vault name, which can be used as the project name and generally serves as a hint - vault_name: String, + vault_name: VaultName, /// Vault admin id, a list of member id representing administrator identities vault_admin_list: Vec<MemberId>, @@ -42,6 +49,7 @@ pub struct VaultServerConfig { impl Default for VaultConfig { fn default() -> Self { Self { + vault_uuid: Uuid::new_v4(), vault_name: "JustEnoughVault".to_string(), vault_admin_list: Vec::new(), server_config: VaultServerConfig { @@ -56,12 +64,12 @@ impl Default for VaultConfig { /// Vault Management impl VaultConfig { - // Change name of the vault. + /// Change name of the vault. pub fn change_name(&mut self, name: impl Into<String>) { self.vault_name = name.into() } - // Add admin + /// Add admin pub fn add_admin(&mut self, member: &Member) { let uuid = member.id(); if !self.vault_admin_list.contains(&uuid) { @@ -69,9 +77,71 @@ impl VaultConfig { } } - // Remove admin + /// Remove admin pub fn remove_admin(&mut self, member: &Member) { let id = member.id(); self.vault_admin_list.retain(|x| x != &id); } + + /// Get vault UUID + pub fn vault_uuid(&self) -> &VaultUuid { + &self.vault_uuid + } + + /// Set vault UUID + pub fn set_vault_uuid(&mut self, vault_uuid: VaultUuid) { + self.vault_uuid = vault_uuid; + } + + /// Get vault name + pub fn vault_name(&self) -> &VaultName { + &self.vault_name + } + + /// Set vault name + pub fn set_vault_name(&mut self, vault_name: VaultName) { + self.vault_name = vault_name; + } + + /// Get vault admin list + pub fn vault_admin_list(&self) -> &Vec<MemberId> { + &self.vault_admin_list + } + + /// Set vault admin list + pub fn set_vault_admin_list(&mut self, vault_admin_list: Vec<MemberId>) { + self.vault_admin_list = vault_admin_list; + } + + /// Get server config + pub fn server_config(&self) -> &VaultServerConfig { + &self.server_config + } + + /// Set server config + pub fn set_server_config(&mut self, server_config: VaultServerConfig) { + self.server_config = server_config; + } +} + +impl VaultServerConfig { + /// Get local bind IP address + pub fn local_bind(&self) -> &IpAddr { + &self.local_bind + } + + /// Set local bind IP address + pub fn set_local_bind(&mut self, local_bind: IpAddr) { + self.local_bind = local_bind; + } + + /// Get port + pub fn port(&self) -> u16 { + self.port + } + + /// Set port + pub fn set_port(&mut self, port: u16) { + self.port = port; + } } |
