Skip to content

Commit

Permalink
update to match ee repo changement
Browse files Browse the repository at this point in the history
  • Loading branch information
dieriba committed Feb 12, 2025
1 parent f1fa83b commit 2b12d84
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion backend/ee-repo-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
713c8c6edc0709aef2a7d2d0d7f353c3fe3b88a0
8488e5f2589c5979b37c736ccf0e394ea10c17bd
4 changes: 2 additions & 2 deletions backend/windmill-api/src/postgres_triggers/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,7 +54,7 @@ pub async fn get_database_connection(
postgres_resource_path: &str,
w_id: &str,
) -> std::result::Result<PgConnection, windmill_common::error::Error> {
let database = get_resource::<Postgres>(authed, user_db, db, postgres_resource_path, w_id).await?;
let database = try_get_resource_from_db_as::<Postgres>(authed, user_db, db, postgres_resource_path, w_id).await?;

Ok(get_raw_postgres_connection(&database).await?)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/windmill-api/src/postgres_triggers/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -450,7 +450,7 @@ impl PostgresConfig {
PostgresConfig::Capture(capture) => capture.fetch_authed(db).await?,
};

let database = get_resource::<Postgres>(
let database = try_get_resource_from_db_as::<Postgres>(
authed,
Some(UserDB::new(db.clone())),
&db,
Expand Down
41 changes: 41 additions & 0 deletions backend/windmill-api/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
authed: ApiAuthed,
user_db: Option<UserDB>,
db: &DB,
resource_path: &str,
w_id: &str,
) -> Result<T>
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::<T>(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)
}
41 changes: 1 addition & 40 deletions backend/windmill-api/src/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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};
Expand Down Expand Up @@ -702,41 +701,3 @@ pub async fn get_variable_or_self(path: String, db: &DB, w_id: &str) -> Result<S

Ok(value)
}

#[allow(dead_code)]
pub async fn get_resource<T>(
authed: ApiAuthed,
user_db: Option<UserDB>,
db: &DB,
resource_path: &str,
w_id: &str,
) -> Result<T>
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::<T>(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)
}

0 comments on commit 2b12d84

Please sign in to comment.