nits: use generic deserializer for empty data (#5727)

* use generic deserializer for empty data

* update repo ref

* fix import
This commit is contained in:
dieriba
2025-05-12 11:00:55 +02:00
committed by GitHub
parent eca587ddf4
commit 00faf1eefe
7 changed files with 38 additions and 23 deletions
+1 -1
View File
@@ -1 +1 @@
4cc3cbd0f0536a2fa4814d98ec058f998044a70b
4dc1f25f4fcc013334d4cc1d07cbe60a22b56d1f
+5 -5
View File
@@ -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<bool>,
logs_enabled: Option<bool>,
tracing_enabled: Option<bool>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
otel_exporter_otlp_endpoint: Option<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
otel_exporter_otlp_headers: Option<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
otel_exporter_otlp_protocol: Option<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
otel_exporter_otlp_compression: Option<String>,
}
+3 -3
View File
@@ -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<String>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
pub base_endpoint: Option<String>,
#[serde(flatten)]
pub create_update: Option<CreateUpdateConfig>,
+4 -4
View File
@@ -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<String>,
#[serde(deserialize_with = "empty_string_as_none")]
#[serde(deserialize_with = "empty_as_none")]
audience: Option<String>,
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<String>,
pub delivery_config: Option<SqlxJson<PushConfig>>,
}
+3 -3
View File
@@ -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<String>,
#[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<String>,
#[serde(rename = "roleArn")]
pub role_arn: String,
+19 -4
View File
@@ -471,13 +471,28 @@ pub async fn report_recovered_critical_error(
}
}
pub fn empty_string_as_none<'de, D>(
deserializer: D,
) -> std::result::Result<Option<String>, D::Error>
pub trait IsEmpty {
fn is_empty(&self) -> bool;
}
impl IsEmpty for String {
fn is_empty(&self) -> bool {
self.is_empty()
}
}
impl<T> IsEmpty for Vec<T> {
fn is_empty(&self) -> bool {
self.is_empty()
}
}
pub fn empty_as_none<'de, D, T>(deserializer: D) -> std::result::Result<Option<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + IsEmpty,
{
let option = <Option<String> as serde::Deserialize>::deserialize(deserializer)?;
let option = <Option<T> as serde::Deserialize>::deserialize(deserializer)?;
Ok(option.filter(|s| !s.is_empty()))
}
@@ -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<AadToken>,
trust_cert: Option<bool>,
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
ca_cert: Option<String>,
}
#[derive(Debug, Deserialize)]
struct AadToken {
#[serde(default, deserialize_with = "empty_string_as_none")]
#[serde(default, deserialize_with = "empty_as_none")]
token: Option<String>,
}