wasmcloud_host/wasmbus/
host_config.rs

1use crate::OciConfig;
2
3use core::net::SocketAddr;
4
5use std::collections::HashMap;
6use std::sync::Arc;
7use std::time::Duration;
8
9use nkeys::KeyPair;
10use url::Url;
11use wasmcloud_core::{logging::Level as LogLevel, OtelConfig};
12use wasmcloud_runtime::{
13    DEFAULT_MAX_CORE_INSTANCES_PER_COMPONENT, MAX_COMPONENTS, MAX_COMPONENT_SIZE, MAX_LINEAR_MEMORY,
14};
15
16use crate::wasmbus::experimental::Features;
17
18/// wasmCloud Host configuration
19#[allow(clippy::struct_excessive_bools)]
20#[derive(Clone, Debug)]
21pub struct Host {
22    /// NATS URL to connect to for component RPC
23    pub rpc_nats_url: Url,
24    /// Timeout period for all RPC calls
25    pub rpc_timeout: Duration,
26    /// Authentication JWT for RPC connection, must be specified with `rpc_seed`
27    pub rpc_jwt: Option<String>,
28    /// Authentication key pair for RPC connection, must be specified with `rpc_jwt`
29    pub rpc_key: Option<Arc<KeyPair>>,
30    /// Whether to require TLS for RPC connection
31    pub rpc_tls: bool,
32    /// The lattice the host belongs to
33    pub lattice: Arc<str>,
34    /// The domain to use for host Jetstream operations
35    pub js_domain: Option<String>,
36    /// Labels (key-value pairs) to add to the host
37    pub labels: HashMap<String, String>,
38    /// The server key pair used by this host to generate its public key
39    pub host_key: Arc<KeyPair>,
40    /// The amount of time to wait for a provider to gracefully shut down before terminating it
41    pub provider_shutdown_delay: Option<Duration>,
42    /// Configuration for downloading artifacts from OCI registries
43    pub oci_opts: OciConfig,
44    /// Whether to allow loading component or provider components from the filesystem
45    pub allow_file_load: bool,
46    /// Whether or not structured logging is enabled
47    pub enable_structured_logging: bool,
48    /// Log level to pass to capability providers to use. Should be parsed from a [`tracing::Level`]
49    pub log_level: LogLevel,
50    /// Whether to enable loading supplemental configuration
51    pub config_service_enabled: bool,
52    /// configuration for OpenTelemetry tracing
53    pub otel_config: OtelConfig,
54    /// The semver version of the host. This is used by a consumer of this crate to indicate the
55    /// host version (which may differ from the crate version)
56    pub version: String,
57    /// The maximum execution time for a component instance
58    pub max_execution_time: Duration,
59    /// The maximum linear memory that a component instance can allocate
60    pub max_linear_memory: u32,
61    /// The maximum size of a component binary that can be loaded
62    pub max_component_size: u64,
63    /// The maximum number of components that can be run simultaneously
64    pub max_components: u32,
65    /// The maximum number of core instances that are allowed in a given component
66    pub max_core_instances_per_component: u32,
67    /// The interval at which the Host will send heartbeats
68    pub heartbeat_interval: Option<Duration>,
69    /// Experimental features that can be enabled in the host
70    pub experimental_features: Features,
71    /// HTTP administration endpoint address
72    pub http_admin: Option<SocketAddr>,
73    /// Whether component auctions are enabled
74    pub enable_component_auction: bool,
75    /// Whether capability provider auctions are enabled
76    pub enable_provider_auction: bool,
77}
78
79/// Configuration for wasmCloud policy service
80#[derive(Clone, Debug, Default)]
81pub struct PolicyService {
82    /// The topic to request policy decisions on
83    pub policy_topic: Option<String>,
84    /// An optional topic to receive updated policy decisions on
85    pub policy_changes_topic: Option<String>,
86    /// The timeout for policy requests
87    pub policy_timeout_ms: Option<Duration>,
88}
89
90impl Default for Host {
91    fn default() -> Self {
92        Self {
93            rpc_nats_url: Url::parse("nats://localhost:4222")
94                .expect("failed to parse RPC NATS URL"),
95            rpc_timeout: Duration::from_millis(2000),
96            rpc_jwt: None,
97            rpc_key: None,
98            rpc_tls: false,
99            lattice: "default".into(),
100            js_domain: None,
101            labels: HashMap::default(),
102            host_key: Arc::new(KeyPair::new_server()),
103            provider_shutdown_delay: None,
104            oci_opts: OciConfig::default(),
105            allow_file_load: false,
106            enable_structured_logging: false,
107            log_level: LogLevel::Info,
108            config_service_enabled: false,
109            otel_config: OtelConfig::default(),
110            version: env!("CARGO_PKG_VERSION").to_string(),
111            max_execution_time: Duration::from_millis(10 * 60 * 1000),
112            // 10 MB
113            max_linear_memory: MAX_LINEAR_MEMORY,
114            // 50 MB
115            max_component_size: MAX_COMPONENT_SIZE,
116            max_core_instances_per_component: DEFAULT_MAX_CORE_INSTANCES_PER_COMPONENT,
117            max_components: MAX_COMPONENTS,
118            heartbeat_interval: None,
119            experimental_features: Features::default(),
120            http_admin: None,
121            enable_component_auction: true,
122            enable_provider_auction: true,
123        }
124    }
125}