|
|
|
@@ -1,8 +1,8 @@
|
|
|
|
|
use rhai::{CustomType, TypeBuilder};
|
|
|
|
|
use prettytable::{Table, row};
|
|
|
|
|
use rhai::{Array, CustomType, TypeBuilder};
|
|
|
|
|
use serde::{Deserialize, Deserializer};
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
use std::fmt;
|
|
|
|
|
use prettytable::{row, Table};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct ServerWrapper {
|
|
|
|
@@ -40,7 +40,9 @@ impl Server {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("Server")
|
|
|
|
|
.with_get("server_ip", |s: &mut Server| s.server_ip.clone())
|
|
|
|
|
.with_get("server_ipv6_net", |s: &mut Server| s.server_ipv6_net.clone())
|
|
|
|
|
.with_get("server_ipv6_net", |s: &mut Server| {
|
|
|
|
|
s.server_ipv6_net.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("server_number", |s: &mut Server| s.server_number)
|
|
|
|
|
.with_get("server_name", |s: &mut Server| s.server_name.clone())
|
|
|
|
|
.with_get("product", |s: &mut Server| s.product.clone())
|
|
|
|
@@ -152,13 +154,7 @@ impl SshKey {
|
|
|
|
|
impl fmt::Display for SshKey {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
let mut table = Table::new();
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Name",
|
|
|
|
|
"Fingerprint",
|
|
|
|
|
"Type",
|
|
|
|
|
"Size",
|
|
|
|
|
"Created At"
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Name", "Fingerprint", "Type", "Size", "Created At"]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
self.name.clone(),
|
|
|
|
|
self.fingerprint.clone(),
|
|
|
|
@@ -251,9 +247,7 @@ impl Rescue {
|
|
|
|
|
.with_get("os", |r: &mut Rescue| r.os.clone())
|
|
|
|
|
.with_get("active", |r: &mut Rescue| r.active)
|
|
|
|
|
.with_get("password", |r: &mut Rescue| r.password.clone())
|
|
|
|
|
.with_get("authorized_key", |r: &mut Rescue| {
|
|
|
|
|
r.authorized_key.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("authorized_key", |r: &mut Rescue| r.authorized_key.clone())
|
|
|
|
|
.with_get("host_key", |r: &mut Rescue| r.host_key.clone())
|
|
|
|
|
.on_print(|r: &mut Rescue| r.to_string())
|
|
|
|
|
.with_fn("pretty_print", |r: &mut Rescue| r.to_string());
|
|
|
|
@@ -293,17 +287,13 @@ impl Linux {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("Linux")
|
|
|
|
|
.with_get("server_ip", |l: &mut Linux| l.server_ip.clone())
|
|
|
|
|
.with_get("server_ipv6_net", |l: &mut Linux| {
|
|
|
|
|
l.server_ipv6_net.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("server_ipv6_net", |l: &mut Linux| l.server_ipv6_net.clone())
|
|
|
|
|
.with_get("server_number", |l: &mut Linux| l.server_number)
|
|
|
|
|
.with_get("dist", |l: &mut Linux| l.dist.clone())
|
|
|
|
|
.with_get("lang", |l: &mut Linux| l.lang.clone())
|
|
|
|
|
.with_get("active", |l: &mut Linux| l.active)
|
|
|
|
|
.with_get("password", |l: &mut Linux| l.password.clone())
|
|
|
|
|
.with_get("authorized_key", |l: &mut Linux| {
|
|
|
|
|
l.authorized_key.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("authorized_key", |l: &mut Linux| l.authorized_key.clone())
|
|
|
|
|
.with_get("host_key", |l: &mut Linux| l.host_key.clone())
|
|
|
|
|
.on_print(|l: &mut Linux| l.to_string())
|
|
|
|
|
.with_fn("pretty_print", |l: &mut Linux| l.to_string());
|
|
|
|
@@ -428,9 +418,7 @@ impl Plesk {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("Plesk")
|
|
|
|
|
.with_get("server_ip", |p: &mut Plesk| p.server_ip.clone())
|
|
|
|
|
.with_get("server_ipv6_net", |p: &mut Plesk| {
|
|
|
|
|
p.server_ipv6_net.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("server_ipv6_net", |p: &mut Plesk| p.server_ipv6_net.clone())
|
|
|
|
|
.with_get("server_number", |p: &mut Plesk| p.server_number)
|
|
|
|
|
.with_get("dist", |p: &mut Plesk| p.dist.clone())
|
|
|
|
|
.with_get("lang", |p: &mut Plesk| p.lang.clone())
|
|
|
|
@@ -558,10 +546,7 @@ impl fmt::Display for Cancellation {
|
|
|
|
|
table.add_row(row!["Server IP", self.server_ip.clone()]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Server IPv6 Net",
|
|
|
|
|
self.server_ipv6_net
|
|
|
|
|
.as_deref()
|
|
|
|
|
.unwrap_or("N/A")
|
|
|
|
|
.to_string()
|
|
|
|
|
self.server_ipv6_net.as_deref().unwrap_or("N/A").to_string()
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Server Number", self.server_number.to_string()]);
|
|
|
|
|
table.add_row(row!["Server Name", self.server_name.clone()]);
|
|
|
|
@@ -570,7 +555,10 @@ impl fmt::Display for Cancellation {
|
|
|
|
|
self.earliest_cancellation_date.clone()
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Cancelled", self.cancelled.to_string()]);
|
|
|
|
|
table.add_row(row!["Reservation Possible", self.reservation_possible.to_string()]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Reservation Possible",
|
|
|
|
|
self.reservation_possible.to_string()
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Reserved", self.reserved.to_string()]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Cancellation Date",
|
|
|
|
@@ -608,9 +596,7 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn option_string_or_seq_string<'de, D>(
|
|
|
|
|
deserializer: D,
|
|
|
|
|
) -> Result<Option<Vec<String>>, D::Error>
|
|
|
|
|
fn option_string_or_seq_string<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
|
|
|
|
where
|
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
|
{
|
|
|
|
@@ -645,7 +631,9 @@ impl From<reqwest::blocking::Response> for ApiError {
|
|
|
|
|
fn from(value: reqwest::blocking::Response) -> Self {
|
|
|
|
|
ApiError {
|
|
|
|
|
status: value.status().into(),
|
|
|
|
|
message: value.text().unwrap_or("The API call returned an error.".to_string()),
|
|
|
|
|
message: value
|
|
|
|
|
.text()
|
|
|
|
|
.unwrap_or("The API call returned an error.".to_string()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -788,7 +776,11 @@ pub struct OrderServerProduct {
|
|
|
|
|
pub traffic: String,
|
|
|
|
|
#[serde(deserialize_with = "string_or_seq_string")]
|
|
|
|
|
pub dist: Vec<String>,
|
|
|
|
|
#[serde(rename = "@deprecated arch", default, deserialize_with = "option_string_or_seq_string")]
|
|
|
|
|
#[serde(
|
|
|
|
|
rename = "@deprecated arch",
|
|
|
|
|
default,
|
|
|
|
|
deserialize_with = "option_string_or_seq_string"
|
|
|
|
|
)]
|
|
|
|
|
#[deprecated(note = "use `dist` instead")]
|
|
|
|
|
pub arch: Option<Vec<String>>,
|
|
|
|
|
#[serde(deserialize_with = "string_or_seq_string")]
|
|
|
|
@@ -805,14 +797,18 @@ impl OrderServerProduct {
|
|
|
|
|
.with_name("OrderServerProduct")
|
|
|
|
|
.with_get("id", |o: &mut OrderServerProduct| o.id.clone())
|
|
|
|
|
.with_get("name", |o: &mut OrderServerProduct| o.name.clone())
|
|
|
|
|
.with_get("description", |o: &mut OrderServerProduct| o.description.clone())
|
|
|
|
|
.with_get("description", |o: &mut OrderServerProduct| {
|
|
|
|
|
o.description.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("traffic", |o: &mut OrderServerProduct| o.traffic.clone())
|
|
|
|
|
.with_get("dist", |o: &mut OrderServerProduct| o.dist.clone())
|
|
|
|
|
.with_get("arch", |o: &mut OrderServerProduct| o.arch.clone())
|
|
|
|
|
.with_get("lang", |o: &mut OrderServerProduct| o.lang.clone())
|
|
|
|
|
.with_get("location", |o: &mut OrderServerProduct| o.location.clone())
|
|
|
|
|
.with_get("prices", |o: &mut OrderServerProduct| o.prices.clone())
|
|
|
|
|
.with_get("orderable_addons", |o: &mut OrderServerProduct| o.orderable_addons.clone())
|
|
|
|
|
.with_get("orderable_addons", |o: &mut OrderServerProduct| {
|
|
|
|
|
o.orderable_addons.clone()
|
|
|
|
|
})
|
|
|
|
|
.on_print(|o: &mut OrderServerProduct| o.to_string())
|
|
|
|
|
.with_fn("pretty_print", |o: &mut OrderServerProduct| o.to_string());
|
|
|
|
|
}
|
|
|
|
@@ -827,7 +823,10 @@ impl fmt::Display for OrderServerProduct {
|
|
|
|
|
table.add_row(row!["Description", self.description.join(", ")]);
|
|
|
|
|
table.add_row(row!["Traffic", self.traffic.clone()]);
|
|
|
|
|
table.add_row(row!["Distributions", self.dist.join(", ")]);
|
|
|
|
|
table.add_row(row!["Architectures", self.arch.as_deref().unwrap_or_default().join(", ")]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Architectures",
|
|
|
|
|
self.arch.as_deref().unwrap_or_default().join(", ")
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Languages", self.lang.join(", ")]);
|
|
|
|
|
table.add_row(row!["Locations", self.location.join(", ")]);
|
|
|
|
|
let mut prices_table = Table::new();
|
|
|
|
@@ -943,7 +942,9 @@ impl Transaction {
|
|
|
|
|
.with_get("status", |t: &mut Transaction| t.status.clone())
|
|
|
|
|
.with_get("server_number", |t: &mut Transaction| t.server_number)
|
|
|
|
|
.with_get("server_ip", |t: &mut Transaction| t.server_ip.clone())
|
|
|
|
|
.with_get("authorized_key", |t: &mut Transaction| t.authorized_key.clone())
|
|
|
|
|
.with_get("authorized_key", |t: &mut Transaction| {
|
|
|
|
|
t.authorized_key.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("host_key", |t: &mut Transaction| t.host_key.clone())
|
|
|
|
|
.with_get("comment", |t: &mut Transaction| t.comment.clone())
|
|
|
|
|
.with_get("product", |t: &mut Transaction| t.product.clone())
|
|
|
|
@@ -968,7 +969,9 @@ impl TransactionProduct {
|
|
|
|
|
.with_name("TransactionProduct")
|
|
|
|
|
.with_get("id", |p: &mut TransactionProduct| p.id.clone())
|
|
|
|
|
.with_get("name", |p: &mut TransactionProduct| p.name.clone())
|
|
|
|
|
.with_get("description", |p: &mut TransactionProduct| p.description.clone())
|
|
|
|
|
.with_get("description", |p: &mut TransactionProduct| {
|
|
|
|
|
p.description.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("traffic", |p: &mut TransactionProduct| p.traffic.clone())
|
|
|
|
|
.with_get("dist", |p: &mut TransactionProduct| p.dist.clone())
|
|
|
|
|
.with_get("arch", |p: &mut TransactionProduct| p.arch.clone())
|
|
|
|
@@ -1016,7 +1019,11 @@ pub struct AuctionServerProduct {
|
|
|
|
|
pub traffic: String,
|
|
|
|
|
#[serde(deserialize_with = "string_or_seq_string")]
|
|
|
|
|
pub dist: Vec<String>,
|
|
|
|
|
#[serde(rename = "@deprecated arch", default, deserialize_with = "option_string_or_seq_string")]
|
|
|
|
|
#[serde(
|
|
|
|
|
rename = "@deprecated arch",
|
|
|
|
|
default,
|
|
|
|
|
deserialize_with = "option_string_or_seq_string"
|
|
|
|
|
)]
|
|
|
|
|
#[deprecated(note = "use `dist` instead")]
|
|
|
|
|
pub arch: Option<Vec<String>>,
|
|
|
|
|
#[serde(deserialize_with = "string_or_seq_string")]
|
|
|
|
@@ -1050,29 +1057,53 @@ impl AuctionServerProduct {
|
|
|
|
|
.with_name("AuctionServerProduct")
|
|
|
|
|
.with_get("id", |p: &mut AuctionServerProduct| p.id)
|
|
|
|
|
.with_get("name", |p: &mut AuctionServerProduct| p.name.clone())
|
|
|
|
|
.with_get("description", |p: &mut AuctionServerProduct| p.description.clone())
|
|
|
|
|
.with_get("description", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.description.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("traffic", |p: &mut AuctionServerProduct| p.traffic.clone())
|
|
|
|
|
.with_get("dist", |p: &mut AuctionServerProduct| p.dist.clone())
|
|
|
|
|
.with_get("arch", |p: &mut AuctionServerProduct| p.arch.clone())
|
|
|
|
|
.with_get("lang", |p: &mut AuctionServerProduct| p.lang.clone())
|
|
|
|
|
.with_get("cpu", |p: &mut AuctionServerProduct| p.cpu.clone())
|
|
|
|
|
.with_get("cpu_benchmark", |p: &mut AuctionServerProduct| p.cpu_benchmark)
|
|
|
|
|
.with_get("cpu_benchmark", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.cpu_benchmark
|
|
|
|
|
})
|
|
|
|
|
.with_get("memory_size", |p: &mut AuctionServerProduct| p.memory_size)
|
|
|
|
|
.with_get("hdd_size", |p: &mut AuctionServerProduct| p.hdd_size)
|
|
|
|
|
.with_get("hdd_text", |p: &mut AuctionServerProduct| p.hdd_text.clone())
|
|
|
|
|
.with_get("hdd_text", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.hdd_text.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("hdd_count", |p: &mut AuctionServerProduct| p.hdd_count)
|
|
|
|
|
.with_get("datacenter", |p: &mut AuctionServerProduct| p.datacenter.clone())
|
|
|
|
|
.with_get("network_speed", |p: &mut AuctionServerProduct| p.network_speed.clone())
|
|
|
|
|
.with_get("datacenter", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.datacenter.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("network_speed", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.network_speed.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("price", |p: &mut AuctionServerProduct| p.price.clone())
|
|
|
|
|
.with_get("price_hourly", |p: &mut AuctionServerProduct| p.price_hourly.clone())
|
|
|
|
|
.with_get("price_setup", |p: &mut AuctionServerProduct| p.price_setup.clone())
|
|
|
|
|
.with_get("price_with_vat", |p: &mut AuctionServerProduct| p.price_with_vat.clone())
|
|
|
|
|
.with_get("price_hourly_with_vat", |p: &mut AuctionServerProduct| p.price_hourly_with_vat.clone())
|
|
|
|
|
.with_get("price_setup_with_vat", |p: &mut AuctionServerProduct| p.price_setup_with_vat.clone())
|
|
|
|
|
.with_get("price_hourly", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.price_hourly.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("price_setup", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.price_setup.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("price_with_vat", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.price_with_vat.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("price_hourly_with_vat", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.price_hourly_with_vat.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("price_setup_with_vat", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.price_setup_with_vat.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("fixed_price", |p: &mut AuctionServerProduct| p.fixed_price)
|
|
|
|
|
.with_get("next_reduce", |p: &mut AuctionServerProduct| p.next_reduce)
|
|
|
|
|
.with_get("next_reduce_date", |p: &mut AuctionServerProduct| p.next_reduce_date.clone())
|
|
|
|
|
.with_get("orderable_addons", |p: &mut AuctionServerProduct| p.orderable_addons.clone())
|
|
|
|
|
.with_get("next_reduce_date", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.next_reduce_date.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("orderable_addons", |p: &mut AuctionServerProduct| {
|
|
|
|
|
p.orderable_addons.clone()
|
|
|
|
|
})
|
|
|
|
|
.on_print(|p: &mut AuctionServerProduct| p.to_string())
|
|
|
|
|
.with_fn("pretty_print", |p: &mut AuctionServerProduct| p.to_string());
|
|
|
|
|
}
|
|
|
|
@@ -1087,7 +1118,10 @@ impl fmt::Display for AuctionServerProduct {
|
|
|
|
|
table.add_row(row!["Description", self.description.join(", ")]);
|
|
|
|
|
table.add_row(row!["Traffic", self.traffic.clone()]);
|
|
|
|
|
table.add_row(row!["Distributions", self.dist.join(", ")]);
|
|
|
|
|
table.add_row(row!["Architectures", self.arch.as_deref().unwrap_or_default().join(", ")]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Architectures",
|
|
|
|
|
self.arch.as_deref().unwrap_or_default().join(", ")
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Languages", self.lang.join(", ")]);
|
|
|
|
|
table.add_row(row!["CPU", self.cpu.clone()]);
|
|
|
|
|
table.add_row(row!["CPU Benchmark", self.cpu_benchmark.to_string()]);
|
|
|
|
@@ -1098,10 +1132,19 @@ impl fmt::Display for AuctionServerProduct {
|
|
|
|
|
table.add_row(row!["Datacenter", self.datacenter.clone()]);
|
|
|
|
|
table.add_row(row!["Network Speed", self.network_speed.clone()]);
|
|
|
|
|
table.add_row(row!["Price (Net)", self.price.clone()]);
|
|
|
|
|
table.add_row(row!["Price (Hourly Net)", self.price_hourly.as_deref().unwrap_or("N/A").to_string()]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Price (Hourly Net)",
|
|
|
|
|
self.price_hourly.as_deref().unwrap_or("N/A").to_string()
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Price (Setup Net)", self.price_setup.clone()]);
|
|
|
|
|
table.add_row(row!["Price (VAT)", self.price_with_vat.clone()]);
|
|
|
|
|
table.add_row(row!["Price (Hourly VAT)", self.price_hourly_with_vat.as_deref().unwrap_or("N/A").to_string()]);
|
|
|
|
|
table.add_row(row![
|
|
|
|
|
"Price (Hourly VAT)",
|
|
|
|
|
self.price_hourly_with_vat
|
|
|
|
|
.as_deref()
|
|
|
|
|
.unwrap_or("N/A")
|
|
|
|
|
.to_string()
|
|
|
|
|
]);
|
|
|
|
|
table.add_row(row!["Price (Setup VAT)", self.price_setup_with_vat.clone()]);
|
|
|
|
|
table.add_row(row!["Fixed Price", self.fixed_price.to_string()]);
|
|
|
|
|
table.add_row(row!["Next Reduce (seconds)", self.next_reduce.to_string()]);
|
|
|
|
@@ -1165,7 +1208,7 @@ pub struct AuctionTransactionProduct {
|
|
|
|
|
pub traffic: String,
|
|
|
|
|
pub dist: String,
|
|
|
|
|
#[serde(rename = "@deprecated arch")]
|
|
|
|
|
pub arch: String,
|
|
|
|
|
pub arch: Option<String>,
|
|
|
|
|
pub lang: String,
|
|
|
|
|
pub cpu: String,
|
|
|
|
|
pub cpu_benchmark: i32,
|
|
|
|
@@ -1175,9 +1218,9 @@ pub struct AuctionTransactionProduct {
|
|
|
|
|
pub hdd_count: i32,
|
|
|
|
|
pub datacenter: String,
|
|
|
|
|
pub network_speed: String,
|
|
|
|
|
pub fixed_price: bool,
|
|
|
|
|
pub next_reduce: i32,
|
|
|
|
|
pub next_reduce_date: String,
|
|
|
|
|
pub fixed_price: Option<bool>,
|
|
|
|
|
pub next_reduce: Option<i32>,
|
|
|
|
|
pub next_reduce_date: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AuctionTransaction {
|
|
|
|
@@ -1187,38 +1230,21 @@ impl AuctionTransaction {
|
|
|
|
|
.with_get("id", |t: &mut AuctionTransaction| t.id.clone())
|
|
|
|
|
.with_get("date", |t: &mut AuctionTransaction| t.date.clone())
|
|
|
|
|
.with_get("status", |t: &mut AuctionTransaction| t.status.clone())
|
|
|
|
|
.with_get("server_number", |t: &mut AuctionTransaction| t.server_number)
|
|
|
|
|
.with_get("server_ip", |t: &mut AuctionTransaction| t.server_ip.clone())
|
|
|
|
|
.with_get("authorized_key", |t: &mut AuctionTransaction| t.authorized_key.clone())
|
|
|
|
|
.with_get("server_number", |t: &mut AuctionTransaction| {
|
|
|
|
|
t.server_number
|
|
|
|
|
})
|
|
|
|
|
.with_get("server_ip", |t: &mut AuctionTransaction| {
|
|
|
|
|
t.server_ip.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("authorized_key", |t: &mut AuctionTransaction| {
|
|
|
|
|
t.authorized_key.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("host_key", |t: &mut AuctionTransaction| t.host_key.clone())
|
|
|
|
|
.with_get("comment", |t: &mut AuctionTransaction| t.comment.clone())
|
|
|
|
|
.with_get("product", |t: &mut AuctionTransaction| t.product.clone())
|
|
|
|
|
.with_get("addons", |t: &mut AuctionTransaction| t.addons.clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AuctionTransactionProduct {
|
|
|
|
|
fn build_rhai_type(builder: &mut TypeBuilder<Self>) {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("AuctionTransactionProduct")
|
|
|
|
|
.with_get("id", |p: &mut AuctionTransactionProduct| p.id)
|
|
|
|
|
.with_get("name", |p: &mut AuctionTransactionProduct| p.name.clone())
|
|
|
|
|
.with_get("description", |p: &mut AuctionTransactionProduct| p.description.clone())
|
|
|
|
|
.with_get("traffic", |p: &mut AuctionTransactionProduct| p.traffic.clone())
|
|
|
|
|
.with_get("dist", |p: &mut AuctionTransactionProduct| p.dist.clone())
|
|
|
|
|
.with_get("arch", |p: &mut AuctionTransactionProduct| p.arch.clone())
|
|
|
|
|
.with_get("lang", |p: &mut AuctionTransactionProduct| p.lang.clone())
|
|
|
|
|
.with_get("cpu", |p: &mut AuctionTransactionProduct| p.cpu.clone())
|
|
|
|
|
.with_get("cpu_benchmark", |p: &mut AuctionTransactionProduct| p.cpu_benchmark)
|
|
|
|
|
.with_get("memory_size", |p: &mut AuctionTransactionProduct| p.memory_size)
|
|
|
|
|
.with_get("hdd_size", |p: &mut AuctionTransactionProduct| p.hdd_size)
|
|
|
|
|
.with_get("hdd_text", |p: &mut AuctionTransactionProduct| p.hdd_text.clone())
|
|
|
|
|
.with_get("hdd_count", |p: &mut AuctionTransactionProduct| p.hdd_count)
|
|
|
|
|
.with_get("datacenter", |p: &mut AuctionTransactionProduct| p.datacenter.clone())
|
|
|
|
|
.with_get("network_speed", |p: &mut AuctionTransactionProduct| p.network_speed.clone())
|
|
|
|
|
.with_get("fixed_price", |p: &mut AuctionTransactionProduct| p.fixed_price)
|
|
|
|
|
.with_get("next_reduce", |p: &mut AuctionTransactionProduct| p.next_reduce)
|
|
|
|
|
.with_get("next_reduce_date", |p: &mut AuctionTransactionProduct| p.next_reduce_date.clone());
|
|
|
|
|
.with_get("addons", |t: &mut AuctionTransaction| t.addons.clone())
|
|
|
|
|
.on_print(|t: &mut AuctionTransaction| t.to_string())
|
|
|
|
|
.with_fn("pretty_print", |t: &mut AuctionTransaction| t.to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1237,7 +1263,7 @@ impl fmt::Display for AuctionTransaction {
|
|
|
|
|
table.add_row(row!["Product Description", self.product.description.join(", ")]);
|
|
|
|
|
table.add_row(row!["Product Traffic", self.product.traffic.clone()]);
|
|
|
|
|
table.add_row(row!["Product Distributions", self.product.dist.clone()]);
|
|
|
|
|
table.add_row(row!["Product Architectures", self.product.arch.clone()]);
|
|
|
|
|
table.add_row(row!["Product Architectures", self.product.arch.as_deref().unwrap_or("N/A")]);
|
|
|
|
|
table.add_row(row!["Product Languages", self.product.lang.clone()]);
|
|
|
|
|
table.add_row(row!["Product CPU", self.product.cpu.clone()]);
|
|
|
|
|
table.add_row(row!["Product CPU Benchmark", self.product.cpu_benchmark.to_string()]);
|
|
|
|
@@ -1247,9 +1273,9 @@ impl fmt::Display for AuctionTransaction {
|
|
|
|
|
table.add_row(row!["Product HDD Count", self.product.hdd_count.to_string()]);
|
|
|
|
|
table.add_row(row!["Product Datacenter", self.product.datacenter.clone()]);
|
|
|
|
|
table.add_row(row!["Product Network Speed", self.product.network_speed.clone()]);
|
|
|
|
|
table.add_row(row!["Product Fixed Price", self.product.fixed_price.to_string()]);
|
|
|
|
|
table.add_row(row!["Product Next Reduce (seconds)", self.product.next_reduce.to_string()]);
|
|
|
|
|
table.add_row(row!["Product Next Reduce Date", self.product.next_reduce_date.clone()]);
|
|
|
|
|
table.add_row(row!["Product Fixed Price", self.product.fixed_price.unwrap_or_default().to_string()]);
|
|
|
|
|
table.add_row(row!["Product Next Reduce (seconds)", self.product.next_reduce.map_or("N/A".to_string(), |r| r.to_string())]);
|
|
|
|
|
table.add_row(row!["Product Next Reduce Date", self.product.next_reduce_date.as_deref().unwrap_or("N/A")]);
|
|
|
|
|
table.add_row(row!["Addons", self.addons.join(", ")]);
|
|
|
|
|
|
|
|
|
|
let mut authorized_keys_table = Table::new();
|
|
|
|
@@ -1267,14 +1293,144 @@ impl fmt::Display for AuctionTransaction {
|
|
|
|
|
let mut host_keys_table = Table::new();
|
|
|
|
|
host_keys_table.add_row(row![b => "Fingerprint", "Type", "Size"]);
|
|
|
|
|
for key in &self.host_key {
|
|
|
|
|
host_keys_table.add_row(row![
|
|
|
|
|
key.key.fingerprint,
|
|
|
|
|
key.key.key_type,
|
|
|
|
|
key.key.size
|
|
|
|
|
]);
|
|
|
|
|
host_keys_table.add_row(row![key.key.fingerprint, key.key.key_type, key.key.size]);
|
|
|
|
|
}
|
|
|
|
|
table.add_row(row!["Host Keys", host_keys_table]);
|
|
|
|
|
|
|
|
|
|
write!(f, "{}", table)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AuctionTransactionProduct {
|
|
|
|
|
fn build_rhai_type(builder: &mut TypeBuilder<Self>) {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("AuctionTransactionProduct")
|
|
|
|
|
.with_get("id", |p: &mut AuctionTransactionProduct| p.id)
|
|
|
|
|
.with_get("name", |p: &mut AuctionTransactionProduct| p.name.clone())
|
|
|
|
|
.with_get("description", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.description.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("traffic", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.traffic.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("dist", |p: &mut AuctionTransactionProduct| p.dist.clone())
|
|
|
|
|
.with_get("arch", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.arch.clone().unwrap_or_default()
|
|
|
|
|
})
|
|
|
|
|
.with_get("lang", |p: &mut AuctionTransactionProduct| p.lang.clone())
|
|
|
|
|
.with_get("cpu", |p: &mut AuctionTransactionProduct| p.cpu.clone())
|
|
|
|
|
.with_get("cpu_benchmark", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.cpu_benchmark
|
|
|
|
|
})
|
|
|
|
|
.with_get("memory_size", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.memory_size
|
|
|
|
|
})
|
|
|
|
|
.with_get("hdd_size", |p: &mut AuctionTransactionProduct| p.hdd_size)
|
|
|
|
|
.with_get("hdd_text", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.hdd_text.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("hdd_count", |p: &mut AuctionTransactionProduct| p.hdd_count)
|
|
|
|
|
.with_get("datacenter", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.datacenter.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("network_speed", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.network_speed.clone()
|
|
|
|
|
})
|
|
|
|
|
.with_get("fixed_price", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.fixed_price.unwrap_or_default()
|
|
|
|
|
})
|
|
|
|
|
.with_get("next_reduce", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.next_reduce.unwrap_or_default()
|
|
|
|
|
})
|
|
|
|
|
.with_get("next_reduce_date", |p: &mut AuctionTransactionProduct| {
|
|
|
|
|
p.next_reduce_date.clone().unwrap_or_default()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone, CustomType)]
|
|
|
|
|
#[rhai_type(extra = Self::build_rhai_type)]
|
|
|
|
|
pub struct OrderAuctionServerBuilder {
|
|
|
|
|
pub product_id: i64,
|
|
|
|
|
pub authorized_keys: Option<Vec<String>>,
|
|
|
|
|
pub dist: Option<String>,
|
|
|
|
|
pub lang: Option<String>,
|
|
|
|
|
pub comment: Option<String>,
|
|
|
|
|
pub addon: Option<Vec<String>>,
|
|
|
|
|
pub test: Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OrderAuctionServerBuilder {
|
|
|
|
|
pub fn new(product_id: i64) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
product_id,
|
|
|
|
|
authorized_keys: None,
|
|
|
|
|
dist: None,
|
|
|
|
|
lang: None,
|
|
|
|
|
comment: None,
|
|
|
|
|
addon: None,
|
|
|
|
|
// by default test is enabled
|
|
|
|
|
test: Some(true),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_authorized_keys(mut self, keys: Array) -> Self {
|
|
|
|
|
let authorized_keys: Vec<String> = if keys.is_empty() {
|
|
|
|
|
vec![]
|
|
|
|
|
} else if keys[0].is::<SshKey>() {
|
|
|
|
|
keys.into_iter()
|
|
|
|
|
.map(|k| k.cast::<SshKey>().fingerprint)
|
|
|
|
|
.collect()
|
|
|
|
|
} else {
|
|
|
|
|
keys.into_iter().map(|k| k.into_string().unwrap()).collect()
|
|
|
|
|
};
|
|
|
|
|
self.authorized_keys = Some(authorized_keys);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_dist(mut self, dist: &str) -> Self {
|
|
|
|
|
self.dist = Some(dist.to_string());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_lang(mut self, lang: &str) -> Self {
|
|
|
|
|
self.lang = Some(lang.to_string());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_comment(mut self, comment: &str) -> Self {
|
|
|
|
|
self.comment = Some(comment.to_string());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_addon(mut self, addon: Array) -> Self {
|
|
|
|
|
let addons = addon
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|a| a.into_string().unwrap())
|
|
|
|
|
.collect();
|
|
|
|
|
self.addon = Some(addons);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_test(mut self, test: bool) -> Self {
|
|
|
|
|
self.test = Some(test);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build_rhai_type(builder: &mut TypeBuilder<Self>) {
|
|
|
|
|
builder
|
|
|
|
|
.with_name("OrderAuctionServerBuilder")
|
|
|
|
|
.with_fn("new_auction_server_builder", Self::new)
|
|
|
|
|
.with_fn("with_authorized_keys", Self::with_authorized_keys)
|
|
|
|
|
.with_fn("with_dist", Self::with_dist)
|
|
|
|
|
.with_fn("with_lang", Self::with_lang)
|
|
|
|
|
.with_fn("with_comment", Self::with_comment)
|
|
|
|
|
.with_fn("with_addon", Self::with_addon)
|
|
|
|
|
.with_fn("with_test", Self::with_test)
|
|
|
|
|
// TODO implement other getters
|
|
|
|
|
.with_get("comment", |b: &mut OrderAuctionServerBuilder| {
|
|
|
|
|
b.comment.clone().unwrap_or("".to_string())
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|