diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index cf3f2b89bf505..dcf5d50dad156 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -713c8c6edc0709aef2a7d2d0d7f353c3fe3b88a0 \ No newline at end of file +8488e5f2589c5979b37c736ccf0e394ea10c17bd \ No newline at end of file diff --git a/backend/windmill-api/src/postgres_triggers/mod.rs b/backend/windmill-api/src/postgres_triggers/mod.rs index 94a4a5036cff7..ecde3ee4d8203 100644 --- a/backend/windmill-api/src/postgres_triggers/mod.rs +++ b/backend/windmill-api/src/postgres_triggers/mod.rs @@ -1,7 +1,7 @@ use crate::{ db::{ApiAuthed, DB}, jobs::{run_flow_by_path_inner, run_script_by_path_inner, RunJobQuery}, - variables::get_resource, + resources::try_get_resource_from_db_as, users::fetch_api_authed, }; use chrono::Utc; @@ -54,7 +54,7 @@ pub async fn get_database_connection( postgres_resource_path: &str, w_id: &str, ) -> std::result::Result { - let database = get_resource::(authed, user_db, db, postgres_resource_path, w_id).await?; + let database = try_get_resource_from_db_as::(authed, user_db, db, postgres_resource_path, w_id).await?; Ok(get_raw_postgres_connection(&database).await?) } diff --git a/backend/windmill-api/src/postgres_triggers/trigger.rs b/backend/windmill-api/src/postgres_triggers/trigger.rs index dc3dab6ac2c3e..b4157902d54cd 100644 --- a/backend/windmill-api/src/postgres_triggers/trigger.rs +++ b/backend/windmill-api/src/postgres_triggers/trigger.rs @@ -11,7 +11,7 @@ use crate::{ }, run_job, }, - users::fetch_api_authed, variables::get_resource, + users::fetch_api_authed, resources::try_get_resource_from_db_as, }; use bytes::{BufMut, Bytes, BytesMut}; use chrono::TimeZone; @@ -450,7 +450,7 @@ impl PostgresConfig { PostgresConfig::Capture(capture) => capture.fetch_authed(db).await?, }; - let database = get_resource::( + let database = try_get_resource_from_db_as::( authed, Some(UserDB::new(db.clone())), &db, diff --git a/backend/windmill-api/src/resources.rs b/backend/windmill-api/src/resources.rs index 3e60a61763d89..d2bf3d34b6b74 100644 --- a/backend/windmill-api/src/resources.rs +++ b/backend/windmill-api/src/resources.rs @@ -1207,3 +1207,44 @@ async fn update_resource_type( Ok(format!("resource_type {} updated", name)) } + +#[cfg(any( + feature = "postgres_trigger", + all(feature = "sqs_trigger", feature = "enterprise") +))] +pub async fn try_get_resource_from_db_as( + authed: ApiAuthed, + user_db: Option, + db: &DB, + resource_path: &str, + w_id: &str, +) -> Result +where + T: serde::de::DeserializeOwned, +{ + let resource = get_resource_value_interpolated_internal( + &authed, + user_db, + &db, + &w_id, + &resource_path, + None, + "", + ) + .await?; + + let resource = match resource { + Some(resource) => serde_json::from_value::(resource) + .map_err(|e| Error::SerdeJson { error: e, location: "variable.rs".to_string() })?, + None => { + return { + Err(Error::NotFound(format!( + "resource at path :{} do not exist", + &resource_path + ))) + } + } + }; + + Ok(resource) +} diff --git a/backend/windmill-api/src/variables.rs b/backend/windmill-api/src/variables.rs index 71735c86b625f..475fe7db98cdf 100644 --- a/backend/windmill-api/src/variables.rs +++ b/backend/windmill-api/src/variables.rs @@ -8,7 +8,6 @@ use crate::{ db::{ApiAuthed, DB}, - resources::get_resource_value_interpolated_internal, users::{maybe_refresh_folders, require_owner_of_path}, webhook_util::{WebhookMessage, WebhookShared}, }; @@ -32,7 +31,7 @@ use windmill_common::{ }; use lazy_static::lazy_static; -use serde::{de::DeserializeOwned, Deserialize}; +use serde::Deserialize; use sqlx::{Postgres, Transaction}; use windmill_common::variables::{decrypt, encrypt}; use windmill_git_sync::{handle_deployment_metadata, DeployedObject}; @@ -702,41 +701,3 @@ pub async fn get_variable_or_self(path: String, db: &DB, w_id: &str) -> Result( - authed: ApiAuthed, - user_db: Option, - db: &DB, - resource_path: &str, - w_id: &str, -) -> Result -where - T: DeserializeOwned, -{ - let resource = get_resource_value_interpolated_internal( - &authed, - user_db, - &db, - &w_id, - &resource_path, - None, - "", - ) - .await?; - - let resource = match resource { - Some(resource) => serde_json::from_value::(resource) - .map_err(|e| Error::SerdeJson { error: e, location: "variable.rs".to_string() })?, - None => { - return { - Err(Error::NotFound(format!( - "resource at path :{} do not exist", - &resource_path - ))) - } - } - }; - - Ok(resource) -}