pub struct ShurikenManager {
pub root_path: PathBuf,
pub engine: Arc<Mutex<NinjaEngine>>,
pub shurikens: Arc<RwLock<HashMap<String, Shuriken>>>,
pub config: Arc<RwLock<NinjaConfig>>,
}Expand description
A thin wrapper around a spawned process. We keep it simple: the
ManagedProcess owns a tokio::process::Child and provides async helpers.
The main orchestrator for managing Shurikens and their lifecycle.
ShurikenManager handles all operations related to Shuriken services,
including startup, configuration, installation, and lifecycle management.
It maintains the scripting engine, configuration, and in-memory state.
§Fields
root_path: Base directory where Ninja stores data (~/.ninja)engine: Lua scripting engine for executing Shuriken scriptsshurikens: Cached map of loaded Shurikens by nameconfig: Global Ninja configuration including registries
Fields§
§root_path: PathBuf§engine: Arc<Mutex<NinjaEngine>>§shurikens: Arc<RwLock<HashMap<String, Shuriken>>>§config: Arc<RwLock<NinjaConfig>>Implementations§
Source§impl ShurikenManager
impl ShurikenManager
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Creates a new ShurikenManager instance.
Initializes the Ninja directory structure (~/.ninja), loads existing Shurikens, creates a Lua scripting engine, and loads or generates the global configuration.
§Returns
Ok(ShurikenManager)on successErrif home directory cannot be found or initialization fails
§Panics
None - all errors are returned as Results
Sourcepub async fn start(&self, name: &str) -> Result<()>
pub async fn start(&self, name: &str) -> Result<()>
Starts a Shuriken by name.
Executes the Shuriken’s startup script and begins running the service.
Updates the Shuriken’s state to Running on success.
§Arguments
name: The name of the Shuriken to start
§Returns
Ok(())if startup completed successfullyErrif Shuriken not found, script execution fails, or startup errors occur
Sourcepub async fn refresh(&self) -> Result<()>
pub async fn refresh(&self) -> Result<()>
Reloads all Shurikens from disk.
Rescans the ~/.ninja/shurikens directory and updates the in-memory cache. Useful after manual file changes or to get latest state from disk.
§Returns
Ok(())on successErrif file system operations fail
Sourcepub async fn configure(&self, name: &str) -> Result<()>
pub async fn configure(&self, name: &str) -> Result<()>
Configures a Shuriken using its configuration script.
Executes the Shuriken’s post_config function to apply configuration settings.
Configuration values are templated and written to the Shuriken’s config file.
§Arguments
name: The name of the Shuriken to configure
§Returns
Ok(())if configuration completed successfullyErrif Shuriken not found or configuration fails
Sourcepub async fn save_config(
&self,
name: &str,
data: HashMap<String, FieldValue>,
) -> Result<()>
pub async fn save_config( &self, name: &str, data: HashMap<String, FieldValue>, ) -> Result<()>
Saves configuration options for a Shuriken.
Persists configuration to disk as TOML and updates the in-memory cache. Creates necessary directories if they don’t exist.
§Arguments
name: The name of the Shurikendata: Configuration key-value pairs to save
§Returns
Ok(())if configuration saved successfullyErrif file operations fail
Sourcepub async fn list(
&self,
state: bool,
) -> Result<Either<Vec<(String, ShurikenState)>, Vec<String>>>
pub async fn list( &self, state: bool, ) -> Result<Either<Vec<(String, ShurikenState)>, Vec<String>>>
Sourcepub fn dsl_ctx(&self) -> DslContext
pub fn dsl_ctx(&self) -> DslContext
Creates a new DSL context for script execution.
§Returns
A DslContext that can be used to interpret Ninja DSL commands
Sourcepub async fn forge(
&self,
meta: ArmoryMetadata,
path: PathBuf,
output: Option<PathBuf>,
) -> Result<()>
pub async fn forge( &self, meta: ArmoryMetadata, path: PathBuf, output: Option<PathBuf>, ) -> Result<()>
Packages a Shuriken into a distributable .shuriken file.
Creates a signed archive containing metadata, the Shuriken directory, and SHA256 checksum. Format: MAGIC + metadata_length + metadata + archive_length + archive + signature
§Arguments
meta: Metadata for the packaged Shurikenpath: Path to the Shuriken directory to packageoutput: Optional output directory (defaults to ~/.ninja/blacksmith)
§Returns
Ok(())if packaging succeededErrif metadata is too large, archive creation fails, or I/O fails
Sourcepub async fn reset_engine(&self) -> Result<()>
pub async fn reset_engine(&self) -> Result<()>
Resets and reinitializes the Lua scripting engine.
Useful when you need to clear engine state between operations. Creates a new engine instance with all modules.
§Returns
Ok(())on successErrif engine initialization fails
Sourcepub async fn install(&self, name: &str) -> Result<()>
pub async fn install(&self, name: &str) -> Result<()>
Installs a Shuriken from various sources.
Automatically detects the source type and installs accordingly:
- Registry reference (e.g., “registry:shuriken”)
- Direct URL
- Local file path
§Arguments
name: The Shuriken source (reference, URL, or file path)
§Returns
Ok(())if installation completedErrif source is invalid or installation fails
Sourcepub async fn install_url(&self, url: &str) -> Result<()>
pub async fn install_url(&self, url: &str) -> Result<()>
Sourcepub async fn install_from_registry(
&self,
reference: &ShurikenReference,
) -> Result<()>
pub async fn install_from_registry( &self, reference: &ShurikenReference, ) -> Result<()>
Install a shuriken from a registry reference (e.g., “my-registry:my-shuriken”)
Sourcepub async fn install_file(&self, path: &Path) -> Result<(), Error>
pub async fn install_file(&self, path: &Path) -> Result<(), Error>
Installs a Shuriken from a local file.
Validates the .shuriken file format (magic bytes, metadata, checksum), extracts the archive, verifies platform compatibility, and runs postinstall hooks.
§Arguments
path: Path to the .shuriken file
§Returns
Ok(())if installation succeededErrif file is invalid, corrupted, incompatible, or extraction fails
§File Format
- MAGIC (6 bytes): “HSRZEG”
- metadata_length (u16 LE)
- metadata (CBOR encoded)
- archive_length (u32 LE)
- archive (tar.gz)
- signature (32 bytes SHA256)
Sourcepub async fn registry_get_all_shurikens(&self) -> Vec<ArmoryItem>
pub async fn registry_get_all_shurikens(&self) -> Vec<ArmoryItem>
Fetches all available Shurikens from all configured registries.
§Returns
A vector of ArmoryItem entries from all registries
Sourcepub async fn registry_get_shuriken(&self, name: String) -> Option<ArmoryItem>
pub async fn registry_get_shuriken(&self, name: String) -> Option<ArmoryItem>
Trait Implementations§
Source§impl Clone for ShurikenManager
impl Clone for ShurikenManager
Source§fn clone(&self) -> ShurikenManager
fn clone(&self) -> ShurikenManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ShurikenManager
impl !RefUnwindSafe for ShurikenManager
impl Send for ShurikenManager
impl Sync for ShurikenManager
impl Unpin for ShurikenManager
impl UnsafeUnpin for ShurikenManager
impl !UnwindSafe for ShurikenManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more