Add local document resource commands
This commit is contained in:
parent
527090fd4c
commit
ce260625d6
14 changed files with 277 additions and 14 deletions
|
|
@ -16,6 +16,7 @@ geth-config = { path = "../geth-config" }
|
|||
geth-control = { path = "../geth-control" }
|
||||
geth-crypto = { path = "../geth-crypto" }
|
||||
geth-db = { path = "../geth-db" }
|
||||
geth-document = { path = "../geth-document" }
|
||||
geth-iroh = { path = "../geth-iroh" }
|
||||
geth-keychain = { path = "../geth-keychain" }
|
||||
geth-kv = { path = "../geth-kv" }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use geth_control::{
|
|||
};
|
||||
use geth_crypto::AgentKey;
|
||||
use geth_db::DbResource;
|
||||
use geth_document::DocumentResource;
|
||||
use geth_iroh::{EndpointStatus, GethIrohConfig, GethIrohEndpoint, GethRelayMode};
|
||||
use geth_keychain::{KeychainOp, KeychainOpKind};
|
||||
use geth_kv::{KvEntry, KvResource};
|
||||
|
|
@ -19,8 +20,8 @@ use geth_ssh_identity::{
|
|||
certificate_id, revocation_id, ssh_public_key_fingerprint,
|
||||
};
|
||||
use geth_store::{
|
||||
Store, StoredAuthOp, StoredDbResource, StoredKeychainOp, StoredKvEntry, StoredKvStore,
|
||||
StoredResource, StoredSshCertRequest, StoredSshCertificate, StoredSshRevocation,
|
||||
Store, StoredAuthOp, StoredDbResource, StoredDocumentResource, StoredKeychainOp, StoredKvEntry,
|
||||
StoredKvStore, StoredResource, StoredSshCertRequest, StoredSshCertificate, StoredSshRevocation,
|
||||
};
|
||||
use geth_types::{
|
||||
AuthOpId, Capability, KeyId, NodeId, PrincipalId, ResourceId, ResourceKind, ResourceName,
|
||||
|
|
@ -62,6 +63,10 @@ pub enum NodeError {
|
|||
InvalidKvKey(String),
|
||||
#[error("kv store not found: {0}")]
|
||||
KvNotFound(String),
|
||||
#[error("invalid document name: {0}")]
|
||||
InvalidDocumentName(String),
|
||||
#[error("document not found: {0}")]
|
||||
DocumentNotFound(String),
|
||||
#[error("invalid ssh certificate kind: {0}")]
|
||||
InvalidSshCertKind(String),
|
||||
#[error("invalid ssh certificate request status: {0}")]
|
||||
|
|
@ -651,6 +656,40 @@ pub fn handle_request(
|
|||
.map(kv_entry_from_stored);
|
||||
Ok(ControlResponse::KvGet { entry })
|
||||
}
|
||||
ControlRequest::DocumentCreate { name } => {
|
||||
geth_document::validate_document_name(&name)
|
||||
.map_err(|_| NodeError::InvalidDocumentName(name.clone()))?;
|
||||
let resource_id = format!("resource:document:{name}");
|
||||
let document_id = format!("document:{name}");
|
||||
let resource = StoredResource {
|
||||
resource_id: resource_id.clone(),
|
||||
kind: ResourceKind::Document.to_string(),
|
||||
name: name.clone(),
|
||||
status: "active".to_owned(),
|
||||
};
|
||||
store.insert_resource(&resource)?;
|
||||
let stored = StoredDocumentResource {
|
||||
document_id,
|
||||
resource_id,
|
||||
name,
|
||||
state_json: "{}".to_owned(),
|
||||
updated_at_ms: geth_store::now_ms(),
|
||||
};
|
||||
store.insert_document_resource(&stored)?;
|
||||
Ok(ControlResponse::DocumentCreated {
|
||||
document: document_resource_from_stored(&stored),
|
||||
})
|
||||
}
|
||||
ControlRequest::DocumentStatus { name } => {
|
||||
geth_document::validate_document_name(&name)
|
||||
.map_err(|_| NodeError::InvalidDocumentName(name.clone()))?;
|
||||
let stored = store
|
||||
.get_document_resource_by_name(&name)?
|
||||
.ok_or_else(|| NodeError::DocumentNotFound(name.clone()))?;
|
||||
Ok(ControlResponse::DocumentStatus {
|
||||
document: document_resource_from_stored(&stored),
|
||||
})
|
||||
}
|
||||
ControlRequest::ModuleStub { module, command } => {
|
||||
Ok(ControlResponse::NotImplemented { module, command })
|
||||
}
|
||||
|
|
@ -715,6 +754,16 @@ fn kv_entry_from_stored(stored: StoredKvEntry) -> KvEntry {
|
|||
}
|
||||
}
|
||||
|
||||
fn document_resource_from_stored(stored: &StoredDocumentResource) -> DocumentResource {
|
||||
DocumentResource {
|
||||
id: stored.document_id.clone().into(),
|
||||
resource: stored.resource_id.clone().into(),
|
||||
name: stored.name.clone(),
|
||||
sync_status: "local-only".to_owned(),
|
||||
state_bytes: stored.state_json.len() as u64,
|
||||
}
|
||||
}
|
||||
|
||||
fn store_auth_op(store: &Store, op: &AuthOp) -> Result<(), NodeError> {
|
||||
store.insert_auth_op(&StoredAuthOp {
|
||||
op_id: op.id.to_string(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue