Skip to content

Commit dc00a13

Browse files
committed
use sync decrypt
1 parent e726013 commit dc00a13

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

backend/ee-repo-ref.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5011623a1ec6470ec3ce67d7d6abf4ebf0444888
1+
7cc103e5827b1ec91180a5939a9c022a2a1856c6

backend/windmill-api/src/slack_approvals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use windmill_common::{
2323
error::{self, Error},
2424
jobs::JobKind,
2525
scripts::ScriptHash,
26-
variables::{build_crypt, decrypt_value_with_mc},
26+
variables::{build_crypt, decrypt},
2727
};
2828

2929
#[derive(Deserialize, Debug)]
@@ -853,7 +853,7 @@ async fn get_slack_token(db: &DB, slack_resource_path: &str, w_id: &str) -> anyh
853853

854854
if slack_token.is_secret {
855855
let mc = build_crypt(&db, w_id).await?;
856-
let bot_token = decrypt_value_with_mc(slack_token.value, mc).await?;
856+
let bot_token = decrypt(&mc, slack_token.value)?;
857857
Ok(bot_token)
858858
} else {
859859
Ok(slack_token.value)

backend/windmill-common/src/variables.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* LICENSE-AGPL for a copy of the license.
77
*/
88

9-
use crate::error::Result;
9+
use crate::error;
1010
use crate::{worker::WORKER_GROUP, BASE_URL, DB};
1111
use chrono::{SecondsFormat, Utc};
1212
use magic_crypt::{MagicCrypt256, MagicCryptError, MagicCryptTrait};
1313
use serde::{Deserialize, Serialize};
14-
use crate::error;
1514

1615
lazy_static::lazy_static! {
1716
pub static ref SECRET_SALT: Option<String> = std::env::var("SECRET_SALT").ok();
@@ -134,7 +133,7 @@ pub async fn get_secret_value_as_admin(
134133
let value = variable.value;
135134
if !value.is_empty() {
136135
let mc = build_crypt(db, w_id).await?;
137-
decrypt_value_with_mc(value, mc).await?
136+
decrypt(&mc, value)?
138137
} else {
139138
"".to_string()
140139
}
@@ -145,16 +144,6 @@ pub async fn get_secret_value_as_admin(
145144
Ok(r)
146145
}
147146

148-
pub async fn decrypt_value_with_mc(value: String, mc: MagicCrypt256) -> Result<String> {
149-
mc.decrypt_base64_to_string(value).map_err(|e| match e {
150-
MagicCryptError::DecryptError(_) => crate::error::Error::InternalErr(
151-
"Could not decrypt value. The value may have been encrypted with a different key."
152-
.to_string(),
153-
),
154-
_ => crate::error::Error::InternalErr(e.to_string()),
155-
})
156-
}
157-
158147
pub fn encrypt(mc: &MagicCrypt256, value: &str) -> String {
159148
mc.encrypt_str_to_base64(value)
160149
}

backend/windmill-worker/src/common.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use windmill_common::jobs::ENTRYPOINT_OVERRIDE;
1818
use windmill_common::s3_helpers::{
1919
get_etag_or_empty, LargeFileStorage, ObjectStoreResource, S3Object,
2020
};
21-
use windmill_common::variables::{build_crypt_with_key_suffix, decrypt_value_with_mc};
21+
use windmill_common::variables::{build_crypt_with_key_suffix, decrypt};
2222
use windmill_common::worker::{
2323
to_raw_value, write_file, CLOUD_HOSTED, ROOT_CACHE_DIR, WORKER_CONFIG,
2424
};
@@ -255,11 +255,9 @@ pub async fn transform_json_value(
255255
let encrypted = y.strip_prefix("$encrypted:").unwrap();
256256
let mc =
257257
build_crypt_with_key_suffix(&db, &job.workspace_id, &job.id.to_string()).await?;
258-
decrypt_value_with_mc(encrypted.to_string(), mc)
259-
.await
260-
.and_then(|x| {
261-
serde_json::from_str(&x).map_err(|e| Error::InternalErr(e.to_string()))
262-
})
258+
decrypt(&mc, encrypted.to_string()).and_then(|x| {
259+
serde_json::from_str(&x).map_err(|e| Error::InternalErr(e.to_string()))
260+
})
263261

264262
// let path = y.strip_prefix("$res:").unwrap();
265263
}

0 commit comments

Comments
 (0)