wasmcloud_provider_messaging_nats/
connection.rs1use std::collections::HashMap;
2
3use tracing::warn;
4use wasmcloud_core::messaging::{
5 ConnectionConfig, CONFIG_NATS_CLIENT_JWT, CONFIG_NATS_CLIENT_SEED,
6};
7use wasmcloud_provider_sdk::{core::secrets::SecretValue, LinkConfig};
8
9pub fn from_link_config(
11 LinkConfig {
12 secrets, config, ..
13 }: &LinkConfig,
14) -> anyhow::Result<ConnectionConfig> {
15 let mut map = HashMap::clone(config);
16
17 if let Some(jwt) = secrets
18 .get(CONFIG_NATS_CLIENT_JWT)
19 .and_then(SecretValue::as_string)
20 .or_else(|| {
21 warn!("secret value [{CONFIG_NATS_CLIENT_JWT}] was found not found in secrets. Prefer using secrets for sensitive values.");
22 config.get(CONFIG_NATS_CLIENT_JWT).map(String::as_str)
23 })
24 {
25 map.insert(CONFIG_NATS_CLIENT_JWT.into(), jwt.to_string());
26 }
27
28 if let Some(seed) = secrets
29 .get(CONFIG_NATS_CLIENT_SEED)
30 .and_then(SecretValue::as_string)
31 .or_else(|| {
32 warn!("secret value [{CONFIG_NATS_CLIENT_SEED}] was found not found in secrets. Prefer using secrets for sensitive values.");
33 config.get(CONFIG_NATS_CLIENT_SEED).map(String::as_str)
34 })
35 {
36 map.insert(CONFIG_NATS_CLIENT_SEED.into(), seed.to_string());
37 }
38
39 ConnectionConfig::from_map(&map)
40}