-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
305 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use clap::{Args, Parser, Subcommand}; | ||
use uuid::Uuid; | ||
|
||
// TODO: Add abouts to arguments | ||
#[derive(Parser, Debug, Clone)] | ||
pub struct AppContext { | ||
#[clap(env)] | ||
pub vicky_url: String, | ||
|
||
#[clap(env)] | ||
pub vicky_token: String, | ||
|
||
#[clap(long)] | ||
pub humanize: bool, | ||
} | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
pub struct TaskData { | ||
#[clap(short, long)] | ||
pub name: String, | ||
#[clap(long)] | ||
pub lock_name: Vec<String>, | ||
#[clap(long)] | ||
pub lock_type: Vec<String>, | ||
#[clap(long)] | ||
pub flake_url: String, | ||
#[clap(long)] | ||
pub flake_arg: Vec<String>, | ||
#[clap(long)] | ||
pub features: Vec<String>, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum TaskCommands { | ||
Create(TaskData), | ||
// Logs, // TODO: could add this later | ||
Claim { features: Vec<String> }, | ||
Finish { id: Uuid, status: String }, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
#[command(version, about = "Manage tasks on the vicky delegation server", long_about = None)] | ||
pub struct TaskArgs { | ||
#[command(subcommand)] | ||
pub commands: TaskCommands, | ||
|
||
#[command(flatten)] | ||
pub ctx: AppContext, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
#[command(version, about = "Show all tasks vicky is managing", long_about = None)] | ||
pub struct TasksArgs { | ||
#[command(flatten)] | ||
pub ctx: AppContext, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
#[command(version, about = "Show all poisoned locks vicky is managing", long_about = None)] | ||
pub struct LocksArgs { | ||
#[command(flatten)] | ||
pub ctx: AppContext, | ||
#[clap(long)] | ||
pub active: bool, | ||
#[clap(long)] | ||
pub poisoned: bool, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
#[command(version, about = "Show all poisoned locks vicky is managing", long_about = None)] | ||
pub struct ResolveArgs { | ||
#[command(flatten)] | ||
pub ctx: AppContext, | ||
#[clap(long)] | ||
pub all: bool, | ||
#[clap(long,short)] | ||
pub task_id: Option<String>, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
pub enum Cli { | ||
Task(TaskArgs), | ||
Tasks(TasksArgs), | ||
Locks(LocksArgs), | ||
Resolve(ResolveArgs), | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::cli::AppContext; | ||
use crate::error::Error; | ||
use crate::http_client::prepare_client; | ||
use crate::locks::types::{LockType, PoisonedLock}; | ||
|
||
pub fn get_locks_endpoint(lock_type: LockType, detailed: bool) -> &'static str { | ||
match lock_type { | ||
LockType::Poisoned => match detailed { | ||
false => "api/v1/locks/poisoned", | ||
true => "api/v1/locks/poisoned_detailed", | ||
}, | ||
LockType::Active => "api/v1/locks/active", | ||
} | ||
} | ||
|
||
pub fn fetch_locks_raw( | ||
ctx: &AppContext, | ||
lock_type: LockType, | ||
detailed: bool, | ||
) -> Result<String, Error> { | ||
let client = prepare_client(ctx)?; | ||
let request = client | ||
.get(format!( | ||
"{}/{}", | ||
ctx.vicky_url, | ||
get_locks_endpoint(lock_type, detailed) | ||
)) | ||
.build()?; | ||
let response = client.execute(request)?.error_for_status()?; | ||
|
||
let locks = response.text()?; | ||
Ok(locks) | ||
} | ||
|
||
pub fn fetch_detailed_poisoned_locks(ctx: &AppContext) -> Result<Vec<PoisonedLock>, Error> { | ||
let raw_locks = fetch_locks_raw(ctx, LockType::Poisoned, true)?; | ||
let locks: Vec<PoisonedLock> = serde_json::from_str(&raw_locks)?; | ||
Ok(locks) | ||
} | ||
|
||
pub fn unlock_lock(ctx: &AppContext, lock_to_clear: &PoisonedLock) -> Result<(), Error> { | ||
let client = prepare_client(ctx)?; | ||
let request = client | ||
.patch(format!( | ||
"{}/api/v1/locks/unlock/{}", | ||
ctx.vicky_url, | ||
lock_to_clear.id() | ||
)) | ||
.build()?; | ||
client.execute(request)?.error_for_status()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mod http; | ||
mod tui; | ||
mod types; | ||
|
||
pub use tui::resolve_lock; | ||
pub use tui::show_locks; |
Oops, something went wrong.