Skip to content

Commit b18a5c3

Browse files
committed
bridge: Rename sender and receiver config and add some docs
1 parent 333f591 commit b18a5c3

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

bridge/svix-bridge/src/config/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ use tracing::Level;
1919
#[derive(Deserialize)]
2020
#[serde(deny_unknown_fields)]
2121
pub struct Config {
22+
/// Config for reading messages from plugins and forwarding to Svix.
2223
#[serde(default)]
23-
pub senders: Vec<SenderConfig>,
24+
pub senders: Vec<WebhookSenderConfig>,
25+
/// Config for receiving webhooks and forwarding them to plugins.
2426
#[serde(default)]
25-
pub receivers: Vec<ReceiverConfig>,
27+
pub receivers: Vec<WebhookReceiverConfig>,
2628
/// The log level to run the service with. Supported: info, debug, trace
2729
#[serde(default)]
2830
pub log_level: LogLevel,
@@ -141,9 +143,10 @@ pub enum LogFormat {
141143
Json,
142144
}
143145

146+
/// Config for reading messages from plugins and forwarding to Svix.
144147
#[derive(Deserialize)]
145148
#[serde(untagged)]
146-
pub enum SenderConfig {
149+
pub enum WebhookSenderConfig {
147150
#[cfg(any(
148151
feature = "gcp-pubsub",
149152
feature = "rabbitmq",
@@ -153,36 +156,37 @@ pub enum SenderConfig {
153156
Queue(QueueSenderConfig),
154157
}
155158

156-
impl SenderConfig {
159+
impl WebhookSenderConfig {
157160
pub fn name(&self) -> &str {
158161
match self {
159-
SenderConfig::Queue(cfg) => &cfg.name,
162+
WebhookSenderConfig::Queue(cfg) => &cfg.name,
160163
}
161164
}
162165
pub fn transformation(&self) -> Option<&TransformationConfig> {
163166
match self {
164-
SenderConfig::Queue(cfg) => cfg.transformation.as_ref(),
167+
WebhookSenderConfig::Queue(cfg) => cfg.transformation.as_ref(),
165168
}
166169
}
167170
}
168171

169-
impl TryFrom<SenderConfig> for Box<dyn SenderInput> {
172+
impl TryFrom<WebhookSenderConfig> for Box<dyn SenderInput> {
170173
type Error = &'static str;
171-
fn try_from(value: SenderConfig) -> Result<Self, Self::Error> {
174+
fn try_from(value: WebhookSenderConfig) -> Result<Self, Self::Error> {
172175
match value {
173176
#[cfg(any(
174177
feature = "gcp-pubsub",
175178
feature = "rabbitmq",
176179
feature = "redis",
177180
feature = "sqs"
178181
))]
179-
SenderConfig::Queue(backend) => backend.into_sender_input(),
182+
WebhookSenderConfig::Queue(backend) => backend.into_sender_input(),
180183
}
181184
}
182185
}
183186

187+
/// Config for receiving webhooks and forwarding them to plugins.
184188
#[derive(Deserialize)]
185-
pub struct ReceiverConfig {
189+
pub struct WebhookReceiverConfig {
186190
pub name: String,
187191
pub input: ReceiverInputOpts,
188192
#[serde(default)]
@@ -202,7 +206,7 @@ pub enum ReceiverOut {
202206
Queue(QueueOutOpts),
203207
}
204208

205-
impl ReceiverConfig {
209+
impl WebhookReceiverConfig {
206210
pub async fn into_receiver_output(self) -> std::io::Result<Box<dyn ReceiverOutput>> {
207211
match self.output {
208212
ReceiverOut::Queue(x) => {

bridge/svix-bridge/src/config/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use svix_bridge_plugin_queue::config::{QueueSenderConfig, RabbitMqInputOpts, Sen
44
use svix_bridge_types::{SenderOutputOpts, SvixSenderOutputOpts};
55

66
use super::Config;
7-
use crate::config::{LogFormat, LogLevel, SenderConfig};
7+
use crate::config::{LogFormat, LogLevel, WebhookSenderConfig};
88

99
/// This is meant to be a kitchen sink config, hitting as many possible
1010
/// configuration options as possible to ensure they parse correctly.
@@ -241,7 +241,7 @@ receivers:
241241

242242
#[test]
243243
fn test_sender_parses_ok() {
244-
let conf: Result<SenderConfig, _> = serde_yaml::from_str(
244+
let conf: Result<WebhookSenderConfig, _> = serde_yaml::from_str(
245245
r#"
246246
name: "from-rabbit-local-to-svix"
247247
input:
@@ -260,7 +260,7 @@ output:
260260

261261
#[test]
262262
fn test_senders_parses_ok() {
263-
let conf: Result<Vec<SenderConfig>, _> = serde_yaml::from_str(
263+
let conf: Result<Vec<WebhookSenderConfig>, _> = serde_yaml::from_str(
264264
r#"
265265
266266
- name: "from-rabbit-local-to-svix"
@@ -455,7 +455,7 @@ fn test_variable_substitution_repeated_lookups() {
455455
vars.insert(String::from("SVIX_TOKEN"), String::from("x"));
456456
let cfg = Config::from_src(src, Some(&vars)).unwrap();
457457

458-
if let SenderConfig::Queue(QueueSenderConfig {
458+
if let WebhookSenderConfig::Queue(QueueSenderConfig {
459459
input:
460460
SenderInputOpts::RabbitMQ(RabbitMqInputOpts {
461461
uri, queue_name, ..
@@ -471,7 +471,7 @@ fn test_variable_substitution_repeated_lookups() {
471471
panic!("sender did not match expected pattern");
472472
}
473473

474-
if let SenderConfig::Queue(QueueSenderConfig {
474+
if let WebhookSenderConfig::Queue(QueueSenderConfig {
475475
input:
476476
SenderInputOpts::RabbitMQ(RabbitMqInputOpts {
477477
uri, queue_name, ..

bridge/svix-bridge/src/webhook_receiver/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::Deserialize;
22
use svix_bridge_types::{TransformationConfig, WebhookVerifier};
33

4-
use crate::config::ReceiverConfig;
4+
use crate::config::WebhookReceiverConfig;
55

66
/// The [`IntegrationConfig`] is the struct associated with a given [`IntegrationId`]. When the route
77
/// associated with an [`IntegrationId`] receives a webhook, or any other HTTP request, then it will
@@ -11,7 +11,7 @@ use crate::config::ReceiverConfig;
1111
#[derive(Deserialize)]
1212
#[allow(dead_code)]
1313
pub struct IntegrationConfig {
14-
pub receiver_cfg: ReceiverConfig,
14+
pub receiver_cfg: WebhookReceiverConfig,
1515
pub verification: WebhookVerifier,
1616
#[serde(default)]
1717
pub transformation: Option<TransformationConfig>,

bridge/svix-bridge/src/webhook_receiver/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use svix_bridge_types::{
1313
use tracing::instrument;
1414
use types::{IntegrationId, IntegrationState, InternalState, SerializableRequest, Unvalidated};
1515

16-
use crate::{config::ReceiverConfig, webhook_receiver::types::SerializablePayload};
16+
use crate::{config::WebhookReceiverConfig, webhook_receiver::types::SerializablePayload};
1717

1818
mod config;
1919
mod types;
@@ -33,7 +33,7 @@ fn router() -> Router<InternalState, Body> {
3333

3434
pub async fn run(
3535
listen_addr: SocketAddr,
36-
routes: Vec<ReceiverConfig>,
36+
routes: Vec<WebhookReceiverConfig>,
3737
transformer_tx: TransformerTx,
3838
) -> std::io::Result<()> {
3939
let state = InternalState::from_receiver_configs(routes, transformer_tx)

bridge/svix-bridge/src/webhook_receiver/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use svix_bridge_types::{
1414
};
1515

1616
use super::verification::{NoVerifier, SvixVerifier, VerificationMethod, Verifier};
17-
use crate::config::ReceiverConfig;
17+
use crate::config::WebhookReceiverConfig;
1818

1919
#[derive(Clone)]
2020
/// The [`InternalState`] is passed to the Axum route and is used to map the "IntegrationId" in the
@@ -50,7 +50,7 @@ impl InternalState {
5050
}
5151

5252
pub async fn from_receiver_configs(
53-
routes: Vec<ReceiverConfig>,
53+
routes: Vec<WebhookReceiverConfig>,
5454
transformer_tx: TransformerTx,
5555
) -> Result<Self> {
5656
let mut state_map = HashMap::new();

0 commit comments

Comments
 (0)