mirror of
https://github.com/kristoferssolo/captra.git
synced 2025-12-20 11:04:39 +00:00
feat: add manifest skelet
This commit is contained in:
parent
8a644f3ef7
commit
ed55cda68e
12
Cargo.toml
12
Cargo.toml
@ -10,3 +10,15 @@ keywords = ["wasm", "sandbox", "capabilities", "plugins", "traces"]
|
|||||||
categories = ["cryptography::randomness", "encoding"]
|
categories = ["cryptography::randomness", "encoding"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
color-eyre = "0.6"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
claims = "0.8"
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
pedantic = "warn"
|
||||||
|
nursery = "warn"
|
||||||
|
unwrap_used = "warn"
|
||||||
|
expect_used = "warn"
|
||||||
|
|||||||
13
examples/manifest.json
Normal file
13
examples/manifest.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"plugin": "formatter-v1",
|
||||||
|
"version": "0.1",
|
||||||
|
"capabilities": {
|
||||||
|
"fs": {
|
||||||
|
"read": [
|
||||||
|
"./workspace/*"
|
||||||
|
],
|
||||||
|
"write": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"issued_by": "dev-team"
|
||||||
|
}
|
||||||
51
src/lib.rs
51
src/lib.rs
@ -1,14 +1,55 @@
|
|||||||
pub fn add(left: u64, right: u64) -> u64 {
|
use std::fs::read_to_string;
|
||||||
left + right
|
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct FsCapability {
|
||||||
|
pub read: Vec<String>, // Glob patter for read
|
||||||
|
pub write: Vec<String>, // Stub for now
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub enum Capability {
|
||||||
|
Fs(FsCapability),
|
||||||
|
// TODO: add Net, Cpu
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Capabilities {
|
||||||
|
pub fs: Option<FsCapability>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct CapabilityManifest {
|
||||||
|
pub plugin: String,
|
||||||
|
pub version: String,
|
||||||
|
pub capabilities: Capabilities,
|
||||||
|
pub issued_by: String,
|
||||||
|
// TODO: add signature
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_manifest(path: &str) -> Result<CapabilityManifest> {
|
||||||
|
let json_str = read_to_string(path)?;
|
||||||
|
let manifest = serde_json::from_str(&json_str)?;
|
||||||
|
Ok(manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use claims::assert_some;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn manifest_loader() {
|
||||||
let result = add(2, 2);
|
let manifest = load_manifest("examples/manifest.json").expect("Load failed");
|
||||||
assert_eq!(result, 4);
|
assert_eq!(manifest.plugin, "formatter-v1");
|
||||||
|
assert_eq!(manifest.version, "0.1");
|
||||||
|
assert_eq!(manifest.issued_by, "dev-team");
|
||||||
|
|
||||||
|
let caps = manifest.capabilities;
|
||||||
|
let fs_cap = assert_some!(caps.fs);
|
||||||
|
assert_eq!(fs_cap.read, vec!["./workspace/*"]);
|
||||||
|
assert!(fs_cap.write.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user