Skip to content

Commit c36dee9

Browse files
refactor!: Removes dependencies from host on provider libraries
Our current host had a circular dependency loop with itself because it depended on the http and messaging providers. In order to break this, I moved the common http and messaging types we use for builtins into `wasmcloud-core` behind feature flags that aren't on by default. As such, this is a breaking change as I moved stuff around, but mostly didn't change any code. Please note that I only bumped version numbers on things we had released already. Some of these crates had not yet been released and do not need another bump Signed-off-by: Taylor Thomas <taylor@cosmonic.com>
1 parent 2b8b5c3 commit c36dee9

File tree

19 files changed

+292
-241
lines changed

19 files changed

+292
-241
lines changed

Cargo.lock

+12-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ wasm-encoder = { version = "0.224", default-features = false }
369369
wasm-gen = { version = "0.1", default-features = false }
370370
wasmcloud-component = { version = "0", path = "crates/component", default-features = false }
371371
wasmcloud-control-interface = { version = "2.4.0", path = "./crates/control-interface", default-features = false }
372-
wasmcloud-core = { version = "^0.17.0", path = "./crates/core", default-features = false }
372+
wasmcloud-core = { version = "^0.18.0", path = "./crates/core", default-features = false }
373373
wasmcloud-host = { version = "^0.25.0", path = "./crates/host", default-features = false }
374374
wasmcloud-provider-blobstore-azure = { version = "*", path = "./crates/provider-blobstore-azure", default-features = false }
375375
wasmcloud-provider-blobstore-fs = { version = "*", path = "./crates/provider-blobstore-fs", default-features = false }
@@ -380,15 +380,15 @@ wasmcloud-provider-keyvalue-nats = { version = "*", path = "./crates/provider-ke
380380
wasmcloud-provider-keyvalue-redis = { version = "*", path = "./crates/provider-keyvalue-redis", default-features = false }
381381
wasmcloud-provider-keyvalue-vault = { version = "*", path = "./crates/provider-keyvalue-vault", default-features = false }
382382
wasmcloud-provider-messaging-kafka = { version = "*", path = "./crates/provider-messaging-kafka", default-features = false }
383-
wasmcloud-provider-messaging-nats = { version = "^0.26.0", path = "./crates/provider-messaging-nats", default-features = false }
384-
wasmcloud-provider-sdk = { version = "^0.14.0", path = "./crates/provider-sdk", default-features = false }
383+
wasmcloud-provider-messaging-nats = { version = "^0.27.0", path = "./crates/provider-messaging-nats", default-features = false }
384+
wasmcloud-provider-sdk = { version = "^0.15.0", path = "./crates/provider-sdk", default-features = false }
385385
wasmcloud-provider-sqldb-postgres = { version = "*", path = "./crates/provider-sqldb-postgres", default-features = false }
386386
wasmcloud-provider-wadm = { version = "*", path = "./crates/provider-wadm", default-features = false }
387-
wasmcloud-runtime = { version = "^0.9.0", path = "./crates/runtime", default-features = false }
387+
wasmcloud-runtime = { version = "^0.10.0", path = "./crates/runtime", default-features = false }
388388
wasmcloud-secrets-client = { version = "^0.7.0", path = "./crates/secrets-client", default-features = false }
389389
wasmcloud-secrets-types = { version = "^0.6.0", path = "./crates/secrets-types", default-features = false }
390390
wasmcloud-test-util = { version = "^0.17.0", path = "./crates/test-util", default-features = false }
391-
wasmcloud-tracing = { version = "^0.13.0", path = "./crates/tracing", default-features = false }
391+
wasmcloud-tracing = { version = "^0.14.0", path = "./crates/tracing", default-features = false }
392392
wasmparser = { version = "0.225", default-features = false }
393393
wasmtime = { version = "26", default-features = false }
394394
wasmtime-wasi = { version = "26", default-features = false }

crates/core/Cargo.toml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wasmcloud-core"
3-
version = "0.17.0"
3+
version = "0.18.0"
44
description = "wasmCloud core functionality shared throughout the ecosystem"
55

66
authors.workspace = true
@@ -22,10 +22,20 @@ hyper-rustls = ["dep:hyper-rustls", "dep:hyper-util"]
2222
tokio-rustls = ["dep:tokio-rustls"]
2323
otel = []
2424
oci = ["dep:oci-client", "dep:oci-wasm"]
25+
http = [
26+
"dep:base64",
27+
"dep:http",
28+
"dep:unicase",
29+
"dep:serde_json",
30+
"dep:thiserror",
31+
]
32+
messaging = ["dep:serde_json"]
2533

2634
[dependencies]
2735
anyhow = { workspace = true, features = ["std"] }
2836
async-nats = { workspace = true, features = ["ring"] }
37+
base64 = { workspace = true, optional = true }
38+
http = { workspace = true, optional = true }
2939
hyper-rustls = { workspace = true, features = [
3040
"http2",
3141
"ring",
@@ -43,8 +53,11 @@ tokio-rustls = { workspace = true, optional = true }
4353
semver = { workspace = true }
4454
secrecy = { workspace = true }
4555
serde = { workspace = true, features = ["derive"] }
56+
serde_json = { workspace = true, optional = true }
57+
thiserror = { workspace = true, optional = true }
4658
tokio = { workspace = true }
4759
tracing = { workspace = true }
60+
unicase = { workspace = true, optional = true }
4861
url = { workspace = true }
4962
wascap = { workspace = true }
5063
webpki-roots = { workspace = true, optional = true }

crates/provider-http-server/src/settings.rs crates/core/src/http.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
//! Configuration settings for [`HttpServerProvider`](crate::HttpServerProvider).
2-
//! The "values" map in the component link definition may contain
3-
//! one or more of the following keys,
1+
//! Common Configuration settings for the http server provider and built in http server. This
2+
//! requires that the `http` feature be enabled.
3+
//!
4+
//! The "values" map in the component link definition may contain one or more of the following keys,
45
//! which determine how the configuration is parsed.
56
//!
6-
//! For the key...
7-
/// `config_file`: load configuration from file name.
8-
/// Interprets file as json or toml, based on file extension.
9-
/// `config_b64`: Configuration is a base64-encoded json string
10-
/// `config_json`: Configuration is a raw json string
7+
//! For the key... `config_file`: load configuration from file name. Interprets file as json
8+
/// or toml, based on file extension. `config_b64`: Configuration is a base64-encoded json
9+
/// string `config_json`: Configuration is a raw json string
1110
///
1211
/// If no configuration is provided, the default settings below will be used:
1312
/// - TLS is disabled
14-
/// - CORS allows all hosts(origins), most methods, and common headers
15-
/// (see constants below).
13+
/// - CORS allows all hosts(origins), most methods, and common headers (see constants below).
1614
/// - Default listener is bound to 127.0.0.1 port 8000.
1715
///
1816
use core::fmt;
@@ -387,8 +385,7 @@ impl FromStr for CorsOrigin {
387385
return Err(std::io::Error::new(
388386
ErrorKind::InvalidInput,
389387
format!(
390-
"Cors origin invalid schema {}, only [http] and [https] are supported: ",
391-
uri.scheme_str().unwrap()
388+
"Cors origin invalid schema {s}, only [http] and [https] are supported: ",
392389
),
393390
));
394391
}
@@ -532,7 +529,7 @@ where
532529
mod test {
533530
use std::str::FromStr;
534531

535-
use crate::settings::{CorsOrigin, ServiceSettings};
532+
use super::{CorsOrigin, ServiceSettings};
536533

537534
const GOOD_ORIGINS: &[&str] = &[
538535
// origins that should be parsed correctly
@@ -561,9 +558,11 @@ mod test {
561558
fn settings_init() {
562559
let s = ServiceSettings::default();
563560
assert!(s.address.is_ipv4());
561+
let allowed_origins = s
562+
.cors_allowed_origins
563+
.expect("allowed_origins should be set");
564564
assert!(s.cors_allowed_methods.is_some());
565-
assert!(s.cors_allowed_origins.is_some());
566-
assert!(s.cors_allowed_origins.unwrap().0.is_empty());
565+
assert!(allowed_origins.0.is_empty());
567566
}
568567

569568
#[test]
@@ -575,10 +574,21 @@ mod test {
575574
}"#;
576575

577576
let s = ServiceSettings::from_json(json).expect("parse_json");
578-
assert_eq!(s.cors_allowed_headers.as_ref().unwrap().0.len(), 1);
579577
assert_eq!(
580-
s.cors_allowed_headers.as_ref().unwrap().0.first().unwrap(),
581-
"X-Cookies"
578+
s.cors_allowed_headers
579+
.as_ref()
580+
.expect("allowed headers should be set")
581+
.0
582+
.len(),
583+
1
584+
);
585+
assert_eq!(
586+
s.cors_allowed_headers
587+
.as_ref()
588+
.expect("allowed headers should be set")
589+
.0
590+
.first(),
591+
Some(&"X-Cookies".into())
582592
);
583593
}
584594

@@ -588,24 +598,22 @@ mod test {
588598
for valid in GOOD_ORIGINS {
589599
let o = serde_json::from_value::<CorsOrigin>(serde_json::Value::String(
590600
(*valid).to_string(),
591-
));
592-
assert!(o.is_ok(), "from_value '{valid}'");
601+
))
602+
.expect("deserialize should succeed");
593603

594604
// test as_ref()
595-
assert_eq!(&o.unwrap().0, valid);
605+
assert_eq!(&o.0, valid);
596606
}
597607
}
598608

599609
#[test]
600610
fn origins_from_str() {
601611
// test CorsOrigin
602612
for &valid in GOOD_ORIGINS {
603-
let o = CorsOrigin::from_str(valid);
604-
println!("{valid}: {o:?}");
605-
assert!(o.is_ok(), "from_str '{valid}'");
613+
let o = CorsOrigin::from_str(valid).expect("deserialize should succeed");
606614

607615
// test as_ref()
608-
assert_eq!(&o.unwrap().0, valid);
616+
assert_eq!(&o.0, valid);
609617
}
610618
}
611619

@@ -614,11 +622,9 @@ mod test {
614622
for bad in BAD_ORIGINS {
615623
let o =
616624
serde_json::from_value::<CorsOrigin>(serde_json::Value::String((*bad).to_string()));
617-
println!("{bad}: {o:?}");
618625
assert!(o.is_err(), "from_value '{bad}' (expect err)");
619626

620627
let o = serde_json::from_str::<CorsOrigin>(bad);
621-
println!("{bad}: {o:?}");
622628
assert!(o.is_err(), "from_str '{bad}' (expect err)");
623629
}
624630
}

crates/core/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub mod secrets;
3232
pub mod wit;
3333
pub use wit::*;
3434

35+
#[cfg(feature = "http")]
36+
pub mod http;
37+
38+
#[cfg(feature = "messaging")]
39+
pub mod messaging;
40+
3541
/// The 1.0 version of the wasmCloud control API, used in topic strings for the control API
3642
pub const CTL_API_VERSION_1: &str = "v1";
3743

0 commit comments

Comments
 (0)