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