requiring passing new value when updating is_secret

This commit is contained in:
Ruben Fiszel
2023-05-11 08:48:40 +02:00
parent 0006c9d7ad
commit 11227f07f0
2 changed files with 19 additions and 1 deletions
+14
View File
@@ -337,6 +337,7 @@ async fn update_variable(
if let Some(npath) = &ns.path {
sqlb.set_str("path", npath);
}
let ns_value_is_none = ns.value.is_none();
if let Some(nvalue) = ns.value {
let is_secret = if ns.is_secret.is_some() {
ns.is_secret.unwrap()
@@ -365,6 +366,19 @@ async fn update_variable(
}
if let Some(nbool) = ns.is_secret {
let old_secret = sqlx::query_scalar!(
"SELECT is_secret from variable WHERE path = $1 AND workspace_id = $2",
&path,
&w_id
)
.fetch_optional(&mut tx)
.await?
.unwrap_or(false);
if old_secret != nbool && ns_value_is_none {
return Err(Error::BadRequest(
"cannot change is_secret without updating value too".to_string(),
));
}
sqlb.set_str("is_secret", nbool);
}
sqlb.returning("path");
@@ -154,7 +154,11 @@
/>
</div>
<div class="mt-4">
<Toggle bind:checked={variable.is_secret} options={{ right: 'Secret' }} />
<Toggle
on:change={() => variable.is_secret && loadVariable(initialPath)}
bind:checked={variable.is_secret}
options={{ right: 'Secret' }}
/>
<div class="mb-2" />
{#if variable.is_secret}
<Alert type="warning" title="Audit log for each access">