wasmcloud_core/
host.rs

1//! Reusable functionality related to [wasmCloud hosts][docs-wasmcloud-hosts]
2//!
3//! [docs-wasmcloud-hosts]: <https://wasmcloud.com/docs/concepts/hosts>
4
5use std::collections::HashMap;
6
7use secrecy::zeroize::{Zeroize, ZeroizeOnDrop};
8use serde::{Deserialize, Serialize};
9
10use crate::link::InterfaceLinkDefinition;
11use crate::logging::Level;
12use crate::otel::OtelConfig;
13use crate::secrets::SecretValue;
14use crate::wit::{deserialize_wit_map, serialize_wit_map, WitMap};
15
16/// Environment settings for initializing a capability provider
17pub type HostEnvValues = WitMap<String>;
18
19/// initialization data for a capability provider
20#[derive(Clone, Debug, Default, Deserialize, Serialize)]
21pub struct HostData {
22    #[serde(default)]
23    pub host_id: String,
24    #[serde(default)]
25    pub lattice_rpc_prefix: String,
26    #[serde(default)]
27    pub link_name: String,
28    #[serde(default)]
29    pub lattice_rpc_user_jwt: String,
30    #[serde(default)]
31    pub lattice_rpc_user_seed: String,
32    #[serde(default)]
33    pub lattice_rpc_url: String,
34    #[serde(default)]
35    pub provider_key: String,
36    #[serde(
37        serialize_with = "serialize_wit_map",
38        deserialize_with = "deserialize_wit_map"
39    )]
40    pub env_values: HostEnvValues,
41    #[serde(default)]
42    pub instance_id: String,
43    /// initial list of links for provider
44    pub link_definitions: Vec<InterfaceLinkDefinition>,
45    /// list of cluster issuers.
46    #[serde(default)]
47    pub cluster_issuers: Vec<String>,
48    /// Merged named configuration set for this provider at runtime
49    #[serde(default)]
50    pub config: HashMap<String, String>,
51    /// Secrets given to this provider at runtime
52    #[serde(default)]
53    pub secrets: HashMap<String, SecretValue>,
54    /// The public key xkey of the host, used for decrypting secrets
55    #[serde(default)]
56    pub host_xkey_public_key: String,
57    /// The private key xkey of the provider, used for decrypting secrets
58    #[serde(default)]
59    pub provider_xkey_private_key: String,
60    /// Host-wide default RPC timeout for rpc messages, in milliseconds.  Defaults to 2000.
61    #[serde(default, skip_serializing_if = "Option::is_none")]
62    pub default_rpc_timeout_ms: Option<u64>,
63    /// True if structured logging is enabled for the host. Providers should use the same setting as the host.
64    #[serde(default)]
65    pub structured_logging: bool,
66    /// The log level providers should log at
67    #[serde(default, skip_serializing_if = "Option::is_none")]
68    pub log_level: Option<Level>,
69    #[serde(default)]
70    pub otel_config: OtelConfig,
71}
72
73// Trait implementations that ensure we zeroize the memory of secrets when they are dropped
74impl ZeroizeOnDrop for HostData {}
75impl Zeroize for HostData {
76    fn zeroize(&mut self) {
77        self.provider_xkey_private_key.zeroize();
78    }
79}