mirror of
https://github.com/moghtech/komodo.git
synced 2026-08-26 08:00:26 +00:00
118ae9b92c
* update easy deps * update otel deps * implement template in types + update resource meta * ts types * dev-2 * dev-3 default template query is include * Toggle resource is template in resource header * dev-4 support CopyServer * gen ts * style template selector in New Resource menu * fix new menu show 0 * add template market in omni search bar * fix some dynamic import behavior * template badge on dashboard * dev-5 * standardize interpolation methods with nice api * core use new interpolation methods * refactor git usage * dev-6 refactor interpolation / git methods * fix pull stack passed replacers * new types * remove redundant interpolation for build secret args * clean up periphery docker client * dev-7 include ports in container summary, see if they actually come through * show container ports in container table * refresh processes without tasks (more efficient) * dev-8 keep container stats cache, include with ContainerListItem * gen types * display more container ports * dev-9 fix repo clone when repo doesn't exist initially * Add ports display to more spots * fix function name * add Periphery full container stats api, may be used later * server container stats list * dev-10 * 1.18.4 release * Use reset instead of invalidate to fix GetUser spam on token expiry (#618) --------- Co-authored-by: Jacky Fong <hello@huzky.dev>
89 lines
2.4 KiB
Rust
89 lines
2.4 KiB
Rust
use std::path::Path;
|
|
|
|
use komodo_client::{
|
|
entities::{komodo_timestamp, update::Log},
|
|
parsers::parse_multiline_command,
|
|
};
|
|
use run_command::{CommandOutput, async_run_command};
|
|
|
|
pub async fn run_komodo_command(
|
|
stage: &str,
|
|
path: impl Into<Option<&Path>>,
|
|
command: impl AsRef<str>,
|
|
) -> Log {
|
|
let command = if let Some(path) = path.into() {
|
|
format!("cd {} && {}", path.display(), command.as_ref())
|
|
} else {
|
|
command.as_ref().to_string()
|
|
};
|
|
let start_ts = komodo_timestamp();
|
|
let output = async_run_command(&command).await;
|
|
output_into_log(stage, command, start_ts, output)
|
|
}
|
|
|
|
/// Parses commands out of multiline string
|
|
/// and chains them together with '&&'.
|
|
/// Supports full line and end of line comments.
|
|
/// See [parse_multiline_command].
|
|
///
|
|
/// The result may be None if the command is empty after parsing,
|
|
/// ie if all the lines are commented out.
|
|
pub async fn run_komodo_command_multiline(
|
|
stage: &str,
|
|
path: impl Into<Option<&Path>>,
|
|
command: impl AsRef<str>,
|
|
) -> Option<Log> {
|
|
let command = parse_multiline_command(command);
|
|
if command.is_empty() {
|
|
return None;
|
|
}
|
|
Some(run_komodo_command(stage, path, command).await)
|
|
}
|
|
|
|
/// Executes the command, and sanitizes the output to avoid exposing secrets in the log.
|
|
///
|
|
/// Checks to make sure the command is non-empty after being multiline-parsed.
|
|
///
|
|
/// If `parse_multiline: true`, parses commands out of multiline string
|
|
/// and chains them together with '&&'.
|
|
/// Supports full line and end of line comments.
|
|
/// See [parse_multiline_command].
|
|
pub async fn run_komodo_command_with_sanitization(
|
|
stage: &str,
|
|
path: impl Into<Option<&Path>>,
|
|
command: impl AsRef<str>,
|
|
parse_multiline: bool,
|
|
replacers: &[(String, String)],
|
|
) -> Option<Log> {
|
|
let mut log = if parse_multiline {
|
|
run_komodo_command_multiline(stage, path, command).await
|
|
} else {
|
|
run_komodo_command(stage, path, command).await.into()
|
|
}?;
|
|
|
|
// Sanitize the command and output
|
|
log.command = svi::replace_in_string(&log.command, replacers);
|
|
log.stdout = svi::replace_in_string(&log.stdout, replacers);
|
|
log.stderr = svi::replace_in_string(&log.stderr, replacers);
|
|
|
|
Some(log)
|
|
}
|
|
|
|
pub fn output_into_log(
|
|
stage: &str,
|
|
command: String,
|
|
start_ts: i64,
|
|
output: CommandOutput,
|
|
) -> Log {
|
|
let success = output.success();
|
|
Log {
|
|
stage: stage.to_string(),
|
|
stdout: output.stdout,
|
|
stderr: output.stderr,
|
|
command,
|
|
success,
|
|
start_ts,
|
|
end_ts: komodo_timestamp(),
|
|
}
|
|
}
|