From 1b25410a884f84c1009bf840125c6216398aae92 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Mon, 19 Aug 2024 17:15:38 +0200 Subject: [PATCH] Integrate outbound-redis factor into trigger2 Signed-off-by: Ryan Levick --- Cargo.lock | 2 ++ crates/factor-outbound-redis/src/lib.rs | 12 +++++++++++- .../factor-outbound-redis/tests/factor_test.rs | 2 +- crates/runtime-config/Cargo.toml | 1 + crates/runtime-config/src/lib.rs | 17 ++++++++++++++--- crates/trigger2/Cargo.toml | 1 + crates/trigger2/src/factors.rs | 3 +++ 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 666c856059..d98a72b595 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8158,6 +8158,7 @@ dependencies = [ "spin-factor-key-value-spin", "spin-factor-outbound-http", "spin-factor-outbound-networking", + "spin-factor-outbound-redis", "spin-factor-sqlite", "spin-factor-variables", "spin-factor-wasi", @@ -8468,6 +8469,7 @@ dependencies = [ "spin-factor-key-value", "spin-factor-outbound-http", "spin-factor-outbound-networking", + "spin-factor-outbound-redis", "spin-factor-sqlite", "spin-factor-variables", "spin-factor-wasi", diff --git a/crates/factor-outbound-redis/src/lib.rs b/crates/factor-outbound-redis/src/lib.rs index bcd9830910..c0ff5924d5 100644 --- a/crates/factor-outbound-redis/src/lib.rs +++ b/crates/factor-outbound-redis/src/lib.rs @@ -6,7 +6,17 @@ use spin_factors::{ anyhow, ConfigureAppContext, Factor, InstanceBuilders, PrepareContext, RuntimeFactors, SelfInstanceBuilder, }; -pub struct OutboundRedisFactor; + +/// The [`Factor`] for `fermyon:spin/outbound-redis`. +pub struct OutboundRedisFactor { + _priv: (), +} + +impl OutboundRedisFactor { + pub fn new() -> Self { + Self { _priv: () } + } +} impl Factor for OutboundRedisFactor { type RuntimeConfig = (); diff --git a/crates/factor-outbound-redis/tests/factor_test.rs b/crates/factor-outbound-redis/tests/factor_test.rs index 14c1ee24fb..70a09f0be9 100644 --- a/crates/factor-outbound-redis/tests/factor_test.rs +++ b/crates/factor-outbound-redis/tests/factor_test.rs @@ -18,7 +18,7 @@ async fn no_outbound_hosts_fails() -> anyhow::Result<()> { let factors = TestFactors { variables: VariablesFactor::default(), networking: OutboundNetworkingFactor, - redis: OutboundRedisFactor, + redis: OutboundRedisFactor::new(), }; let env = TestEnvironment::new(factors).extend_manifest(toml! { spin_manifest_version = 2 diff --git a/crates/runtime-config/Cargo.toml b/crates/runtime-config/Cargo.toml index 989793a877..e67129a5e5 100644 --- a/crates/runtime-config/Cargo.toml +++ b/crates/runtime-config/Cargo.toml @@ -17,6 +17,7 @@ spin-factor-key-value-redis = { path = "../factor-key-value-redis" } spin-factor-key-value-azure = { path = "../factor-key-value-azure" } spin-factor-outbound-http = { path = "../factor-outbound-http" } spin-factor-outbound-networking = { path = "../factor-outbound-networking" } +spin-factor-outbound-redis = { path = "../factor-outbound-redis" } spin-factor-sqlite = { path = "../factor-sqlite" } spin-factor-variables = { path = "../factor-variables" } spin-factor-wasi = { path = "../factor-wasi" } diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index 61624133b6..d4df03c73f 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -6,9 +6,10 @@ use spin_factor_key_value::{DefaultLabelResolver as _, KeyValueFactor}; use spin_factor_outbound_http::OutboundHttpFactor; use spin_factor_outbound_networking::runtime_config::spin::SpinTlsRuntimeConfig; use spin_factor_outbound_networking::OutboundNetworkingFactor; +use spin_factor_outbound_redis::OutboundRedisFactor; use spin_factor_sqlite::runtime_config::spin as sqlite; -use spin_factor_variables::{spin_cli as variables, VariablesFactor}; use spin_factor_sqlite::SqliteFactor; +use spin_factor_variables::{spin_cli as variables, VariablesFactor}; use spin_factor_wasi::WasiFactor; use spin_factors::{ runtime_config::toml::TomlKeyTracker, FactorRuntimeConfigSource, RuntimeConfigSourceFinalizer, @@ -148,8 +149,18 @@ impl FactorRuntimeConfigSource for TomlRuntimeConfigSo } impl FactorRuntimeConfigSource for TomlRuntimeConfigSource<'_> { - fn get_runtime_config(&mut self) -> anyhow::Result::RuntimeConfig>> { - Ok(Some(variables::runtime_config_from_toml(self.table.as_ref())?)) + fn get_runtime_config( + &mut self, + ) -> anyhow::Result::RuntimeConfig>> { + Ok(Some(variables::runtime_config_from_toml( + self.table.as_ref(), + )?)) + } +} + +impl FactorRuntimeConfigSource for TomlRuntimeConfigSource<'_> { + fn get_runtime_config(&mut self) -> anyhow::Result> { + Ok(None) } } diff --git a/crates/trigger2/Cargo.toml b/crates/trigger2/Cargo.toml index ab955f5d51..70a7588ac0 100644 --- a/crates/trigger2/Cargo.toml +++ b/crates/trigger2/Cargo.toml @@ -27,6 +27,7 @@ spin-factor-variables = { path = "../factor-variables" } spin-factor-wasi = { path = "../factor-wasi" } spin-factor-key-value = { path = "../factor-key-value" } spin-factor-sqlite = { path = "../factor-sqlite" } +spin-factor-outbound-redis = { path = "../factor-outbound-redis" } spin-factors = { path = "../factors" } spin-factors-executor = { path = "../factors-executor" } spin-telemetry = { path = "../telemetry" } diff --git a/crates/trigger2/src/factors.rs b/crates/trigger2/src/factors.rs index c1bd26a39f..897151863f 100644 --- a/crates/trigger2/src/factors.rs +++ b/crates/trigger2/src/factors.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use spin_factor_key_value::KeyValueFactor; use spin_factor_outbound_http::OutboundHttpFactor; use spin_factor_outbound_networking::OutboundNetworkingFactor; +use spin_factor_outbound_redis::OutboundRedisFactor; use spin_factor_sqlite::SqliteFactor; use spin_factor_variables::VariablesFactor; use spin_factor_wasi::{spin::SpinFilesMounter, WasiFactor}; @@ -17,6 +18,7 @@ pub struct TriggerFactors { pub outbound_networking: OutboundNetworkingFactor, pub outbound_http: OutboundHttpFactor, pub sqlite: SqliteFactor, + pub redis: OutboundRedisFactor, } impl TriggerFactors { @@ -34,6 +36,7 @@ impl TriggerFactors { outbound_networking: OutboundNetworkingFactor, outbound_http: OutboundHttpFactor, sqlite: SqliteFactor::new(default_sqlite_label_resolver), + redis: OutboundRedisFactor::new(), } } }