diff --git a/Cargo.lock b/Cargo.lock index fa22838180..bb84e5a0d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,7 +563,7 @@ dependencies = [ [[package]] name = "azure_core" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "base64 0.22.1", @@ -591,7 +591,7 @@ dependencies = [ [[package]] name = "azure_data_cosmos" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "azure_core", @@ -609,7 +609,7 @@ dependencies = [ [[package]] name = "azure_identity" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-lock 3.4.0", "async-process 2.3.0", @@ -629,7 +629,7 @@ dependencies = [ [[package]] name = "azure_security_keyvault" version = "0.20.0" -source = "git+https://github.com/azure/azure-sdk-for-rust?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" +source = "git+https://github.com/azure/azure-sdk-for-rust.git?rev=8c4caa251c3903d5eae848b41bb1d02a4d65231c#8c4caa251c3903d5eae848b41bb1d02a4d65231c" dependencies = [ "async-trait", "azure_core", @@ -7302,10 +7302,6 @@ dependencies = [ name = "spin-factor-variables" version = "2.8.0-pre0" dependencies = [ - "azure_core", - "azure_identity", - "azure_security_keyvault", - "dotenvy", "serde 1.0.210", "spin-expressions", "spin-factors", @@ -7314,7 +7310,6 @@ dependencies = [ "tokio", "toml 0.8.19", "tracing", - "vaultrs", ] [[package]] @@ -7634,6 +7629,7 @@ dependencies = [ "spin-key-value-spin", "spin-sqlite", "spin-trigger", + "spin-variables", "spin-world", "tempfile", "tokio", @@ -7863,6 +7859,24 @@ dependencies = [ "tracing", ] +[[package]] +name = "spin-variables" +version = "2.8.0-pre0" +dependencies = [ + "azure_core", + "azure_identity", + "azure_security_keyvault", + "dotenvy", + "serde 1.0.210", + "spin-expressions", + "spin-factor-variables", + "spin-factors", + "spin-world", + "tokio", + "tracing", + "vaultrs", +] + [[package]] name = "spin-world" version = "2.8.0-pre0" diff --git a/crates/factor-variables/Cargo.toml b/crates/factor-variables/Cargo.toml index 6310d2a882..82c915bf4f 100644 --- a/crates/factor-variables/Cargo.toml +++ b/crates/factor-variables/Cargo.toml @@ -5,18 +5,12 @@ authors = { workspace = true } edition = { workspace = true } [dependencies] -azure_core = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } -azure_identity = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } -azure_security_keyvault = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } -dotenvy = "0.15" serde = { workspace = true } spin-expressions = { path = "../expressions" } spin-factors = { path = "../factors" } spin-world = { path = "../world" } -tokio = { workspace = true, features = ["rt-multi-thread"] } toml = { workspace = true } tracing = { workspace = true } -vaultrs = "0.7" [dev-dependencies] spin-factors-test = { path = "../factors-test" } diff --git a/crates/factor-variables/src/lib.rs b/crates/factor-variables/src/lib.rs index 7078c99aa4..ac5c7e626b 100644 --- a/crates/factor-variables/src/lib.rs +++ b/crates/factor-variables/src/lib.rs @@ -1,6 +1,5 @@ mod host; pub mod runtime_config; -pub mod spin_cli; use std::sync::Arc; diff --git a/crates/factor-variables/tests/factor_test.rs b/crates/factor-variables/tests/factor_test.rs index 33df9f1b2f..40e8be773d 100644 --- a/crates/factor-variables/tests/factor_test.rs +++ b/crates/factor-variables/tests/factor_test.rs @@ -1,7 +1,6 @@ -use spin_factor_variables::{spin_cli, VariablesFactor}; -use spin_factors::{ - anyhow, Factor, FactorRuntimeConfigSource, RuntimeConfigSourceFinalizer, RuntimeFactors, -}; +use spin_expressions::{Key, Provider}; +use spin_factor_variables::{runtime_config::RuntimeConfig, VariablesFactor}; +use spin_factors::{anyhow, RuntimeFactors}; use spin_factors_test::{toml, TestEnvironment}; use spin_world::v2::variables::Host; @@ -11,10 +10,14 @@ struct TestFactors { } #[tokio::test(flavor = "multi_thread")] -async fn static_provider_works() -> anyhow::Result<()> { +async fn provider_works() -> anyhow::Result<()> { let factors = TestFactors { variables: VariablesFactor::default(), }; + let providers = vec![Box::new(MockProvider) as _]; + let runtime_config = TestFactorsRuntimeConfig { + variables: Some(RuntimeConfig { providers }), + }; let env = TestEnvironment::new(factors) .extend_manifest(toml! { [variables] @@ -24,11 +27,7 @@ async fn static_provider_works() -> anyhow::Result<()> { source = "does-not-exist.wasm" variables = { baz = "<{{ foo }}>" } }) - .runtime_config(TomlConfig::new(toml! { - [[variables_provider]] - type = "static" - values = { foo = "bar" } - }))?; + .runtime_config(runtime_config)?; let mut state = env.build_instance_state().await?; let val = state.variables.get("baz".into()).await?; @@ -36,34 +35,15 @@ async fn static_provider_works() -> anyhow::Result<()> { Ok(()) } -struct TomlConfig { - table: toml::Table, -} - -impl TomlConfig { - fn new(table: toml::Table) -> Self { - Self { table } - } -} - -impl TryFrom for TestFactorsRuntimeConfig { - type Error = anyhow::Error; - - fn try_from(value: TomlConfig) -> Result { - Self::from_source(value) - } -} - -impl FactorRuntimeConfigSource for TomlConfig { - fn get_runtime_config( - &mut self, - ) -> anyhow::Result::RuntimeConfig>> { - spin_cli::runtime_config_from_toml(&self.table).map(Some) - } -} +#[derive(Debug)] +struct MockProvider; -impl RuntimeConfigSourceFinalizer for TomlConfig { - fn finalize(&mut self) -> anyhow::Result<()> { - Ok(()) +#[spin_world::async_trait] +impl Provider for MockProvider { + async fn get(&self, key: &Key) -> anyhow::Result> { + match key.as_str() { + "foo" => Ok(Some("bar".to_string())), + _ => Ok(None), + } } } diff --git a/crates/runtime-config/Cargo.toml b/crates/runtime-config/Cargo.toml index 288e75f379..569026129f 100644 --- a/crates/runtime-config/Cargo.toml +++ b/crates/runtime-config/Cargo.toml @@ -28,6 +28,7 @@ spin-key-value-redis = { path = "../key-value-redis" } spin-key-value-spin = { path = "../key-value-spin" } spin-sqlite = { path = "../sqlite" } spin-trigger = { path = "../trigger" } +spin-variables = { path = "../variables" } toml = { workspace = true } [dev-dependencies] diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index 4507506115..fd0687361a 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -13,7 +13,7 @@ use spin_factor_outbound_networking::OutboundNetworkingFactor; use spin_factor_outbound_pg::OutboundPgFactor; use spin_factor_outbound_redis::OutboundRedisFactor; use spin_factor_sqlite::SqliteFactor; -use spin_factor_variables::{spin_cli as variables, VariablesFactor}; +use spin_factor_variables::VariablesFactor; use spin_factor_wasi::WasiFactor; use spin_factors::runtime_config::toml::GetTomlValue as _; use spin_factors::{ @@ -314,7 +314,9 @@ impl FactorRuntimeConfigSource for TomlRuntimeConfigSource<'_, fn get_runtime_config( &mut self, ) -> anyhow::Result::RuntimeConfig>> { - Ok(Some(variables::runtime_config_from_toml(&self.toml.table)?)) + Ok(Some(spin_variables::runtime_config_from_toml( + &self.toml.table, + )?)) } } diff --git a/crates/variables/Cargo.toml b/crates/variables/Cargo.toml new file mode 100644 index 0000000000..f97cbdcda1 --- /dev/null +++ b/crates/variables/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "spin-variables" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +rust-version.workspace = true + +[dependencies] +azure_core = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } +azure_identity = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } +azure_security_keyvault = { git = "https://github.com/azure/azure-sdk-for-rust", rev = "8c4caa251c3903d5eae848b41bb1d02a4d65231c" } +dotenvy = "0.15" +serde = { workspace = true } +spin-expressions = { path = "../expressions" } +spin-factors = { path = "../factors" } +spin-factor-variables = { path = "../factor-variables" } +spin-world = { path = "../world" } +tokio = { workspace = true, features = ["rt-multi-thread"] } +tracing = { workspace = true } +vaultrs = "0.7" + +[lints] +workspace = true diff --git a/crates/factor-variables/src/spin_cli/azure_key_vault.rs b/crates/variables/src/azure_key_vault.rs similarity index 100% rename from crates/factor-variables/src/spin_cli/azure_key_vault.rs rename to crates/variables/src/azure_key_vault.rs diff --git a/crates/factor-variables/src/spin_cli/env.rs b/crates/variables/src/env.rs similarity index 100% rename from crates/factor-variables/src/spin_cli/env.rs rename to crates/variables/src/env.rs diff --git a/crates/factor-variables/src/spin_cli/mod.rs b/crates/variables/src/lib.rs similarity index 97% rename from crates/factor-variables/src/spin_cli/mod.rs rename to crates/variables/src/lib.rs index 6a31a5b09f..f5857e0d07 100644 --- a/crates/factor-variables/src/spin_cli/mod.rs +++ b/crates/variables/src/lib.rs @@ -14,7 +14,7 @@ use serde::Deserialize; use spin_expressions::Provider; use spin_factors::{anyhow, runtime_config::toml::GetTomlValue}; -use crate::runtime_config::RuntimeConfig; +use spin_factor_variables::runtime_config::RuntimeConfig; /// Resolves a runtime configuration for the variables factor from a TOML table. pub fn runtime_config_from_toml(table: &impl GetTomlValue) -> anyhow::Result { diff --git a/crates/factor-variables/src/spin_cli/statik.rs b/crates/variables/src/statik.rs similarity index 100% rename from crates/factor-variables/src/spin_cli/statik.rs rename to crates/variables/src/statik.rs diff --git a/crates/factor-variables/src/spin_cli/vault.rs b/crates/variables/src/vault.rs similarity index 100% rename from crates/factor-variables/src/spin_cli/vault.rs rename to crates/variables/src/vault.rs