Crate wasmcloud_host[][src]

wasmCloud Host

wasmCloud is a secure, distributed actor platform with an autonomous mesh network built for bridging disparate and far-flung infrastructure.

By default a wasmCloud host will start in offline mode and only allow “local” scheduling of actors and capabilities. If you choose to opt-in to the lattice, you can use NATS as a message broker to provide the infrastructure for wasmCloud’s self-forming, self-healing network. If you then want even more power, you can choose to override the capability provider used for managing the shared state within a lattice.

Local development on your workstation is easy and simple by default, and you should only incur additional complexity as you move toward resilient, distributed production environments.

To start a runtime, simply add actors and capabilities to the host. For more information, take a look at the documentation and tutorials at wasmcloud.dev.

Example

The following example creates a new wasmCloud host in the default standalone (no lattice) mode. It then loads an actor that simply echoes back incoming HTTP requests as outbound HTTP responses. The HTTP server capability provider is loaded so that the actor can receive web requests. Note that the link definition (configuration of the link between the actor and the capability provider) can be defined in any order. The host runtime automatically establishes links as soon as all related parties are up and running inside a host or a lattice.

use wasmcloud_host::{HostBuilder, Actor, NativeCapability};
use std::collections::HashMap;
use std::error::Error;
use std::time::Duration;
use actix_rt::time::sleep;
use reqwest;

const WEB_PORT: u32 = 8080;

#[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error + Sync +Send>> {
    let h = HostBuilder::new().build();
    h.start().await?;
    let echo = Actor::from_file("../../tests/modules/echo.wasm")?;
    let actor_id = echo.public_key();
    h.start_actor(echo).await?;

    // Read a cross-platform provider archive file
    let arc = par_from_file("../../tests/modules/httpserver.par.gz")?;
    let websrv = NativeCapability::from_archive(&arc, None)?;
    let websrv_id = websrv.id();

    let mut webvalues: HashMap<String, String> = HashMap::new();
    webvalues.insert("PORT".to_string(), format!("{}", WEB_PORT));
    // Establish a link between the actor and a capability provider
    h.set_link(
        &actor_id,
        "wasmcloud:httpserver",
        None,
        websrv_id,
        webvalues,
    )
    .await?;
    // Start the web server provider (which auto-establishes the link)
    h.start_native_capability(websrv).await?;
    // Let the web server start
    sleep(Duration::from_millis(500)).await;
    let url = format!("http://localhost:{}/demo?test=kthxbye", WEB_PORT);

    let resp = reqwest::get(&url).await?;
    assert!(resp.status().is_success());
    let v: serde_json::Value = serde_json::from_slice(&resp.bytes().await?)?;
    assert_eq!("test=kthxbye", v["query_string"].as_str().unwrap());

    Ok(())
}

Structs

Host

A wasmCloud Host is a secure runtime container responsible for scheduling actors and capability providers, configuring the links between them, and facilitating secure function call dispatch between actors and capabilities.

HostBuilder

A host builder provides a convenient, fluid syntax for setting initial configuration and tuning parameters for a wasmCloud host

HostManifest

A host manifest contains a descriptive profile of the host’s desired state, including a list of actors and capability providers to load as well as any desired link definitions

NativeCapability

Represents a native capability provider compiled as a shared object library. These plugins are OS- and architecture-specific, so they will be .so files on Linux, .dylib files on macOS, etc.

WasmCloudActor

An actor is a WebAssembly module that conforms to the wasmCloud protocols and can securely consume capabilities exposed by native or portable capability providers

Traits

Authorizer

An authorizer is responsible for determining whether an actor can be loaded as well as whether an actor can invoke another entity. For invocation checks, the authorizer is only ever invoked after an initial capability attestation check has been performed and passed. This has the net effect of making it impossible to override the base behavior of checking that an actor’s embedded JWT contains the right capability attestations.

Type Definitions

Actor

Type alias used to disambiguate between wasmCloud actors and Actix actors

Result

Result type used for function calls within this library