use super::*;
#[derive(Debug, Clone, Serialize, Default, PartialEq)]
pub struct DsResult {
pub ran: bool,
pub scale: String,
pub target: String,
pub crates: usize,
pub files: usize,
pub ops: u64,
pub bytes: u64,
pub mbs: f64,
pub ops_per_sec: f64,
pub status: String,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct DsConfig {
pub scale: String,
pub target: String,
pub status: String,
pub result: Option<DsResult>,
}
impl Default for DsConfig {
fn default() -> Self {
Self {
scale: "micro".to_string(),
target: String::new(),
status: String::new(),
result: None,
}
}
}
impl DsConfig {
pub fn state_json(&self) -> Value {
serde_json::to_value(self).unwrap_or(Value::Null)
}
pub fn cli_command(&self) -> String {
let mut s = format!("holger-server holger-ds --preset {}", self.scale);
if !self.target.is_empty() {
s.push_str(&format!(" --target {}", self.target));
}
s
}
}
#[derive(Debug, Clone, Serialize, Default, PartialEq, Eq)]
pub struct MigrateRun {
pub ran: bool,
pub source: String,
pub url: String,
pub output: String,
pub repositories: usize,
pub status: String,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct MigrateConfig {
pub source: String,
pub url: String,
pub output: String,
pub repository: String,
pub status: String,
pub result: Option<MigrateRun>,
}
impl Default for MigrateConfig {
fn default() -> Self {
Self {
source: "nexus".to_string(),
url: String::new(),
output: "migrated.znippy".to_string(),
repository: String::new(),
status: String::new(),
result: None,
}
}
}
impl MigrateConfig {
pub fn state_json(&self) -> Value {
serde_json::to_value(self).unwrap_or(Value::Null)
}
pub fn cli_command(&self) -> String {
let url_flag = if self.source == "artifactory" { "--artifactory-url" } else { "--nexus-url" };
let url = if self.url.is_empty() { "<url>" } else { &self.url };
let mut s = format!(
"holger-agent --from {} {url_flag} {url} --to znippy --output {}",
self.source, self.output
);
if !self.repository.is_empty() {
s.push_str(&format!(" --repository {}", self.repository));
}
s
}
}
#[derive(Debug, Clone, Serialize, Default, PartialEq, Eq)]
pub struct AirgapRun {
pub ran: bool,
pub dry_run: bool,
pub plan: String,
pub log: String,
pub exit_code: i32,
pub success: bool,
pub status: String,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default, PartialEq, Eq)]
pub struct DeployRun {
pub ran: bool,
pub repository: String,
pub target: String,
pub file_count: u64,
pub bytes: u64,
pub archive_path: String,
pub plan: String,
pub status: String,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct DeployConfig {
pub target: holger_airgap::Target,
pub status: String,
pub result: Option<DeployRun>,
}
impl Default for DeployConfig {
fn default() -> Self {
Self {
target: holger_airgap::Target::Holger,
status: String::new(),
result: None,
}
}
}
impl DeployConfig {
pub fn state_json(&self) -> Value {
serde_json::to_value(self).unwrap_or(Value::Null)
}
}