summaryrefslogtreecommitdiff
path: root/crates/vcs_data/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'crates/vcs_data/src/data')
-rw-r--r--crates/vcs_data/src/data/local/config.rs25
-rw-r--r--crates/vcs_data/src/data/sheet.rs8
-rw-r--r--crates/vcs_data/src/data/vault/config.rs78
3 files changed, 103 insertions, 8 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/sheet.rs b/crates/vcs_data/src/data/sheet.rs
index a6220c9..f1cf67c 100644
--- a/crates/vcs_data/src/data/sheet.rs
+++ b/crates/vcs_data/src/data/sheet.rs
@@ -107,7 +107,7 @@ impl<'a> Sheet<'a> {
}
/// Accept an input package and insert to the sheet
- pub fn accept_import(
+ pub async fn accept_import(
&mut self,
input_name: &InputName,
insert_to: &SheetPathBuf,
@@ -129,7 +129,8 @@ impl<'a> Sheet<'a> {
// Insert to sheet
for (relative_path, virtual_file_id) in input.files {
- let _ = self.add_mapping(insert_to.join(relative_path), virtual_file_id);
+ self.add_mapping(insert_to.join(relative_path), virtual_file_id)
+ .await?;
}
Ok(())
@@ -176,8 +177,7 @@ impl<'a> Sheet<'a> {
}
Err(_) => {
// Error checking rights, don't allow modifying the mapping
- Err(std::io::Error::new(
- std::io::ErrorKind::Other,
+ Err(std::io::Error::other(
"Failed to check virtual file edit rights",
))
}
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;
+ }
}