mirror of
https://github.com/moghtech/komodo.git
synced 2025-12-05 19:17:36 -06:00
* resolver v3
add new ec2 instance types
clean up testing config
document the libraries a bit
clean up main
update sysinfo and otel
update client resolver 3.0
resolver v3 prog
clean up gitignore
implement periphery resolver v3
clean up
core read api v3
more prog
execute api
missing apis
compiling
1.16.13
work on more granular traits
prog on crud
* fmt
* format
* resource2 not really a benefit
* axum to 0.8
* bump aws deps
* just make it 1.17.0
* clean up cors
* the komodo env file should be highest priority over additional files
* add entities / message for test alerter
* test alert implementation
* rust 1.84.0
* axum update :param to {param} syntax
* fix last axum updates
* Add test alerter button
* higher quality / colored icons
* komodo-logo
* simplify network stats
* rename Test Alerter button
* escape incoming sync backslashes (BREAKING)
* clean up rust client websocket subscription
* finish oidc comment
* show update available stack table
* update available deployment table
* feature: use the repo path instead of name in GetLatestCommit (#282)
* Update repo path handling in commit fetching
- Changed `name` to `path` for repository identification.
- Updated cache update function to use the new path field.
- Improved error message for non-directory repo paths.
* feat: use optional name and path in GetLatestCommit
* review: don't use optional for name
* review: use helper
* review: remove redundant to_string()
* 1.17.0-dev
* feature: add post_deploy command (#288)
* feature: add post_deploy command
* review: do not run post_deploy if deploy failed
* feature: interpolate secrets in custom alerter (#289)
* feature: interpolate secrets in custom alerter
* fix rust warning
* review: sanitize errors
* review: sanitize error message
* Remove .git from remote_url (#299)
Remove .git from remote_url
Co-authored-by: Deon Marshall <dmarshall@ccp.com.au>
* mbecker20 -> moghtech
* remove example from cargo toml workspace
* dev-1
* fix login screen logo
* more legible favicon
* fix new compose images
* docs new organization
* typescript subscribe_to_update_websocket
* add donate button docsite
* add config save button in desktop sidebar navigator
* add save button to config bottom
* feature: allow docker image text to overflow in table (#301)
* feature: allow docker image text to overflow in table
* review: use break-words
* wip: revert line break in css file
* feature: update devcontainer node release
* improve First Login docs
* FIx PullStack re #302 and record docker compose config on stack deploy
* requery alerts more often
* improve update indicator style and also put on home screen
* Add all services stack log
* 1.17.0-dev-2
* fix api name chnage
* choose which stack services to include in logs
* feature: improve tables quick actions on mobile (#312)
* feature: improve tables quick actions on mobile
* review: fix gap4
* review: use flex-wrap
* improve pull to git init on existing folder without .git
* Fix unclear ComposePull log re #244
* use komodo_client.subscribe_to_update_websocket, and click indicator to reconnect
* dev-3
* ServerTemplate description
* improve WriteComposeContentsToHost instrument fields
* give server stat charts labels
* filters wrap
* show provider usernames from config file
* Stack: Fix git repo new compose file initialization
* init sync file new repo
* set branch on git init folder
* ResourceSync: pending view toggle between "Execute" vs "Commit" sync direction
* Improve resource sync Execute / Pending view selector
* standardize running commands with interpolation / output sanitizations
* fix all clippy lints
* fix rand
* lock certain users username / password, prevent demo creds from being changed.
* revert to login screen whenever the call to check login fails
* ResourceSync state resolution refinement
* make sure parent directories exist whenever writing files
* don't prune images if server not enabled
* update most deps
* update openidconnect dependency, and use reqwest rustls-tls-native-roots
* dev-4
* resource sync only add escaping on toml between the """
* Stacks executions take list of services -- Auto update only redeploys services with update
* auto update all service deploy option
* dev-5 fix the stack service executions
* clean up service_args
* rust 1.85
* store sync edits on localstorage
* stack edits on localstorage and show last deployed config
* add yarn install to runfile
* Fix actions when core on https
* add update_available query parameter to filter for only stacks /deployments with available update
* rust 2024 and fmt
* rename test.compose.yaml to dev.compose.yaml, and update runfile
* update .devcontainer / dev docs for updated runfile
* use png in topbar logo, svg quality sometimes bad
* OIDC: Support PKCE auth (secret optional)
* update docs on OIDC and client secret
* cycle the oidc client on interval to ensure up to date JWKs
* add KOMODO_LOCK_LOGIN_CREDENTIALS_FOR in config doc
* update deps
* resource sync toggle resource / variable / user group inclusion independantly
* use jsonwebtoken
* improve variable value table overflow
* colored tags
* fix sync summary count ok
* default new tag colors to grey
* soften tag opacity a bit
* Update config.tsx (#358)
* isolate stacks / deployments with pending updates
* update some deps
* use Tooltip component instead of HoverCard for mobile compatibility
* batch Build builds
* link to typescript client in the intro
* add link to main docs from client docs
* doc tweaks
* use moghtech/komodo-core and moghtech/komodo-periphery as images
* remove unnecessary explicit network
* periphery.compose.yaml
* clean up periphery compose
* add link to config
* update periphery container compose config
* rust 1.85.1
* update sync docs
* 1.17.0
---------
Co-authored-by: unsync <1211591+unsync@users.noreply.github.com>
Co-authored-by: Deon Marshall <dmarshall@ccp.com.au>
Co-authored-by: komodo <komodo@komo.do>
Co-authored-by: wlatic <jamesoh@gmail.com>
376 lines
9.0 KiB
Rust
376 lines
9.0 KiB
Rust
use anyhow::{Context, anyhow};
|
|
use git::GitRes;
|
|
use komodo_client::{
|
|
api::write::*,
|
|
entities::{
|
|
CloneArgs, NoData,
|
|
build::{Build, BuildInfo, PartialBuildConfig},
|
|
config::core::CoreConfig,
|
|
permission::PermissionLevel,
|
|
update::Update,
|
|
},
|
|
};
|
|
use mongo_indexed::doc;
|
|
use mungos::mongodb::bson::to_document;
|
|
use octorust::types::{
|
|
ReposCreateWebhookRequest, ReposCreateWebhookRequestConfig,
|
|
};
|
|
use resolver_api::Resolve;
|
|
|
|
use crate::{
|
|
config::core_config,
|
|
helpers::git_token,
|
|
resource,
|
|
state::{db_client, github_client},
|
|
};
|
|
|
|
use super::WriteArgs;
|
|
|
|
impl Resolve<WriteArgs> for CreateBuild {
|
|
#[instrument(name = "CreateBuild", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<Build> {
|
|
Ok(
|
|
resource::create::<Build>(&self.name, self.config, user)
|
|
.await?,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for CopyBuild {
|
|
#[instrument(name = "CopyBuild", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<Build> {
|
|
let Build { mut config, .. } =
|
|
resource::get_check_permissions::<Build>(
|
|
&self.id,
|
|
user,
|
|
PermissionLevel::Write,
|
|
)
|
|
.await?;
|
|
// reset version to 0.0.0
|
|
config.version = Default::default();
|
|
Ok(
|
|
resource::create::<Build>(&self.name, config.into(), user)
|
|
.await?,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for DeleteBuild {
|
|
#[instrument(name = "DeleteBuild", skip(args))]
|
|
async fn resolve(self, args: &WriteArgs) -> serror::Result<Build> {
|
|
Ok(resource::delete::<Build>(&self.id, args).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for UpdateBuild {
|
|
#[instrument(name = "UpdateBuild", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<Build> {
|
|
Ok(resource::update::<Build>(&self.id, self.config, user).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for RenameBuild {
|
|
#[instrument(name = "RenameBuild", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<Update> {
|
|
Ok(resource::rename::<Build>(&self.id, &self.name, user).await?)
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for RefreshBuildCache {
|
|
#[instrument(
|
|
name = "RefreshBuildCache",
|
|
level = "debug",
|
|
skip(user)
|
|
)]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<NoData> {
|
|
// Even though this is a write request, this doesn't change any config. Anyone that can execute the
|
|
// build should be able to do this.
|
|
let build = resource::get_check_permissions::<Build>(
|
|
&self.build,
|
|
user,
|
|
PermissionLevel::Execute,
|
|
)
|
|
.await?;
|
|
|
|
if build.config.repo.is_empty()
|
|
|| build.config.git_provider.is_empty()
|
|
{
|
|
// Nothing to do here
|
|
return Ok(NoData {});
|
|
}
|
|
|
|
let config = core_config();
|
|
|
|
let mut clone_args: CloneArgs = (&build).into();
|
|
let repo_path =
|
|
clone_args.unique_path(&core_config().repo_directory)?;
|
|
clone_args.destination = Some(repo_path.display().to_string());
|
|
// Don't want to run these on core.
|
|
clone_args.on_clone = None;
|
|
clone_args.on_pull = None;
|
|
|
|
let access_token = if let Some(username) = &clone_args.account {
|
|
git_token(&clone_args.provider, username, |https| {
|
|
clone_args.https = https
|
|
})
|
|
.await
|
|
.with_context(
|
|
|| format!("Failed to get git token in call to db. Stopping run. | {} | {username}", clone_args.provider),
|
|
)?
|
|
} else {
|
|
None
|
|
};
|
|
|
|
let GitRes {
|
|
hash: latest_hash,
|
|
message: latest_message,
|
|
..
|
|
} = git::pull_or_clone(
|
|
clone_args,
|
|
&config.repo_directory,
|
|
access_token,
|
|
&[],
|
|
"",
|
|
None,
|
|
&[],
|
|
)
|
|
.await
|
|
.context("failed to clone build repo")?;
|
|
|
|
let info = BuildInfo {
|
|
last_built_at: build.info.last_built_at,
|
|
built_hash: build.info.built_hash,
|
|
built_message: build.info.built_message,
|
|
latest_hash,
|
|
latest_message,
|
|
};
|
|
|
|
let info = to_document(&info)
|
|
.context("failed to serialize build info to bson")?;
|
|
|
|
db_client()
|
|
.builds
|
|
.update_one(
|
|
doc! { "name": &build.name },
|
|
doc! { "$set": { "info": info } },
|
|
)
|
|
.await
|
|
.context("failed to update build info on db")?;
|
|
|
|
Ok(NoData {})
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for CreateBuildWebhook {
|
|
#[instrument(name = "CreateBuildWebhook", skip(args))]
|
|
async fn resolve(
|
|
self,
|
|
args: &WriteArgs,
|
|
) -> serror::Result<CreateBuildWebhookResponse> {
|
|
let Some(github) = github_client() else {
|
|
return Err(
|
|
anyhow!(
|
|
"github_webhook_app is not configured in core config toml"
|
|
)
|
|
.into(),
|
|
);
|
|
};
|
|
|
|
let WriteArgs { user } = args;
|
|
|
|
let build = resource::get_check_permissions::<Build>(
|
|
&self.build,
|
|
user,
|
|
PermissionLevel::Write,
|
|
)
|
|
.await?;
|
|
|
|
if build.config.repo.is_empty() {
|
|
return Err(
|
|
anyhow!("No repo configured, can't create webhook").into(),
|
|
);
|
|
}
|
|
|
|
let mut split = build.config.repo.split('/');
|
|
let owner = split.next().context("Build repo has no owner")?;
|
|
|
|
let Some(github) = github.get(owner) else {
|
|
return Err(
|
|
anyhow!("Cannot manage repo webhooks under owner {owner}")
|
|
.into(),
|
|
);
|
|
};
|
|
|
|
let repo =
|
|
split.next().context("Build repo has no repo after the /")?;
|
|
|
|
let github_repos = github.repos();
|
|
|
|
// First make sure the webhook isn't already created (inactive ones are ignored)
|
|
let webhooks = github_repos
|
|
.list_all_webhooks(owner, repo)
|
|
.await
|
|
.context("failed to list all webhooks on repo")?
|
|
.body;
|
|
|
|
let CoreConfig {
|
|
host,
|
|
webhook_base_url,
|
|
webhook_secret,
|
|
..
|
|
} = core_config();
|
|
|
|
let webhook_secret = if build.config.webhook_secret.is_empty() {
|
|
webhook_secret
|
|
} else {
|
|
&build.config.webhook_secret
|
|
};
|
|
|
|
let host = if webhook_base_url.is_empty() {
|
|
host
|
|
} else {
|
|
webhook_base_url
|
|
};
|
|
let url = format!("{host}/listener/github/build/{}", build.id);
|
|
|
|
for webhook in webhooks {
|
|
if webhook.active && webhook.config.url == url {
|
|
return Ok(NoData {});
|
|
}
|
|
}
|
|
|
|
// Now good to create the webhook
|
|
let request = ReposCreateWebhookRequest {
|
|
active: Some(true),
|
|
config: Some(ReposCreateWebhookRequestConfig {
|
|
url,
|
|
secret: webhook_secret.to_string(),
|
|
content_type: String::from("json"),
|
|
insecure_ssl: None,
|
|
digest: Default::default(),
|
|
token: Default::default(),
|
|
}),
|
|
events: vec![String::from("push")],
|
|
name: String::from("web"),
|
|
};
|
|
github_repos
|
|
.create_webhook(owner, repo, &request)
|
|
.await
|
|
.context("failed to create webhook")?;
|
|
|
|
if !build.config.webhook_enabled {
|
|
UpdateBuild {
|
|
id: build.id,
|
|
config: PartialBuildConfig {
|
|
webhook_enabled: Some(true),
|
|
..Default::default()
|
|
},
|
|
}
|
|
.resolve(args)
|
|
.await
|
|
.map_err(|e| e.error)
|
|
.context("failed to update build to enable webhook")?;
|
|
}
|
|
|
|
Ok(NoData {})
|
|
}
|
|
}
|
|
|
|
impl Resolve<WriteArgs> for DeleteBuildWebhook {
|
|
#[instrument(name = "DeleteBuildWebhook", skip(user))]
|
|
async fn resolve(
|
|
self,
|
|
WriteArgs { user }: &WriteArgs,
|
|
) -> serror::Result<DeleteBuildWebhookResponse> {
|
|
let Some(github) = github_client() else {
|
|
return Err(
|
|
anyhow!(
|
|
"github_webhook_app is not configured in core config toml"
|
|
)
|
|
.into(),
|
|
);
|
|
};
|
|
|
|
let build = resource::get_check_permissions::<Build>(
|
|
&self.build,
|
|
user,
|
|
PermissionLevel::Write,
|
|
)
|
|
.await?;
|
|
|
|
if build.config.git_provider != "github.com" {
|
|
return Err(
|
|
anyhow!("Can only manage github.com repo webhooks").into(),
|
|
);
|
|
}
|
|
|
|
if build.config.repo.is_empty() {
|
|
return Err(
|
|
anyhow!("No repo configured, can't delete webhook").into(),
|
|
);
|
|
}
|
|
|
|
let mut split = build.config.repo.split('/');
|
|
let owner = split.next().context("Build repo has no owner")?;
|
|
|
|
let Some(github) = github.get(owner) else {
|
|
return Err(
|
|
anyhow!("Cannot manage repo webhooks under owner {owner}")
|
|
.into(),
|
|
);
|
|
};
|
|
|
|
let repo =
|
|
split.next().context("Build repo has no repo after the /")?;
|
|
|
|
let github_repos = github.repos();
|
|
|
|
let webhooks = github_repos
|
|
.list_all_webhooks(owner, repo)
|
|
.await
|
|
.context("failed to list all webhooks on repo")?
|
|
.body;
|
|
|
|
let CoreConfig {
|
|
host,
|
|
webhook_base_url,
|
|
..
|
|
} = core_config();
|
|
|
|
let host = if webhook_base_url.is_empty() {
|
|
host
|
|
} else {
|
|
webhook_base_url
|
|
};
|
|
let url = format!("{host}/listener/github/build/{}", build.id);
|
|
|
|
for webhook in webhooks {
|
|
if webhook.active && webhook.config.url == url {
|
|
github_repos
|
|
.delete_webhook(owner, repo, webhook.id)
|
|
.await
|
|
.context("failed to delete webhook")?;
|
|
return Ok(NoData {});
|
|
}
|
|
}
|
|
|
|
// No webhook to delete, all good
|
|
Ok(NoData {})
|
|
}
|
|
}
|