mirror of
https://github.com/moghtech/komodo.git
synced 2026-05-02 09:34:38 -05:00
* start 1.19.4 * deploy 1.19.4-dev-1 * try smaller binaries with cargo strip * deploy 1.19.4-dev-2 * smaller binaries with cargo strip * Fix Submit Dialog Button Behavior with 500 Errors on Duplicate Names (#819) * Implement enhanced error handling and messaging for resource creation * Implement improved error handling for resource creation across alerter, build, and sync * Implement error handling improvements for resource copying and validation feedback * Adjust error handling for resource creation to distinguish validation errors from unexpected system errors * Refactor resource creation error handling by removing redundant match statements and simplifying the error propagation in multiple API modules. * fmt * bump indexmap * fix account selector showing empty when account no longer found * clean up theme logic, ensure monaco and others get up to date current theme * enforce disable_non_admin_create for tags. Clean up status code responses * update server cache concurrency controller * deploy 1.19.4-dev-3 * Allow signing in by pressing enter (#830) * Improve dialog overflow handling to prevent clipping of content (#828) * Add Email notification entry to community.md (#824) * Add clickable file path to show/hide file contents in StackInfo (#827) * add clickable file path to show/hide file contents in StackInfo Also added CopyButton due to the new functionality making the file path not selectable. * Move clicking interaction to CardHeader * Avoid sync edge cases of having toggle show function capturing showContents from outside Co-authored-by: Maxwell Becker <49575486+mbecker20@users.noreply.github.com> * Format previous change * Add `default_show_contents` to `handleToggleShow` --------- Co-authored-by: Maxwell Becker <49575486+mbecker20@users.noreply.github.com> * deploy 1.19.4-dev-4 * avoid stake info ShowHideButton double toggle * Allow multiple simultaneous Action runs for use with Args * deploy 1.19.4-dev-5 * feat: persist all table sorting states including unsorted (#832) - Always save sorting state to localStorage, even when empty/unsorted - Fixes issue where 'unsorted' state was not persisted across page reloads - Ensures consistent and predictable sorting behavior for all DataTable components * autofocus on login username field (#837) * Fix unnecessary auth queries flooding console on login page (#842) * Refactor authentication error handling to use serror::Result and status codes * Enable user query only when JWT is present * Enable query execution in useRead only if JWT is present * Revert backend auth changes - keep PR focused on frontend only * Fix unnecessary API queries to unreachable servers flooding console (#843) * Implement server availability checks in various components * Refactor server availability check to ensure only healthy servers are identified * cargo fmt * fmt * Auth error handling with status codes (#841) * Refactor authentication error handling to use serror::Result and status codes * Refactor error messages * Refactor authentication error handling to include status codes and improve error messages * clean up * clean * fmt * invalid user id also UNAUTHORIZED * deploy 1.19.4-dev-6 * deploy 1.19.4-dev-7 --------- Co-authored-by: Marcel Pfennig <82059270+MP-Tool@users.noreply.github.com> Co-authored-by: jack <45038833+jackra1n@users.noreply.github.com> Co-authored-by: Guten <ywzhaifei@gmail.com> Co-authored-by: Paulo Roberto Albuquerque <paulora2405@gmail.com> Co-authored-by: Lorenzo Farnararo <2814802+baldarn@users.noreply.github.com>
208 lines
5.2 KiB
Rust
208 lines
5.2 KiB
Rust
use anyhow::{Context, anyhow};
|
|
use database::mungos::mongodb::bson::doc;
|
|
use komodo_client::{
|
|
api::write::*,
|
|
entities::{Operation, ResourceTarget, variable::Variable},
|
|
};
|
|
use reqwest::StatusCode;
|
|
use resolver_api::Resolve;
|
|
use serror::AddStatusCodeError;
|
|
|
|
use crate::{
|
|
helpers::{
|
|
query::get_variable,
|
|
update::{add_update, make_update},
|
|
},
|
|
state::db_client,
|
|
};
|
|
|
|
use super::WriteArgs;
|
|
|
|
impl Resolve<WriteArgs> for CreateVariable {
|
|
#[instrument(name = "CreateVariable", skip(user, self), fields(name = &self.name))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<CreateVariableResponse> {
|
|
if !user.admin {
|
|
return Err(
|
|
anyhow!("Only admins can create variables")
|
|
.status_code(StatusCode::FORBIDDEN),
|
|
);
|
|
}
|
|
|
|
let CreateVariable {
|
|
name,
|
|
value,
|
|
description,
|
|
is_secret,
|
|
} = self;
|
|
|
|
let variable = Variable {
|
|
name,
|
|
value,
|
|
description,
|
|
is_secret,
|
|
};
|
|
|
|
db_client()
|
|
.variables
|
|
.insert_one(&variable)
|
|
.await
|
|
.context("Failed to create variable on db")?;
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::CreateVariable,
|
|
user,
|
|
);
|
|
|
|
update
|
|
.push_simple_log("create variable", format!("{variable:#?}"));
|
|
update.finalize();
|
|
|
|
add_update(update).await?;
|
|
|
|
Ok(get_variable(&variable.name).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for UpdateVariableValue {
|
|
#[instrument(name = "UpdateVariableValue", skip(user, self), fields(name = &self.name))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<UpdateVariableValueResponse> {
|
|
if !user.admin {
|
|
return Err(
|
|
anyhow!("Only admins can update variables")
|
|
.status_code(StatusCode::FORBIDDEN),
|
|
);
|
|
}
|
|
|
|
let UpdateVariableValue { name, value } = self;
|
|
|
|
let variable = get_variable(&name).await?;
|
|
|
|
if value == variable.value {
|
|
return Ok(variable);
|
|
}
|
|
|
|
db_client()
|
|
.variables
|
|
.update_one(
|
|
doc! { "name": &name },
|
|
doc! { "$set": { "value": &value } },
|
|
)
|
|
.await
|
|
.context("Failed to update variable value on db")?;
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::UpdateVariableValue,
|
|
user,
|
|
);
|
|
|
|
let log = if variable.is_secret {
|
|
format!(
|
|
"<span class=\"text-muted-foreground\">variable</span>: '{name}'\n<span class=\"text-muted-foreground\">from</span>: <span class=\"text-red-500\">{}</span>\n<span class=\"text-muted-foreground\">to</span>: <span class=\"text-green-500\">{value}</span>",
|
|
variable.value.replace(|_| true, "#")
|
|
)
|
|
} else {
|
|
format!(
|
|
"<span class=\"text-muted-foreground\">variable</span>: '{name}'\n<span class=\"text-muted-foreground\">from</span>: <span class=\"text-red-500\">{}</span>\n<span class=\"text-muted-foreground\">to</span>: <span class=\"text-green-500\">{value}</span>",
|
|
variable.value
|
|
)
|
|
};
|
|
|
|
update.push_simple_log("Update Variable Value", log);
|
|
update.finalize();
|
|
|
|
add_update(update).await?;
|
|
|
|
Ok(get_variable(&name).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for UpdateVariableDescription {
|
|
#[instrument(name = "UpdateVariableDescription", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<UpdateVariableDescriptionResponse> {
|
|
if !user.admin {
|
|
return Err(
|
|
anyhow!("Only admins can update variables")
|
|
.status_code(StatusCode::FORBIDDEN),
|
|
);
|
|
}
|
|
db_client()
|
|
.variables
|
|
.update_one(
|
|
doc! { "name": &self.name },
|
|
doc! { "$set": { "description": &self.description } },
|
|
)
|
|
.await
|
|
.context("Failed to update variable description on db")?;
|
|
Ok(get_variable(&self.name).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for UpdateVariableIsSecret {
|
|
#[instrument(name = "UpdateVariableIsSecret", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<UpdateVariableIsSecretResponse> {
|
|
if !user.admin {
|
|
return Err(
|
|
anyhow!("Only admins can update variables")
|
|
.status_code(StatusCode::FORBIDDEN),
|
|
);
|
|
}
|
|
db_client()
|
|
.variables
|
|
.update_one(
|
|
doc! { "name": &self.name },
|
|
doc! { "$set": { "is_secret": self.is_secret } },
|
|
)
|
|
.await
|
|
.context("Failed to update variable is secret on db")?;
|
|
Ok(get_variable(&self.name).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for DeleteVariable {
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<DeleteVariableResponse> {
|
|
if !user.admin {
|
|
return Err(
|
|
anyhow!("Only admins can delete variables")
|
|
.status_code(StatusCode::FORBIDDEN),
|
|
);
|
|
}
|
|
let variable = get_variable(&self.name).await?;
|
|
db_client()
|
|
.variables
|
|
.delete_one(doc! { "name": &self.name })
|
|
.await
|
|
.context("Failed to delete variable on db")?;
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::DeleteVariable,
|
|
user,
|
|
);
|
|
|
|
update
|
|
.push_simple_log("Delete Variable", format!("{variable:#?}"));
|
|
update.finalize();
|
|
|
|
add_update(update).await?;
|
|
|
|
Ok(variable)
|
|
}
|
|
}
|