Skip to content

Make config type, variant names less confusing #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bridge/svix-bridge-plugin-queue/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub use crate::{
};

#[derive(Deserialize)]
pub struct QueueConsumerConfig {
pub struct QueueSenderConfig {
pub name: String,
pub input: SenderInputOpts,
#[serde(default)]
pub transformation: Option<TransformationConfig>,
pub output: SenderOutputOpts,
}

impl QueueConsumerConfig {
impl QueueSenderConfig {
pub fn into_sender_input(self) -> Result<Box<dyn SenderInput>, &'static str> {
// FIXME: see if this check is still needed. String transforms worked for the omniqueue redis receiver, I think?
if matches!(self.input, SenderInputOpts::Redis(_))
Expand Down Expand Up @@ -92,7 +92,7 @@ mod tests {
SenderOutputOpts, SvixSenderOutputOpts, TransformationConfig, TransformerInputFormat,
};

use super::{into_receiver_output, QueueConsumerConfig};
use super::{into_receiver_output, QueueSenderConfig};
use crate::{
config::{ReceiverOutputOpts, SenderInputOpts},
redis::{RedisInputOpts, RedisOutputOpts},
Expand All @@ -102,7 +102,7 @@ mod tests {
// Revisit after `omniqueue` adoption.
#[test]
fn redis_sender_with_string_transformation_is_err() {
let cfg = QueueConsumerConfig {
let cfg = QueueSenderConfig {
name: "redis-with-string-transformation".to_string(),
input: SenderInputOpts::Redis(RedisInputOpts {
dsn: "".to_string(),
Expand Down
3 changes: 1 addition & 2 deletions bridge/svix-bridge-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ pub enum WebhookVerifier {
}

#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum ReceiverInputOpts {
Webhook {
path_id: String,
#[serde(default)]
verification: WebhookVerifier,
},
#[serde(rename = "svix-webhook")]
SvixWebhook {
path_id: String,
endpoint_secret: String,
Expand Down
14 changes: 7 additions & 7 deletions bridge/svix-bridge/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use serde::Deserialize;
use shellexpand::LookupError;
use svix_bridge_plugin_queue::config::{
into_receiver_output, QueueConsumerConfig, ReceiverOutputOpts as QueueOutOpts,
into_receiver_output, QueueSenderConfig, ReceiverOutputOpts as QueueOutOpts,
};
use svix_bridge_types::{ReceiverInputOpts, ReceiverOutput, SenderInput, TransformationConfig};
use tracing::Level;
Expand Down Expand Up @@ -150,18 +150,18 @@ pub enum SenderConfig {
feature = "redis",
feature = "sqs"
))]
QueueConsumer(QueueConsumerConfig),
Queue(QueueSenderConfig),
}

impl SenderConfig {
pub fn name(&self) -> &str {
match self {
SenderConfig::QueueConsumer(cfg) => &cfg.name,
SenderConfig::Queue(cfg) => &cfg.name,
}
}
pub fn transformation(&self) -> Option<&TransformationConfig> {
match self {
SenderConfig::QueueConsumer(cfg) => cfg.transformation.as_ref(),
SenderConfig::Queue(cfg) => cfg.transformation.as_ref(),
}
}
}
Expand All @@ -176,7 +176,7 @@ impl TryFrom<SenderConfig> for Box<dyn SenderInput> {
feature = "redis",
feature = "sqs"
))]
SenderConfig::QueueConsumer(backend) => backend.into_sender_input(),
SenderConfig::Queue(backend) => backend.into_sender_input(),
}
}
}
Expand All @@ -199,13 +199,13 @@ pub enum ReceiverOut {
feature = "redis",
feature = "sqs"
))]
QueueProducer(QueueOutOpts),
Queue(QueueOutOpts),
}

impl ReceiverConfig {
pub async fn into_receiver_output(self) -> std::io::Result<Box<dyn ReceiverOutput>> {
match self.output {
ReceiverOut::QueueProducer(x) => {
ReceiverOut::Queue(x) => {
into_receiver_output(self.name.clone(), x, self.transformation.as_ref())
.await
.map_err(Into::into)
Expand Down
8 changes: 4 additions & 4 deletions bridge/svix-bridge/src/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use svix_bridge_plugin_queue::config::{QueueConsumerConfig, RabbitMqInputOpts, SenderInputOpts};
use svix_bridge_plugin_queue::config::{QueueSenderConfig, RabbitMqInputOpts, SenderInputOpts};
use svix_bridge_types::{SenderOutputOpts, SvixSenderOutputOpts};

use super::Config;
Expand Down Expand Up @@ -340,7 +340,7 @@ fn test_senders_example() {
#[test]
fn test_variable_substitution_missing_vars() {
let src = r#"
opentelemetry:
opentelemetry:
address: "${OTEL_ADDR}"
"#;
let vars = HashMap::new();
Expand Down Expand Up @@ -455,7 +455,7 @@ fn test_variable_substitution_repeated_lookups() {
vars.insert(String::from("SVIX_TOKEN"), String::from("x"));
let cfg = Config::from_src(src, Some(&vars)).unwrap();

if let SenderConfig::QueueConsumer(QueueConsumerConfig {
if let SenderConfig::Queue(QueueSenderConfig {
input:
SenderInputOpts::RabbitMQ(RabbitMqInputOpts {
uri, queue_name, ..
Expand All @@ -471,7 +471,7 @@ fn test_variable_substitution_repeated_lookups() {
panic!("sender did not match expected pattern");
}

if let SenderConfig::QueueConsumer(QueueConsumerConfig {
if let SenderConfig::Queue(QueueSenderConfig {
input:
SenderInputOpts::RabbitMQ(RabbitMqInputOpts {
uri, queue_name, ..
Expand Down