Skip to main content

ShurikenManager

Struct ShurikenManager 

Source
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 scripts
  • shurikens: Cached map of loaded Shurikens by name
  • config: 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

Source

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 success
  • Err if home directory cannot be found or initialization fails
§Panics

None - all errors are returned as Results

Source

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 successfully
  • Err if Shuriken not found, script execution fails, or startup errors occur
Source

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 success
  • Err if file system operations fail
Source

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 successfully
  • Err if Shuriken not found or configuration fails
Source

pub async fn lockpick(&self, name: &str) -> Result<()>

Removes the lock file for a Shuriken.

Forces the Shuriken to be considered “not running” by removing its lock file. Useful for recovering from crashed processes.

§Arguments
  • name: The name of the Shuriken
§Returns
  • Ok(()) if lock file successfully removed or didn’t exist
  • Err if operation fails
Source

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 Shuriken
  • data: Configuration key-value pairs to save
§Returns
  • Ok(()) if configuration saved successfully
  • Err if file operations fail
Source

pub async fn stop(&self, name: &str) -> Result<()>

Stops a running Shuriken.

Executes the Shuriken’s stop script and halts the service. Updates the Shuriken’s state to Idle on success.

§Arguments
  • name: The name of the Shuriken to stop
§Returns
  • Ok(()) if stop completed successfully
  • Err if Shuriken not found or stop script fails
Source

pub async fn get(&self, name: String) -> Result<Shuriken>

Retrieves a Shuriken by name.

§Arguments
  • name: The name of the Shuriken to retrieve
§Returns
  • Ok(Shuriken) if found
  • Err if Shuriken not found
Source

pub async fn list( &self, state: bool, ) -> Result<Either<Vec<(String, ShurikenState)>, Vec<String>>>

Lists all available Shurikens.

§Arguments
  • state: If true, returns names with their current state; if false, returns only names
§Returns
  • Ok(Left(vec)) with state information if state is true
  • Ok(Right(vec)) with just names if state is false
  • Err if operation fails
Source

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

Source

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 Shuriken
  • path: Path to the Shuriken directory to package
  • output: Optional output directory (defaults to ~/.ninja/blacksmith)
§Returns
  • Ok(()) if packaging succeeded
  • Err if metadata is too large, archive creation fails, or I/O fails
Source

pub async fn remove(&self, name: &str) -> Result<()>

Removes a Shuriken from the system.

Deletes the Shuriken directory and removes it from the cache.

§Arguments
  • name: The name of the Shuriken to remove
§Returns
  • Ok(()) if removal succeeded
  • Err if Shuriken not found or deletion fails
Source

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 success
  • Err if engine initialization fails
Source

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 completed
  • Err if source is invalid or installation fails
Source

pub async fn install_url(&self, url: &str) -> Result<()>

Installs a Shuriken from a direct URL.

Downloads the .shuriken file and installs it.

§Arguments
  • url: The download URL for the .shuriken file
§Returns
  • Ok(()) if installation succeeded
  • Err if download or installation fails
Source

pub async fn install_from_registry( &self, reference: &ShurikenReference, ) -> Result<()>

Install a shuriken from a registry reference (e.g., “my-registry:my-shuriken”)

Source

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 succeeded
  • Err if 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)
Source

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

Source

pub async fn registry_get_shuriken(&self, name: String) -> Option<ArmoryItem>

Fetches a specific Shuriken from any configured registry.

§Arguments
  • name: The name of the Shuriken to fetch
§Returns
  • Some(ArmoryItem) if found in a registry
  • None if not found
Source

pub async fn get_projects(&self) -> Result<Vec<String>>

Lists all projects in the projects directory.

§Returns
  • Ok(Vec<String>) with project names
  • Err if directory access fails

Trait Implementations§

Source§

impl Clone for ShurikenManager

Source§

fn clone(&self) -> ShurikenManager

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShurikenManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,