From 00faf1eefecb9113ebfffcc7e03ec88784b75ea1 Mon Sep 17 00:00:00 2001 From: dieriba Date: Mon, 12 May 2025 11:00:55 +0200 Subject: [PATCH] nits: use generic deserializer for empty data (#5727) * use generic deserializer for empty data * update repo ref * fix import --- backend/ee-repo-ref.txt | 2 +- backend/src/monitor.rs | 10 ++++---- backend/windmill-api/src/capture.rs | 6 ++--- backend/windmill-api/src/gcp_triggers_ee.rs | 8 +++---- backend/windmill-common/src/auth.rs | 6 ++--- backend/windmill-common/src/utils.rs | 23 +++++++++++++++---- backend/windmill-worker/src/mssql_executor.rs | 6 ++--- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 1e7c10394e..9600e384bf 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -4cc3cbd0f0536a2fa4814d98ec058f998044a70b +4dc1f25f4fcc013334d4cc1d07cbe60a22b56d1f \ No newline at end of file diff --git a/backend/src/monitor.rs b/backend/src/monitor.rs index b7ae065f43..cf04ff8c32 100644 --- a/backend/src/monitor.rs +++ b/backend/src/monitor.rs @@ -60,7 +60,7 @@ use windmill_common::{ server::load_smtp_config, tracing_init::JSON_FMT, users::truncate_token, - utils::{empty_string_as_none, now_from_db, rd_string, report_critical_error, Mode}, + utils::{empty_as_none, now_from_db, rd_string, report_critical_error, Mode}, worker::{ load_env_vars, load_init_bash_from_env, load_whitelist_env_vars_from_env, load_worker_config, reload_custom_tags_setting, store_pull_query, store_suspended_pull_query, update_min_version, Connection, WorkerConfig, DEFAULT_TAGS_PER_WORKSPACE, DEFAULT_TAGS_WORKSPACES, INDEXER_CONFIG, SCRIPT_TOKEN_EXPIRY, SMTP_CONFIG, TMP_DIR, WORKER_CONFIG, WORKER_GROUP }, @@ -280,13 +280,13 @@ struct OtelSetting { metrics_enabled: Option, logs_enabled: Option, tracing_enabled: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] otel_exporter_otlp_endpoint: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] otel_exporter_otlp_headers: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] otel_exporter_otlp_protocol: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] otel_exporter_otlp_compression: Option, } diff --git a/backend/windmill-api/src/capture.rs b/backend/windmill-api/src/capture.rs index d296c7b2cc..0c3840adc4 100644 --- a/backend/windmill-api/src/capture.rs +++ b/backend/windmill-api/src/capture.rs @@ -30,7 +30,7 @@ use { axum::extract::Request, http::HeaderMap, serde::de::DeserializeOwned, - windmill_common::{error::Error, utils::empty_string_as_none}, + windmill_common::{error::Error, utils::empty_as_none}, }; #[cfg(all(feature = "enterprise", feature = "kafka"))] @@ -162,9 +162,9 @@ pub struct SqsTriggerConfig { pub struct GcpTriggerConfig { pub gcp_resource_path: String, pub subscription_mode: SubscriptionMode, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] pub subscription_id: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] pub base_endpoint: Option, #[serde(flatten)] pub create_update: Option, diff --git a/backend/windmill-api/src/gcp_triggers_ee.rs b/backend/windmill-api/src/gcp_triggers_ee.rs index 2e38d96423..bdf98c9bb9 100644 --- a/backend/windmill-api/src/gcp_triggers_ee.rs +++ b/backend/windmill-api/src/gcp_triggers_ee.rs @@ -11,7 +11,7 @@ use windmill_common::db::UserDB; use windmill_common::worker::to_raw_value; use windmill_common::{ error::{Error as WindmillError, Result as WindmillResult}, - utils::empty_string_as_none, + utils::empty_as_none, }; use windmill_queue::TriggerKind; @@ -33,9 +33,9 @@ impl Default for DeliveryType { #[derive(FromRow, Deserialize, Serialize, Debug)] #[allow(unused)] pub struct PushConfig { - #[serde(deserialize_with = "empty_string_as_none")] + #[serde(deserialize_with = "empty_as_none")] route_path: Option, - #[serde(deserialize_with = "empty_string_as_none")] + #[serde(deserialize_with = "empty_as_none")] audience: Option, authenticate: bool, base_endpoint: String, @@ -44,7 +44,7 @@ pub struct PushConfig { #[allow(unused)] pub struct CreateUpdateConfig { pub delivery_type: DeliveryType, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] pub subscription_id: Option, pub delivery_config: Option>, } diff --git a/backend/windmill-common/src/auth.rs b/backend/windmill-common/src/auth.rs index 9d1ee74675..5823fccf7c 100644 --- a/backend/windmill-common/src/auth.rs +++ b/backend/windmill-common/src/auth.rs @@ -317,7 +317,7 @@ pub mod aws { use crate::error::to_anyhow; use super::*; - use crate::utils::empty_string_as_none; + use crate::utils::empty_as_none; use aws_config::{BehaviorVersion, Region}; use aws_sdk_sts::{ config::Credentials as AwsCredentials, @@ -363,7 +363,7 @@ pub mod aws { #[derive(Debug, Deserialize)] pub struct CredentialsAuth { - #[serde(deserialize_with = "empty_string_as_none")] + #[serde(deserialize_with = "empty_as_none")] pub region: Option, #[serde(rename = "awsAccessKeyId")] pub aws_access_key_id: String, @@ -374,7 +374,7 @@ pub mod aws { #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "snake_case")] pub struct OidcAuth { - #[serde(deserialize_with = "empty_string_as_none")] + #[serde(deserialize_with = "empty_as_none")] pub region: Option, #[serde(rename = "roleArn")] pub role_arn: String, diff --git a/backend/windmill-common/src/utils.rs b/backend/windmill-common/src/utils.rs index ff3aea9a19..981b71eccf 100644 --- a/backend/windmill-common/src/utils.rs +++ b/backend/windmill-common/src/utils.rs @@ -471,13 +471,28 @@ pub async fn report_recovered_critical_error( } } -pub fn empty_string_as_none<'de, D>( - deserializer: D, -) -> std::result::Result, D::Error> +pub trait IsEmpty { + fn is_empty(&self) -> bool; +} + +impl IsEmpty for String { + fn is_empty(&self) -> bool { + self.is_empty() + } +} + +impl IsEmpty for Vec { + fn is_empty(&self) -> bool { + self.is_empty() + } +} + +pub fn empty_as_none<'de, D, T>(deserializer: D) -> std::result::Result, D::Error> where D: Deserializer<'de>, + T: Deserialize<'de> + IsEmpty, { - let option = as serde::Deserialize>::deserialize(deserializer)?; + let option = as serde::Deserialize>::deserialize(deserializer)?; Ok(option.filter(|s| !s.is_empty())) } diff --git a/backend/windmill-worker/src/mssql_executor.rs b/backend/windmill-worker/src/mssql_executor.rs index d827e57095..303685595b 100644 --- a/backend/windmill-worker/src/mssql_executor.rs +++ b/backend/windmill-worker/src/mssql_executor.rs @@ -10,7 +10,7 @@ use tokio_util::compat::TokioAsyncWriteCompatExt; use uuid::Uuid; use windmill_common::{ error::{self, to_anyhow, Error}, - utils::empty_string_as_none, + utils::empty_as_none, worker::{to_raw_value, Connection}, }; use windmill_parser_sql::{parse_db_resource, parse_mssql_sig}; @@ -35,13 +35,13 @@ struct MssqlDatabase { #[serde(default, deserialize_with = "deserialize_aad_token")] aad_token: Option, trust_cert: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] ca_cert: Option, } #[derive(Debug, Deserialize)] struct AadToken { - #[serde(default, deserialize_with = "empty_string_as_none")] + #[serde(default, deserialize_with = "empty_as_none")] token: Option, }