mirror of
https://github.com/moghtech/komodo.git
synced 2026-03-21 22:00:36 -05:00
* attach env_file to compose build and compose pull stages * fmt and bump rust version * bump dependencies * ignored for Sqlite message * fix Build secret args info * improve secret arguments info * improve environment, ports, volumes deserializers * rename `mongo` to `database` in config * support _FILE in secret env vars * improve setup - simpler compose * remove aws ecr container registry support, alpine dockerfiles * log periphery config * ssl_enabled mode * log http vs https * periphery client accept untrust ssl certs * fix nav issue from links * configurable ssl * KOMODO_ENSURE_SERVER -> KOMODO_FIRST_SERVER * mount proc and ssl volume * managed sync * validate files on host resource path * remove sync repo not configured guards * disable confirm dialog * fix sync hash / message Option * try dev dockerfile * refresh sync resources after commit * socket invalidate handling * delete dev dockerfile * Commit Changes * Add Info tab to syncs * fix new Info parsing issue with serde default * refresh stack cache on create / update * managed syncs can't sync themselves * managed syncs seems to work * bump thiserror * use alpine as main dockerfile * apt add --no-cache * disable user write perms, super admin perms to manage admins * manage admin user UI * implement disable non admin create frontend * disable create non admin * Copy button shown based on permission * warning message on managed sync * implement monaco editor * impl simple match tags config * resource sync support match tags * more match tag filtering * improve config with better saving diffs * export button use monaco * deser Conversions with wrapping strings * envs editing * don't delete variables / user groups if match tags defined * env from_str improve * improve dashboards * remove core ca stuff for now * move periphery ssl gen to dedicated file * default server address periphery:8120 * clean up ssl configs * server dashboard * nice test compose * add discord alerter * discord alerter * stack hideInfo logic * compose setup * alert table * improve config hover card style * update min editor height and stack config * Feat: Styling Updates (#94) * sidebar takes full screen height * add bg accent to navbar * add aschild prop to topbar alerts trigger * stylize resource rows * internally scrollable data tables * better hover color for outlined button * always show scrollbar to prevent layout shift * better hover color for navbar * rearrange buttons * fix table and resource row styles * cleanup scrollbar css * use page for dashboard instead of section * fix padding * resource sync refactor and env keep comments * frontend build * improve configs * config nice * Feat/UI (#95) * stylize resource rows * internally scrollable data tables * fix table and resource row styles * use page for dashboard instead of section * fix padding * add `ResourcePageHeader` to required components * add generic resource page header component * add resource page headers for all components * add resource notificaitons component * add `TextUpdateMenu2` for use in resource page * cleanup resource notificaitons * update resource page layout * ui edits * sync kind of work * clean up unused import * syncs seem to work * new sync pending * monaco diff hide unchanged regions * update styling all in config resource select links * confirm update default strings * move procedure Add Stage to left * update colors / styles * frontend build * backend for write file contents to host * compose reference ports comment out * server config * ensure parent directory created * fix frontend build * remove default stack run_directory * fix periphery compose deploy response set * update compose files * move server stats under tabs * fix deployment list item getting correct image when not deployed * stack updates cache after file write * edit files on host * clean up unused imports * top level config update assignment must be spread * update deps, move alert module * move stack module * move sync module * move to sync db_client usage after init * support generic OIDC provider * init builders / server templates specifying https * special cases for server / deployment state * improve alert details * add builder template `use_https` config * try downgrade aws sdk ec2 for x86 build * update debian dockerfiles to rm lists/* * optionally configure seperate KOMODO_OIDC_REDIRECT * add defaults to compose.env * keep tags / search right aligned when view only * clean up configs * remove unused migrator deps * update roadmap support generic OIDC * initialize sync use confirm button * key_value syntax highlighting * smaller debian dockerfiles * clean up deps.sh * debian dockerifle * New config layout (#96) * new config layout * fix image config layout and components config * fix dom nesting and cleanup components * fix label, make switches flex row * ensure smooth scroll on hash navigations * width 180 on config sidebar * slight edits to config * log whether https builder * DISABLED <switch> ENABLED * fix some more config * smaller checked component * server config looking good * auto initialize compose files when files on host * stack files on host good * stack config nice * remove old config * deployments looking good * build looking good * Repo good * nice config for builders * alerter good * server template config * syncs good * tweak stack config * use status badge for update tables * unified update page using router params * replace /updates with unified updates page * redirect all resource updates to unified update page * fix reset handling * unmount legacy page * try periphery rustls * rm unused import * fix broken deps * add unified alerts apge * mount new alerts, remove old alerts page * reroute resource alerts to unified alerts page * back to periphery openssl * ssl_enabled defaults to false for backward compat * reqwest need json feature * back to og yaml monaco * Uncomment config fields for clearer config * clean up compose env * implement pull or clone, avoid deleting repo directory * refactor mongo configuration params * all configs respect empty string null * add back status to header * build toml don't have version if not auto incrementing * fix comile * fix repo pull cd to correct dir * fix core pull_or_clone directory * improve statuses * remove ' ' from kv list parser * longer CSRF valid for, to give time to login / accept * don't compute diff / execute if there are any file_errors * PartialBuilderConfig enum user inner option * move errors to top * fix toml init serializer * server template and bulder manually add config.params line * better way to check builder / template params empty * improve build configs * merge links into network area deployment * default periphery config * improve SystemCommand editor * better Repo server / builder Info * improve Alerts / Updates with ResourceSelector * fix unused frontend * update ResourceSync description * toml use [resource.config] syntax * update toml syntax * update Build.image_registry schema * fix repo / stack resource link alias * reorder image registry * align toml / yaml parser style * some config updates --------- Co-authored-by: Karamvir Singh <67458484+karamvirsingh98@users.noreply.github.com> Co-authored-by: kv <karamvir.singh98@gmail.com>
400 lines
9.5 KiB
Rust
400 lines
9.5 KiB
Rust
use anyhow::{anyhow, Context};
|
|
use komodo_client::{
|
|
api::write::*,
|
|
entities::{
|
|
provider::{DockerRegistryAccount, GitProviderAccount},
|
|
user::User,
|
|
Operation, ResourceTarget,
|
|
},
|
|
};
|
|
use mungos::{
|
|
by_id::{delete_one_by_id, find_one_by_id, update_one_by_id},
|
|
mongodb::bson::{doc, to_document},
|
|
};
|
|
use resolver_api::Resolve;
|
|
|
|
use crate::{
|
|
helpers::update::{add_update, make_update},
|
|
state::{db_client, State},
|
|
};
|
|
|
|
impl Resolve<CreateGitProviderAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
CreateGitProviderAccount { account }: CreateGitProviderAccount,
|
|
user: User,
|
|
) -> anyhow::Result<CreateGitProviderAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can create git provider accounts"
|
|
));
|
|
}
|
|
|
|
let mut account: GitProviderAccount = account.into();
|
|
|
|
if account.domain.is_empty() {
|
|
return Err(anyhow!("domain cannot be empty string."));
|
|
}
|
|
|
|
if account.username.is_empty() {
|
|
return Err(anyhow!("username cannot be empty string."));
|
|
}
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::CreateGitProviderAccount,
|
|
&user,
|
|
);
|
|
|
|
account.id = db_client()
|
|
.git_accounts
|
|
.insert_one(&account)
|
|
.await
|
|
.context("failed to create git provider account on db")?
|
|
.inserted_id
|
|
.as_object_id()
|
|
.context("inserted id is not ObjectId")?
|
|
.to_string();
|
|
|
|
update.push_simple_log(
|
|
"create git provider account",
|
|
format!(
|
|
"Created git provider account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for create git provider account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|
|
|
|
impl Resolve<UpdateGitProviderAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
UpdateGitProviderAccount { id, mut account }: UpdateGitProviderAccount,
|
|
user: User,
|
|
) -> anyhow::Result<UpdateGitProviderAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can update git provider accounts"
|
|
));
|
|
}
|
|
|
|
if let Some(domain) = &account.domain {
|
|
if domain.is_empty() {
|
|
return Err(anyhow!(
|
|
"cannot update git provider with empty domain"
|
|
));
|
|
}
|
|
}
|
|
|
|
if let Some(username) = &account.username {
|
|
if username.is_empty() {
|
|
return Err(anyhow!(
|
|
"cannot update git provider with empty username"
|
|
));
|
|
}
|
|
}
|
|
|
|
// Ensure update does not change id
|
|
account.id = None;
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::UpdateGitProviderAccount,
|
|
&user,
|
|
);
|
|
|
|
let account = to_document(&account).context(
|
|
"failed to serialize partial git provider account to bson",
|
|
)?;
|
|
let db = db_client();
|
|
update_one_by_id(
|
|
&db.git_accounts,
|
|
&id,
|
|
doc! { "$set": account },
|
|
None,
|
|
)
|
|
.await
|
|
.context("failed to update git provider account on db")?;
|
|
|
|
let Some(account) =
|
|
find_one_by_id(&db.git_accounts, &id)
|
|
.await
|
|
.context("failed to query db for git accounts")?
|
|
else {
|
|
return Err(anyhow!("no account found with given id"));
|
|
};
|
|
|
|
update.push_simple_log(
|
|
"update git provider account",
|
|
format!(
|
|
"Updated git provider account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for update git provider account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|
|
|
|
impl Resolve<DeleteGitProviderAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
DeleteGitProviderAccount { id }: DeleteGitProviderAccount,
|
|
user: User,
|
|
) -> anyhow::Result<DeleteGitProviderAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can delete git provider accounts"
|
|
));
|
|
}
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::UpdateGitProviderAccount,
|
|
&user,
|
|
);
|
|
|
|
let db = db_client();
|
|
let Some(account) =
|
|
find_one_by_id(&db.git_accounts, &id)
|
|
.await
|
|
.context("failed to query db for git accounts")?
|
|
else {
|
|
return Err(anyhow!("no account found with given id"));
|
|
};
|
|
delete_one_by_id(&db.git_accounts, &id, None)
|
|
.await
|
|
.context("failed to delete git account on db")?;
|
|
|
|
update.push_simple_log(
|
|
"delete git provider account",
|
|
format!(
|
|
"Deleted git provider account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for delete git provider account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|
|
|
|
impl Resolve<CreateDockerRegistryAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
CreateDockerRegistryAccount { account }: CreateDockerRegistryAccount,
|
|
user: User,
|
|
) -> anyhow::Result<CreateDockerRegistryAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can create docker registry account accounts"
|
|
));
|
|
}
|
|
|
|
let mut account: DockerRegistryAccount = account.into();
|
|
|
|
if account.domain.is_empty() {
|
|
return Err(anyhow!("domain cannot be empty string."));
|
|
}
|
|
|
|
if account.username.is_empty() {
|
|
return Err(anyhow!("username cannot be empty string."));
|
|
}
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::CreateDockerRegistryAccount,
|
|
&user,
|
|
);
|
|
|
|
account.id = db_client()
|
|
.registry_accounts
|
|
.insert_one(&account)
|
|
.await
|
|
.context(
|
|
"failed to create docker registry account account on db",
|
|
)?
|
|
.inserted_id
|
|
.as_object_id()
|
|
.context("inserted id is not ObjectId")?
|
|
.to_string();
|
|
|
|
update.push_simple_log(
|
|
"create docker registry account",
|
|
format!(
|
|
"Created docker registry account account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for create docker registry account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|
|
|
|
impl Resolve<UpdateDockerRegistryAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
UpdateDockerRegistryAccount { id, mut account }: UpdateDockerRegistryAccount,
|
|
user: User,
|
|
) -> anyhow::Result<UpdateDockerRegistryAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can update docker registry accounts"
|
|
));
|
|
}
|
|
|
|
if let Some(domain) = &account.domain {
|
|
if domain.is_empty() {
|
|
return Err(anyhow!(
|
|
"cannot update docker registry account with empty domain"
|
|
));
|
|
}
|
|
}
|
|
|
|
if let Some(username) = &account.username {
|
|
if username.is_empty() {
|
|
return Err(anyhow!(
|
|
"cannot update docker registry account with empty username"
|
|
));
|
|
}
|
|
}
|
|
|
|
account.id = None;
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::UpdateDockerRegistryAccount,
|
|
&user,
|
|
);
|
|
|
|
let account = to_document(&account).context(
|
|
"failed to serialize partial docker registry account account to bson",
|
|
)?;
|
|
|
|
let db = db_client();
|
|
update_one_by_id(
|
|
&db.registry_accounts,
|
|
&id,
|
|
doc! { "$set": account },
|
|
None,
|
|
)
|
|
.await
|
|
.context(
|
|
"failed to update docker registry account account on db",
|
|
)?;
|
|
|
|
let Some(account) = find_one_by_id(&db.registry_accounts, &id)
|
|
.await
|
|
.context("failed to query db for registry accounts")?
|
|
else {
|
|
return Err(anyhow!("no account found with given id"));
|
|
};
|
|
|
|
update.push_simple_log(
|
|
"update docker registry account",
|
|
format!(
|
|
"Updated docker registry account account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for update docker registry account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|
|
|
|
impl Resolve<DeleteDockerRegistryAccount, User> for State {
|
|
async fn resolve(
|
|
&self,
|
|
DeleteDockerRegistryAccount { id }: DeleteDockerRegistryAccount,
|
|
user: User,
|
|
) -> anyhow::Result<DeleteDockerRegistryAccountResponse> {
|
|
if !user.admin {
|
|
return Err(anyhow!(
|
|
"only admins can delete docker registry accounts"
|
|
));
|
|
}
|
|
|
|
let mut update = make_update(
|
|
ResourceTarget::system(),
|
|
Operation::UpdateDockerRegistryAccount,
|
|
&user,
|
|
);
|
|
|
|
let db = db_client();
|
|
let Some(account) = find_one_by_id(&db.registry_accounts, &id)
|
|
.await
|
|
.context("failed to query db for git accounts")?
|
|
else {
|
|
return Err(anyhow!("no account found with given id"));
|
|
};
|
|
delete_one_by_id(&db.registry_accounts, &id, None)
|
|
.await
|
|
.context("failed to delete registry account on db")?;
|
|
|
|
update.push_simple_log(
|
|
"delete registry account",
|
|
format!(
|
|
"Deleted registry account for {} with username {}",
|
|
account.domain, account.username
|
|
),
|
|
);
|
|
|
|
update.finalize();
|
|
|
|
add_update(update)
|
|
.await
|
|
.inspect_err(|e| {
|
|
error!("failed to add update for delete docker registry account | {e:#}")
|
|
})
|
|
.ok();
|
|
|
|
Ok(account)
|
|
}
|
|
}
|