feat: add grpc support

This commit is contained in:
a.tolmachev
2026-03-25 21:23:57 +03:00
parent ada2436e54
commit 8005510ad2
33 changed files with 1725 additions and 32 deletions
+44 -2
View File
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use mcpaas_core::{OperationId, SampleId};
use mcpaas_registry::SampleKind;
use mcpaas_core::{DescriptorId, OperationId, SampleId};
use mcpaas_registry::{DescriptorKind, SampleKind};
use serde_json::Value;
use thiserror::Error;
use tokio::fs;
@@ -57,6 +57,39 @@ impl LocalArtifactStorage {
Ok(serde_json::from_slice(&bytes)?)
}
pub async fn write_descriptor(
&self,
operation_id: &OperationId,
version: u32,
descriptor_kind: DescriptorKind,
descriptor_id: &DescriptorId,
source_name: Option<&str>,
payload: &[u8],
) -> Result<String, StorageError> {
let file_name = match descriptor_kind {
DescriptorKind::ProtoUpload => source_name.unwrap_or("schema.proto").to_owned(),
DescriptorKind::DescriptorSet => source_name.unwrap_or("descriptor-set.bin").to_owned(),
DescriptorKind::ReflectionSnapshot => {
source_name.unwrap_or("reflection.bin").to_owned()
}
};
let path = self
.root
.join("descriptors")
.join(operation_id.as_str())
.join(format!("v{version}"))
.join(format!("{}_{}", descriptor_id.as_str(), file_name));
write_bytes(&path, payload).await?;
Ok(to_storage_ref(&path))
}
pub async fn read_bytes(&self, storage_ref: &str) -> Result<Vec<u8>, StorageError> {
let path = from_storage_ref(storage_ref)?;
Ok(fs::read(path).await?)
}
}
async fn write_json_file(path: &Path, payload: &Value) -> Result<(), StorageError> {
@@ -69,6 +102,15 @@ async fn write_json_file(path: &Path, payload: &Value) -> Result<(), StorageErro
Ok(())
}
async fn write_bytes(path: &Path, payload: &[u8]) -> Result<(), StorageError> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).await?;
}
fs::write(path, payload).await?;
Ok(())
}
fn to_storage_ref(path: &Path) -> String {
format!("file://{}", path.display())
}