Skip to content

Commit 783d61b

Browse files
feat(host): gate messaging@v3 behind feature flag
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
1 parent 791a658 commit 783d61b

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

crates/host/src/wasmbus/experimental.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub struct Features {
1010
/// Enable the built-in NATS Messaging capability provider
1111
/// that can be started with the reference wasmcloud+builtin://messaging-nats
1212
pub(crate) builtin_messaging_nats: bool,
13+
/// Enable the wasmcloud:messaging@v3 interface support in the host
14+
pub(crate) wasmcloud_messaging_v3: bool,
1315
}
1416

1517
impl Features {
@@ -29,6 +31,12 @@ impl Features {
2931
self.builtin_messaging_nats = true;
3032
self
3133
}
34+
35+
/// Enable the wasmcloud:messaging@v3 interface support in the host
36+
pub fn enable_wasmcloud_messaging_v3(mut self) -> Self {
37+
self.wasmcloud_messaging_v3 = true;
38+
self
39+
}
3240
}
3341

3442
/// This enables unioning feature flags together
@@ -39,6 +47,7 @@ impl std::ops::BitOr for Features {
3947
Self {
4048
builtin_http_server: self.builtin_http_server || rhs.builtin_http_server,
4149
builtin_messaging_nats: self.builtin_messaging_nats || rhs.builtin_messaging_nats,
50+
wasmcloud_messaging_v3: self.wasmcloud_messaging_v3 || rhs.wasmcloud_messaging_v3,
4251
}
4352
}
4453
}
@@ -62,6 +71,9 @@ impl From<&str> for Features {
6271
"builtin-messaging-nats" | "builtin_messaging_nats" => {
6372
Self::new().enable_builtin_messaging_nats()
6473
}
74+
"wasmcloud-messaging-v3" | "wasmcloud_messaging_v3" => {
75+
Self::new().enable_wasmcloud_messaging_v3()
76+
}
6577
_ => {
6678
warn!(%s, "unknown feature flag");
6779
Self::new()

crates/host/src/wasmbus/handler.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use wasmcloud_tracing::context::TraceContextInjector;
2626
use wrpc_transport::InvokeExt as _;
2727

2828
use super::config::ConfigBundle;
29-
use super::injector_to_headers;
29+
use super::{injector_to_headers, Features};
3030

3131
#[derive(Clone, Debug)]
3232
pub struct Handler {
@@ -62,6 +62,8 @@ pub struct Handler {
6262
pub messaging_links: Arc<RwLock<HashMap<Box<str>, async_nats::Client>>>,
6363

6464
pub invocation_timeout: Duration,
65+
/// Experimental features enabled in the host for gating handler functionality
66+
pub experimental_features: Features,
6567
}
6668

6769
impl Handler {
@@ -78,6 +80,7 @@ impl Handler {
7880
instance_links: self.instance_links.clone(),
7981
messaging_links: self.messaging_links.clone(),
8082
invocation_timeout: self.invocation_timeout,
83+
experimental_features: self.experimental_features,
8184
}
8285
}
8386
}
@@ -585,23 +588,27 @@ impl MessagingHostMessage0_3 for Message {
585588
}
586589

587590
impl Messaging0_3 for Handler {
591+
#[instrument(level = "debug", skip_all)]
588592
async fn connect(
589593
&self,
590594
name: String,
591595
) -> anyhow::Result<
592596
Result<Box<dyn MessagingClient0_3 + Send + Sync>, messaging0_3_0::types::Error>,
593597
> {
598+
self.ensure_messaging_v3()?;
594599
Ok(Ok(Box::new(MessagingClient {
595600
name: name.into_boxed_str(),
596601
})))
597602
}
598603

604+
#[instrument(level = "debug", skip_all)]
599605
async fn send(
600606
&self,
601607
client: &(dyn MessagingClient0_3 + Send + Sync),
602608
topic: messaging0_3_0::types::Topic,
603609
message: messaging0_3_0::types::Message,
604610
) -> anyhow::Result<Result<(), messaging0_3_0::types::Error>> {
611+
self.ensure_messaging_v3()?;
605612
use wasmcloud_runtime::capability::wrpc::wasmcloud::messaging0_2_0 as messaging;
606613

607614
let MessagingClient { name } = client
@@ -741,6 +748,7 @@ impl Messaging0_3 for Handler {
741748
}
742749
}
743750

751+
#[instrument(level = "debug", skip_all)]
744752
async fn request(
745753
&self,
746754
client: &(dyn MessagingClient0_3 + Send + Sync),
@@ -750,6 +758,7 @@ impl Messaging0_3 for Handler {
750758
) -> anyhow::Result<
751759
Result<Vec<Box<dyn MessagingHostMessage0_3 + Send + Sync>>, messaging0_3_0::types::Error>,
752760
> {
761+
self.ensure_messaging_v3()?;
753762
if options.is_some() {
754763
return Ok(Err(messaging0_3_0::types::Error::Other(
755764
"`options` not currently supported".into(),
@@ -906,11 +915,13 @@ impl Messaging0_3 for Handler {
906915
}
907916
}
908917

918+
#[instrument(level = "debug", skip_all)]
909919
async fn reply(
910920
&self,
911921
reply_to: &messaging0_3_0::types::Message,
912922
message: messaging0_3_0::types::Message,
913923
) -> anyhow::Result<Result<(), messaging0_3_0::types::Error>> {
924+
self.ensure_messaging_v3()?;
914925
use wasmcloud_runtime::capability::wrpc::wasmcloud::messaging0_2_0 as messaging;
915926

916927
{
@@ -1117,3 +1128,16 @@ impl InvocationErrorIntrospect for Handler {
11171128
InvocationErrorKind::Trap
11181129
}
11191130
}
1131+
1132+
impl Handler {
1133+
/// Helper function for our wasmcloud:messaging@v3 invocations to ensure the feature is enabled
1134+
/// before continuing with an invocation.
1135+
fn ensure_messaging_v3(&self) -> anyhow::Result<()> {
1136+
self.experimental_features
1137+
.wasmcloud_messaging_v3
1138+
.then(|| ())
1139+
.ok_or(anyhow!(
1140+
"wasmcloud-messaging-v3 feature flag is disabled, rejecting invocation"
1141+
))
1142+
}
1143+
}

crates/host/src/wasmbus/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ impl Host {
13851385
Arc::clone(links.entry(Arc::clone(&component_id)).or_default())
13861386
},
13871387
invocation_timeout: Duration::from_secs(10), // TODO: Make this configurable
1388+
experimental_features: self.experimental_features,
13881389
};
13891390
let component = wasmcloud_runtime::Component::new(&self.runtime, &wasm)?;
13901391
let component = self

crates/test-util/src/host.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ impl WasmCloudTestHost {
103103
secrets_topic_prefix,
104104
experimental_features: Features::new()
105105
.enable_builtin_http_server()
106-
.enable_builtin_messaging_nats(),
106+
.enable_builtin_messaging_nats()
107+
.enable_wasmcloud_messaging_v3(),
107108
..Default::default()
108109
};
109110
if let Some(psc) = policy_service_config {

0 commit comments

Comments
 (0)