Add color to status

This commit is contained in:
Pierre HUBERT 2025-03-06 15:11:54 +01:00
parent 672549a86d
commit f506835b53
3 changed files with 27 additions and 3 deletions

17
Cargo.lock generated
View File

@ -181,6 +181,16 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "colored"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
dependencies = [
"lazy_static",
"windows-sys",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.17" version = "0.2.17"
@ -455,6 +465,12 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.170" version = "0.2.170"
@ -575,6 +591,7 @@ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
"clap", "clap",
"colored",
"env_logger", "env_logger",
"http", "http",
"log", "log",

View File

@ -11,4 +11,5 @@ http = { version = "1.2.0" }
anyhow = "1.0.97" anyhow = "1.0.97"
url = "2.5.4" url = "2.5.4"
base64 = "0.22.1" base64 = "0.22.1"
sha256 = "1.6.0" sha256 = "1.6.0"
colored = "2"

View File

@ -6,6 +6,7 @@ use sha256::{digest, Sha256Digest};
use url::Url; use url::Url;
use base64::prelude::*; use base64::prelude::*;
use base64::engine::general_purpose::URL_SAFE as BASE64_URL_URL_SAFE; use base64::engine::general_purpose::URL_SAFE as BASE64_URL_URL_SAFE;
use colored::Colorize;
/// Simple SCEP parser program /// Simple SCEP parser program
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -141,13 +142,18 @@ fn main() {
_ => panic!("Unsupported operation {}!", operation), _ => panic!("Unsupported operation {}!", operation),
}; };
let status = match response.status().as_u16() {
100..=199=> response.status().as_u16().to_string().blue(),
200..=299 => response.status().as_u16().to_string().green(),
400..=999 => response.status().as_u16().to_string().red(),
_ => response.status().as_u16().to_string().white().on_red(),
};
let date = response.headers().get("Date").unwrap().to_str().unwrap(); let date = response.headers().get("Date").unwrap().to_str().unwrap();
let sha_req = sha256::digest(request.body()).chars().take(10).collect::<String>(); let sha_req = sha256::digest(request.body()).chars().take(10).collect::<String>();
let sha_res = sha256::digest(response.body()).chars().take(10).collect::<String>(); let sha_res = sha256::digest(response.body()).chars().take(10).collect::<String>();
// TODO : add color println!("{date} - {status} - {op:?}\t - Req: {sha_req}\t - Res: {sha_res}");
println!("{date} - {} - {op:?}\t - Req: {sha_req}\t - Res: {sha_res}", response.status().as_u16());
// Parse details about PKIOperation request // Parse details about PKIOperation request
// https://www.rfc-editor.org/rfc/rfc8894.html#section-4.3 // https://www.rfc-editor.org/rfc/rfc8894.html#section-4.3