spin_factor_outbound_redis/
lib.rs

1mod host;
2
3use host::InstanceState;
4use spin_factor_outbound_networking::OutboundNetworkingFactor;
5use spin_factors::{
6    anyhow, ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
7};
8
9/// The [`Factor`] for `fermyon:spin/outbound-redis`.
10#[derive(Default)]
11pub struct OutboundRedisFactor {
12    _priv: (),
13}
14
15impl OutboundRedisFactor {
16    pub fn new() -> Self {
17        Self::default()
18    }
19}
20
21impl Factor for OutboundRedisFactor {
22    type RuntimeConfig = ();
23    type AppState = ();
24    type InstanceBuilder = InstanceState;
25
26    fn init<T: Send + 'static>(
27        &mut self,
28        mut ctx: spin_factors::InitContext<T, Self>,
29    ) -> anyhow::Result<()> {
30        ctx.link_bindings(spin_world::v1::redis::add_to_linker)?;
31        ctx.link_bindings(spin_world::v2::redis::add_to_linker)?;
32        Ok(())
33    }
34
35    fn configure_app<T: RuntimeFactors>(
36        &self,
37        _ctx: ConfigureAppContext<T, Self>,
38    ) -> anyhow::Result<Self::AppState> {
39        Ok(())
40    }
41
42    fn prepare<T: RuntimeFactors>(
43        &self,
44        mut ctx: PrepareContext<T, Self>,
45    ) -> anyhow::Result<Self::InstanceBuilder> {
46        let allowed_hosts = ctx
47            .instance_builder::<OutboundNetworkingFactor>()?
48            .allowed_hosts();
49        Ok(InstanceState {
50            allowed_hosts,
51            connections: spin_resource_table::Table::new(1024),
52        })
53    }
54}
55
56impl SelfInstanceBuilder for InstanceState {}