fn wascc_run(
    host: Arc<Mutex<WasccHost>>,
    data: Vec<u8>,
    mut env: EnvVars,
    volumes: Vec<VolumeBinding>,
    log_path: &Path,
    port_assigned: u16,
) -> anyhow::Result<ContainerHandle<ActorHandle, LogHandleFactory>> {
    let mut capabilities: Vec<Capability> = Vec::new();
    info!("sending actor to wascc host");
    let log_output = NamedTempFile::new_in(log_path)?;
    let mut logenv: HashMap<String, String> = HashMap::new();
    logenv.insert(
        LOG_PATH_KEY.to_string(),
        log_output.path().to_str().unwrap().to_owned(),
    );

    let load = Actor::from_bytes(data).map_err(|e| anyhow::anyhow!("Error loading WASM: {}", e))?;
    let pk = load.public_key();

    let actor_caps = load.capabilities();

    if actor_caps.contains(&LOG_CAPABILITY.to_owned()) {
        capabilities.push(Capability {
            name: LOG_CAPABILITY,
            binding: None,
            env: logenv,
        });
    }

    if actor_caps.contains(&HTTP_CAPABILITY.to_owned()) {
        env.insert("PORT".to_string(), port_assigned.to_string());
        capabilities.push(Capability {
            name: HTTP_CAPABILITY,
            binding: None,
            env,
        });
    }

    if actor_caps.contains(&FS_CAPABILITY.to_owned()) {
        for vol in &volumes {
            info!(
                "Loading File System capability for volume name: '{}' host_path: '{}'",
                vol.name,
                vol.host_path.display()
            );
            let mut fsenv: HashMap<String, String> = HashMap::new();
            fsenv.insert(
                FS_CONFIG_ROOTDIR.to_owned(),
                vol.host_path.as_path().to_str().unwrap().to_owned(),
            );
            let fs_provider = FileSystemProvider::new();
            let fs_capability =
                NativeCapability::from_instance(fs_provider, Some(vol.name.clone())).map_err(
                    |e| anyhow::anyhow!("Failed to instantiate File System capability: {}", e),
                )?;
            host.lock()
                .unwrap()
                .add_native_capability(fs_capability)
                .map_err(|e| anyhow::anyhow!("Failed to add File System capability: {}", e))?;
            capabilities.push(Capability {
                name: FS_CAPABILITY,
                binding: Some(vol.name.clone()),
                env: fsenv,
            });
        }
    }

    host.lock()
        .unwrap()
        .add_actor(load)
        .map_err(|e| anyhow::anyhow!("Error adding actor: {}", e))?;
    capabilities.iter().try_for_each(|cap| {
        info!("configuring capability {}", cap.name);
        host.lock()
            .unwrap()
            .bind_actor(&pk, cap.name, cap.binding.clone(), cap.env.clone())
            .map_err(|e| anyhow::anyhow!("Error configuring capabilities for module: {}", e))
    })?;

    let log_handle_factory = LogHandleFactory { temp: log_output };

    info!("wascc actor executing");
    Ok(ContainerHandle::new(
        ActorHandle {
            host,
            key: pk,
            volumes,
        },
        log_handle_factory,
    ))
}
/// Run the given WASM data as a waSCC actor with the given public key.
///
/// The provided capabilities will be configured for this actor, but the capabilities
/// must first be loaded into the host by some other process, such as register_native_capabilities().
Run the given WASM data as a waSCC actor with the given public key.
The provided capabilities will be configured for this actor, but the capabilities
must first be loaded into the host by some other process, such as register_native_capabilities().
Run the given WASM data as a waSCC actor with the given public key . The provided capabilities will be configured for this actor but the capabilities must first be loaded into the host by some other process such as register_native_capabilities () .
fn wascc_run(
    host: Arc<Mutex<WasccHost>>,
    data: Vec<u8>,
    mut env: EnvVars,
    volumes: Vec<VolumeBinding>,
    log_path: &Path,
    port_assigned: u16,
) -> anyhow::Result<ContainerHandle<ActorHandle, LogHandleFactory>> {
    let mut capabilities: Vec<Capability> = Vec::new();
    info!("sending actor to wascc host");
    let log_output = NamedTempFile::new_in(log_path)?;
    let mut logenv: HashMap<String, String> = HashMap::new();
    logenv.insert(
        LOG_PATH_KEY.to_string(),
        log_output.path().to_str().unwrap().to_owned(),
    );
    let load = Actor::from_bytes(data).map_err(|e| anyhow::anyhow!("Error loading WASM: {}", e))?;
    let pk = load.public_key();
    let actor_caps = load.capabilities();
    if actor_caps.contains(&LOG_CAPABILITY.to_owned()) {
        capabilities.push(Capability {
            name: LOG_CAPABILITY,
            binding: None,
            env: logenv,
        });
    }
    if actor_caps.contains(&HTTP_CAPABILITY.to_owned()) {
        env.insert("PORT".to_string(), port_assigned.to_string());
        capabilities.push(Capability {
            name: HTTP_CAPABILITY,
            binding: None,
            env,
        });
    }
    if actor_caps.contains(&FS_CAPABILITY.to_owned()) {
        for vol in &volumes {
            info!(
                "Loading File System capability for volume name: '{}' host_path: '{}'",
                vol.name,
                vol.host_path.display()
            );
            let mut fsenv: HashMap<String, String> = HashMap::new();
            fsenv.insert(
                FS_CONFIG_ROOTDIR.to_owned(),
                vol.host_path.as_path().to_str().unwrap().to_owned(),
            );
            let fs_provider = FileSystemProvider::new();
            let fs_capability =
                NativeCapability::from_instance(fs_provider, Some(vol.name.clone())).map_err(
                    |e| anyhow::anyhow!("Failed to instantiate File System capability: {}", e),
                )?;
            host.lock()
                .unwrap()
                .add_native_capability(fs_capability)
                .map_err(|e| anyhow::anyhow!("Failed to add File System capability: {}", e))?;
            capabilities.push(Capability {
                name: FS_CAPABILITY,
                binding: Some(vol.name.clone()),
                env: fsenv,
            });
        }
    }
    host.lock()
        .unwrap()
        .add_actor(load)
        .map_err(|e| anyhow::anyhow!("Error adding actor: {}", e))?;
    capabilities.iter().try_for_each(|cap| {
        info!("configuring capability {}", cap.name);
        host.lock()
            .unwrap()
            .bind_actor(&pk, cap.name, cap.binding.clone(), cap.env.clone())
            .map_err(|e| anyhow::anyhow!("Error configuring capabilities for module: {}", e))
    })?;
    let log_handle_factory = LogHandleFactory { temp: log_output };
    info!("wascc actor executing");
    Ok(ContainerHandle::new(
        ActorHandle {
            host,
            key: pk,
            volumes,
        },
        log_handle_factory,
    ))
}
fn wascc_run ( host : Arc < Mutex < WasccHost > > , data : Vec < u8 > , mut env : EnvVars , volumes : Vec < VolumeBinding > , log_path : & Path , port_assigned : u16 , ) -> anyhow :: Result < ContainerHandle < ActorHandle , LogHandleFactory > > { let mut capabilities : Vec < Capability > = Vec :: new ( ) ; info ! ( " " ) ; let log_output = NamedTempFile :: new_in ( log_path ) ? ; let mut logenv : HashMap < String , String > = HashMap :: new ( ) ; logenv . insert ( LOG_PATH_KEY . to_string ( ) , log_output . path ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) , ) ; let load = Actor :: from_bytes ( data ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; let pk = load . public_key ( ) ; let actor_caps = load . capabilities ( ) ; if actor_caps . contains ( & LOG_CAPABILITY . to_owned ( ) ) { capabilities . push ( Capability { name : LOG_CAPABILITY , binding : None , env : logenv , } ) ; } if actor_caps . contains ( & HTTP_CAPABILITY . to_owned ( ) ) { env . insert ( " " . to_string ( ) , port_assigned . to_string ( ) ) ; capabilities . push ( Capability { name : HTTP_CAPABILITY , binding : None , env , } ) ; } if actor_caps . contains ( & FS_CAPABILITY . to_owned ( ) ) { for vol in & volumes { info ! ( " " vol name vol host_path display ( ) ) ; let mut fsenv : HashMap < String , String > = HashMap :: new ( ) ; fsenv . insert ( FS_CONFIG_ROOTDIR . to_owned ( ) , vol . host_path . as_path ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) , ) ; let fs_provider = FileSystemProvider :: new ( ) ; let fs_capability = NativeCapability :: from_instance ( fs_provider , Some ( vol . name . clone ( ) ) ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) , ) ? ; host . lock ( ) . unwrap ( ) . add_native_capability ( fs_capability ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; capabilities . push ( Capability { name : FS_CAPABILITY , binding : Some ( vol . name . clone ( ) ) , env : fsenv , } ) ; } } host . lock ( ) . unwrap ( ) . add_actor ( load ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) ? ; capabilities . iter ( ) . try_for_each ( | cap | { info ! ( " " cap name ) ; host . lock ( ) . unwrap ( ) . bind_actor ( & pk , cap . name , cap . binding . clone ( ) , cap . env . clone ( ) ) . map_err ( | e | anyhow :: anyhow ! ( " " e ) ) } ) ? ; let log_handle_factory = LogHandleFactory { temp : log_output } ; info ! ( " " ) ; Ok ( ContainerHandle :: new ( ActorHandle { host , key : pk , volumes , } , log_handle_factory , ) ) }
Run the given WASM data as a waSCC actor with the given public key.
Run the given WASM data as a waSCC actor with the given public key .
host
Arc<Mutex<WasccHost>>
data
Vec<u8>
env
EnvVars
volumes
Vec<VolumeBinding>
log_path
&Path
port_assigned
u16
host
Arc<Mutex<WasccHost>>
data
Vec<u8>
env
EnvVars
volumes
Vec<VolumeBinding>
log_path
&Path
port_assigned
u16