wasmcloud_host/wasmbus/
experimental.rs1use tracing::warn;
2
3#[derive(Copy, Clone, Debug, Default)]
6pub struct Features {
7 pub(crate) builtin_http_client: bool,
10 pub(crate) builtin_http_server: bool,
13 pub(crate) builtin_messaging_nats: bool,
16 pub(crate) wasmcloud_messaging_v3: bool,
18 pub(crate) workload_identity_auth: bool,
21 pub(crate) workload_identity_interface: bool,
23 pub(crate) rpc_interface: bool,
25}
26
27impl Features {
28 pub fn new() -> Self {
30 Self::default()
31 }
32
33 pub fn enable_builtin_http_client(mut self) -> Self {
35 self.builtin_http_client = true;
36 self
37 }
38
39 pub fn enable_builtin_http_server(mut self) -> Self {
41 self.builtin_http_server = true;
42 self
43 }
44
45 pub fn enable_builtin_messaging_nats(mut self) -> Self {
47 self.builtin_messaging_nats = true;
48 self
49 }
50
51 pub fn enable_wasmcloud_messaging_v3(mut self) -> Self {
53 self.wasmcloud_messaging_v3 = true;
54 self
55 }
56
57 pub fn enable_workload_identity_auth(mut self) -> Self {
59 self.workload_identity_auth = true;
60 self
61 }
62
63 pub fn enable_workload_identity_interface(mut self) -> Self {
65 self.workload_identity_interface = true;
66 self
67 }
68
69 pub fn enable_rpc_interface(mut self) -> Self {
71 self.rpc_interface = true;
72 self
73 }
74
75 pub fn builtin_http_server_enabled(&self) -> bool {
77 self.builtin_http_server
78 }
79
80 pub fn builtin_messaging_nats_enabled(&self) -> bool {
82 self.builtin_messaging_nats
83 }
84
85 pub fn wasmcloud_messaging_v3_enabled(&self) -> bool {
87 self.wasmcloud_messaging_v3
88 }
89
90 pub fn workload_identity_auth_enabled(&self) -> bool {
92 self.workload_identity_auth
93 }
94
95 pub fn workload_identity_interface_enabled(&self) -> bool {
97 self.workload_identity_interface
98 }
99
100 pub fn rpc_interface_enabled(&self) -> bool {
102 self.rpc_interface
103 }
104}
105
106impl std::ops::BitOr for Features {
108 type Output = Self;
109
110 fn bitor(self, rhs: Self) -> Self::Output {
111 Self {
112 builtin_http_client: self.builtin_http_client || rhs.builtin_http_client,
113 builtin_http_server: self.builtin_http_server || rhs.builtin_http_server,
114 builtin_messaging_nats: self.builtin_messaging_nats || rhs.builtin_messaging_nats,
115 wasmcloud_messaging_v3: self.wasmcloud_messaging_v3 || rhs.wasmcloud_messaging_v3,
116 workload_identity_auth: self.workload_identity_auth || rhs.workload_identity_auth,
117 workload_identity_interface: self.workload_identity_interface
118 || rhs.workload_identity_interface,
119 rpc_interface: self.rpc_interface || rhs.rpc_interface,
120 }
121 }
122}
123
124impl std::iter::Sum for Features {
126 fn sum<I: Iterator<Item = Self>>(mut iter: I) -> Self {
127 let first = iter.next().unwrap_or_default();
129 iter.fold(first, |a, b| a | b)
130 }
131}
132
133impl From<&str> for Features {
135 fn from(s: &str) -> Self {
136 match &*s.to_ascii_lowercase() {
137 "builtin-http-client" | "builtin_http_client" => {
138 Self::new().enable_builtin_http_client()
139 }
140 "builtin-http-server" | "builtin_http_server" => {
141 Self::new().enable_builtin_http_server()
142 }
143 "builtin-messaging-nats" | "builtin_messaging_nats" => {
144 Self::new().enable_builtin_messaging_nats()
145 }
146 "wasmcloud-messaging-v3" | "wasmcloud_messaging_v3" => {
147 Self::new().enable_wasmcloud_messaging_v3()
148 }
149 "workload-identity-auth" | "workload_identity_auth" => {
150 Self::new().enable_workload_identity_auth()
151 }
152 "workload-identity-interface" | "workload_identity_interface" => {
153 Self::new().enable_workload_identity_interface()
154 }
155 "rpc-interface" | "rpc_interface" => Self::new().enable_rpc_interface(),
156 _ => {
157 warn!(%s, "unknown feature flag");
158 Self::new()
159 }
160 }
161 }
162}
163
164impl From<Features> for wasmcloud_runtime::experimental::Features {
166 fn from(f: Features) -> wasmcloud_runtime::experimental::Features {
167 wasmcloud_runtime::experimental::Features {
168 wasmcloud_messaging_v3: f.wasmcloud_messaging_v3,
169 workload_identity_interface: f.workload_identity_interface,
170 rpc_interface: f.rpc_interface,
171 }
172 }
173}