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