feat(tools):增加生成证书文件的命令行功能。
This commit is contained in:
parent
1f7ff5e66a
commit
bf3add13a3
|
@ -7,3 +7,6 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
cert_lib = { path = "../cert_lib" }
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
|
|
28
cert_tools/src/generate_key.rs
Normal file
28
cert_tools/src/generate_key.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use clap::Args;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct GenerateKeyOptions {
|
||||
#[arg(short, long, help = "set certificate file version")]
|
||||
version: Option<i32>,
|
||||
#[arg(short, long, help = "set where certification file stores")]
|
||||
output_path: Option<String>,
|
||||
#[arg(short, long, help = "set certification serial number")]
|
||||
serial: Option<u32>,
|
||||
#[arg(short = 'p', long, help = "set certification validity periods")]
|
||||
validity_periods: Option<u32>,
|
||||
#[arg(help = "set certification file name")]
|
||||
name: String,
|
||||
}
|
||||
|
||||
pub fn generate_key_file(options: GenerateKeyOptions) {
|
||||
if let Err(e) = cert_lib::generate_certificate(
|
||||
options.output_path.unwrap_or(String::from(".")).as_ref(),
|
||||
&options.name,
|
||||
4096,
|
||||
options.validity_periods.unwrap_or(365),
|
||||
options.version.unwrap_or(1),
|
||||
options.serial,
|
||||
) {
|
||||
println!("Failed to generate certificate, due to: {}", e.to_string());
|
||||
}
|
||||
}
|
|
@ -1,3 +1,35 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::{Parser, Subcommand};
|
||||
use generate_key::{generate_key_file, GenerateKeyOptions};
|
||||
use power_equal::PowerEqualResultOption;
|
||||
|
||||
mod generate_key;
|
||||
mod power_equal;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(
|
||||
name = "cert-tools",
|
||||
version = "0.1",
|
||||
about = "A tool for managing license server certificates"
|
||||
)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands {
|
||||
#[command(about = "Generate a new certificate")]
|
||||
Generate(GenerateKeyOptions),
|
||||
#[command(about = "Calculate the equal result for power plugin")]
|
||||
CalcEqual(PowerEqualResultOption),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Cli::parse();
|
||||
match args.command {
|
||||
Commands::Generate(options) => generate_key_file(options),
|
||||
Commands::CalcEqual(_options) => {
|
||||
println!("Calculating the equal result for power plugin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
cert_tools/src/power_equal.rs
Normal file
9
cert_tools/src/power_equal.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct PowerEqualResultOption {
|
||||
#[arg(help = "Certificate file")]
|
||||
key_file: PathBuf,
|
||||
}
|
Loading…
Reference in New Issue
Block a user