From ace951390396084b2b2e498def2a2a78fde3ae5a Mon Sep 17 00:00:00 2001 From: Caleb Schoepp Date: Fri, 30 Aug 2024 15:29:53 -0600 Subject: [PATCH] Merge host component outbound networking implementation into new factor crate Signed-off-by: Caleb Schoepp --- Cargo.lock | 33 +++++++------------ crates/factor-outbound-mysql/Cargo.toml | 1 - crates/factor-outbound-networking/Cargo.toml | 7 ++-- .../src/config.rs} | 0 crates/factor-outbound-networking/src/lib.rs | 8 +++-- crates/loader/Cargo.toml | 2 +- crates/loader/src/local.rs | 6 ++-- crates/outbound-networking/Cargo.toml | 15 --------- crates/trigger-http/Cargo.toml | 2 +- crates/trigger-http/src/headers.rs | 2 +- crates/trigger-http/src/outbound_http.rs | 2 +- examples/spin-timer/Cargo.lock | 21 +++--------- 12 files changed, 34 insertions(+), 65 deletions(-) rename crates/{outbound-networking/src/lib.rs => factor-outbound-networking/src/config.rs} (100%) delete mode 100644 crates/outbound-networking/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index ad3850d08f..30dbbb1374 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ dependencies = [ [[package]] name = "azure_core" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "base64 0.22.1", @@ -599,7 +599,7 @@ dependencies = [ [[package]] name = "azure_data_cosmos" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "azure_core", @@ -617,7 +617,7 @@ dependencies = [ [[package]] name = "azure_identity" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-lock 3.3.0", "async-process 2.2.2", @@ -637,7 +637,7 @@ dependencies = [ [[package]] name = "azure_security_keyvault" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "azure_core", @@ -7392,7 +7392,6 @@ dependencies = [ "spin-factor-variables", "spin-factors", "spin-factors-test", - "spin-outbound-networking", "spin-world", "table", "tokio", @@ -7412,16 +7411,20 @@ dependencies = [ "rustls-pemfile 2.1.2", "rustls-pki-types", "serde 1.0.197", + "spin-expressions", "spin-factor-variables", "spin-factor-wasi", "spin-factors", "spin-factors-test", - "spin-outbound-networking", + "spin-locked-app", "spin-serde", "tempfile", + "terminal", "tokio", "toml 0.8.14", "tracing", + "url", + "urlencoding", "wasmtime-wasi", "webpki-roots 0.26.1", ] @@ -7699,9 +7702,9 @@ dependencies = [ "sha2", "shellexpand 3.1.0", "spin-common", + "spin-factor-outbound-networking", "spin-locked-app", "spin-manifest", - "spin-outbound-networking", "spin-serde", "tempfile", "terminal", @@ -7775,20 +7778,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "spin-outbound-networking" -version = "2.8.0-pre0" -dependencies = [ - "anyhow", - "http 1.1.0", - "ipnet", - "spin-expressions", - "spin-locked-app", - "terminal", - "url", - "urlencoding", -] - [[package]] name = "spin-plugins" version = "2.8.0-pre0" @@ -8011,9 +8000,9 @@ dependencies = [ "spin-app", "spin-core", "spin-factor-outbound-http", + "spin-factor-outbound-networking", "spin-factor-wasi", "spin-http", - "spin-outbound-networking", "spin-telemetry", "spin-trigger", "spin-world", diff --git a/crates/factor-outbound-mysql/Cargo.toml b/crates/factor-outbound-mysql/Cargo.toml index 083807cf19..3c721f7d0a 100644 --- a/crates/factor-outbound-mysql/Cargo.toml +++ b/crates/factor-outbound-mysql/Cargo.toml @@ -21,7 +21,6 @@ spin-core = { path = "../core" } spin-expressions = { path = "../expressions" } spin-factor-outbound-networking = { path = "../factor-outbound-networking" } spin-factors = { path = "../factors" } -spin-outbound-networking = { path = "../outbound-networking" } spin-world = { path = "../world" } table = { path = "../table" } tokio = { version = "1", features = ["rt-multi-thread"] } diff --git a/crates/factor-outbound-networking/Cargo.toml b/crates/factor-outbound-networking/Cargo.toml index 66e1d054f1..6c0d3c8b20 100644 --- a/crates/factor-outbound-networking/Cargo.toml +++ b/crates/factor-outbound-networking/Cargo.toml @@ -13,13 +13,16 @@ rustls = { version = "0.23", default-features = false, features = ["ring", "std" rustls-pemfile = { version = "2.1.2", optional = true } rustls-pki-types = "1.7.0" serde = { version = "1", features = ["derive"] } +spin-expressions = { path = "../expressions" } spin-factor-variables = { path = "../factor-variables" } spin-factor-wasi = { path = "../factor-wasi" } spin-factors = { path = "../factors" } -# TODO: merge with this crate -spin-outbound-networking = { path = "../outbound-networking" } +spin-locked-app = { path = "../locked-app" } spin-serde = { path = "../serde" } +terminal = { path = "../terminal" } tracing = { workspace = true } +url = "2.4.1" +urlencoding = "2.1" webpki-roots = "0.26" [dev-dependencies] diff --git a/crates/outbound-networking/src/lib.rs b/crates/factor-outbound-networking/src/config.rs similarity index 100% rename from crates/outbound-networking/src/lib.rs rename to crates/factor-outbound-networking/src/config.rs diff --git a/crates/factor-outbound-networking/src/lib.rs b/crates/factor-outbound-networking/src/lib.rs index 7af5f34f14..9610e618e1 100644 --- a/crates/factor-outbound-networking/src/lib.rs +++ b/crates/factor-outbound-networking/src/lib.rs @@ -1,7 +1,9 @@ +mod config; pub mod runtime_config; use std::{collections::HashMap, sync::Arc}; +use config::ALLOWED_HOSTS_KEY; use futures_util::{ future::{BoxFuture, Shared}, FutureExt, @@ -14,9 +16,11 @@ use spin_factors::{ ConfigureAppContext, Error, Factor, FactorInstanceBuilder, InstanceBuilders, PrepareContext, RuntimeFactors, }; -use spin_outbound_networking::{AllowedHostsConfig, ALLOWED_HOSTS_KEY}; -pub use spin_outbound_networking::OutboundUrl; +pub use config::{ + is_service_chaining_host, parse_service_chaining_target, AllowedHostConfig, AllowedHostsConfig, + HostConfig, OutboundUrl, SERVICE_CHAINING_DOMAIN_SUFFIX, +}; pub use runtime_config::ComponentTlsConfigs; diff --git a/crates/loader/Cargo.toml b/crates/loader/Cargo.toml index c7d29dd087..329f1c5e5e 100644 --- a/crates/loader/Cargo.toml +++ b/crates/loader/Cargo.toml @@ -26,7 +26,7 @@ shellexpand = "3.1" spin-common = { path = "../common" } spin-locked-app = { path = "../locked-app" } spin-manifest = { path = "../manifest" } -spin-outbound-networking = { path = "../outbound-networking" } +spin-factor-outbound-networking = { path = "../factor-outbound-networking" } spin-serde = { path = "../serde" } tempfile = "3.8.0" terminal = { path = "../terminal" } diff --git a/crates/loader/src/local.rs b/crates/loader/src/local.rs index af1bf7d493..3d5bb6304b 100644 --- a/crates/loader/src/local.rs +++ b/crates/loader/src/local.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, bail, ensure, Context, Result}; use futures::{future::try_join_all, StreamExt}; use reqwest::Url; use spin_common::{paths::parent_dir, sloth, ui::quoted_path}; +use spin_factor_outbound_networking::SERVICE_CHAINING_DOMAIN_SUFFIX; use spin_locked_app::{ locked::{ self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentDependency, @@ -12,7 +13,6 @@ use spin_locked_app::{ values::{ValuesMap, ValuesMapBuilder}, }; use spin_manifest::schema::v2::{self, AppManifest, KebabId, WasiFilesMount}; -use spin_outbound_networking::SERVICE_CHAINING_DOMAIN_SUFFIX; use spin_serde::DependencyName; use std::collections::BTreeMap; use tokio::{io::AsyncWriteExt, sync::Semaphore}; @@ -147,7 +147,7 @@ impl LocalLoader { let allowed_outbound_hosts = component .normalized_allowed_outbound_hosts() .context("`allowed_http_hosts` is malformed")?; - spin_outbound_networking::AllowedHostsConfig::validate(&allowed_outbound_hosts) + spin_factor_outbound_networking::AllowedHostsConfig::validate(&allowed_outbound_hosts) .context("`allowed_outbound_hosts` is malformed")?; let metadata = ValuesMapBuilder::new() @@ -784,7 +784,7 @@ fn requires_service_chaining(component: &spin_manifest::schema::v2::Component) - } fn is_chaining_host(pattern: &str) -> bool { - use spin_outbound_networking::{AllowedHostConfig, HostConfig}; + use spin_factor_outbound_networking::{AllowedHostConfig, HostConfig}; let Ok(allowed) = AllowedHostConfig::parse(pattern) else { return false; diff --git a/crates/outbound-networking/Cargo.toml b/crates/outbound-networking/Cargo.toml deleted file mode 100644 index d630181eb2..0000000000 --- a/crates/outbound-networking/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "spin-outbound-networking" -version.workspace = true -authors.workspace = true -edition.workspace = true - -[dependencies] -anyhow = "1.0" -http = "1.0.0" -ipnet = "2.9.0" -spin-expressions = { path = "../expressions" } -spin-locked-app = { path = "../locked-app" } -terminal = { path = "../terminal" } -url = "2.4.1" -urlencoding = "2.1" diff --git a/crates/trigger-http/Cargo.toml b/crates/trigger-http/Cargo.toml index c273b1db22..f02bea8516 100644 --- a/crates/trigger-http/Cargo.toml +++ b/crates/trigger-http/Cargo.toml @@ -34,7 +34,7 @@ spin-core = { path = "../core" } spin-factor-outbound-http = { path = "../factor-outbound-http" } spin-factor-wasi = { path = "../factor-wasi" } spin-http = { path = "../http" } -spin-outbound-networking = { path = "../outbound-networking" } +spin-factor-outbound-networking = { path = "../factor-outbound-networking" } spin-telemetry = { path = "../telemetry" } spin-trigger = { path = "../trigger" } spin-world = { path = "../world" } diff --git a/crates/trigger-http/src/headers.rs b/crates/trigger-http/src/headers.rs index eed6a40754..82b365e72b 100644 --- a/crates/trigger-http/src/headers.rs +++ b/crates/trigger-http/src/headers.rs @@ -3,8 +3,8 @@ use std::{net::SocketAddr, str, str::FromStr}; use anyhow::Result; use http::Uri; use hyper::Request; +use spin_factor_outbound_networking::is_service_chaining_host; use spin_http::routes::RouteMatch; -use spin_outbound_networking::is_service_chaining_host; use crate::Body; diff --git a/crates/trigger-http/src/outbound_http.rs b/crates/trigger-http/src/outbound_http.rs index a722bc315d..53912106fd 100644 --- a/crates/trigger-http/src/outbound_http.rs +++ b/crates/trigger-http/src/outbound_http.rs @@ -7,8 +7,8 @@ use http::uri::Scheme; use spin_factor_outbound_http::{ HostFutureIncomingResponse, InterceptOutcome, OutgoingRequestConfig, Request, }; +use spin_factor_outbound_networking::parse_service_chaining_target; use spin_http::routes::RouteMatch; -use spin_outbound_networking::parse_service_chaining_target; use wasmtime_wasi_http::types::IncomingResponse; use crate::HttpServer; diff --git a/examples/spin-timer/Cargo.lock b/examples/spin-timer/Cargo.lock index 7d7e3f3b2c..54dfede101 100644 --- a/examples/spin-timer/Cargo.lock +++ b/examples/spin-timer/Cargo.lock @@ -3879,7 +3879,6 @@ dependencies = [ "spin-expressions", "spin-factor-outbound-networking", "spin-factors", - "spin-outbound-networking", "spin-world", "table", "tokio", @@ -3899,12 +3898,16 @@ dependencies = [ "rustls-pemfile 2.1.3", "rustls-pki-types", "serde", + "spin-expressions", "spin-factor-variables", "spin-factor-wasi", "spin-factors", - "spin-outbound-networking", + "spin-locked-app", "spin-serde", + "terminal", "tracing", + "url", + "urlencoding", "webpki-roots 0.26.3", ] @@ -4102,20 +4105,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "spin-outbound-networking" -version = "2.8.0-pre0" -dependencies = [ - "anyhow", - "http 1.1.0", - "ipnet", - "spin-expressions", - "spin-locked-app", - "terminal", - "url", - "urlencoding", -] - [[package]] name = "spin-runtime-config" version = "2.8.0-pre0"