Skip to content

Commit

Permalink
transform CLI command "query certificates" to "certificate get"
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 22, 2023
1 parent 9085a20 commit acdc8c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
27 changes: 17 additions & 10 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ pub enum SubCmd {
},
#[clap(name = "certificate", about = "certificate management")]
Certificate {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format",
global = true
)]
json: bool,
#[clap(subcommand)]
cmd: CertificateCmd,
},
Expand Down Expand Up @@ -743,6 +750,16 @@ pub enum TcpListenerCmd {

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
pub enum CertificateCmd {
#[clap(
name = "get",
about = "query certificates, all or filtered by fingerprint or domain name"
)]
Get {
#[clap(short = 'f', long = "fingerprint", help = "certificate fingerprint")]
fingerprint: Option<String>,
#[clap(short = 'd', long = "domain", help = "domain name of the queried certificates")]
domain: Option<String>,
},
#[clap(name = "add", about = "Add a certificate")]
Add {
#[clap(
Expand Down Expand Up @@ -818,16 +835,6 @@ pub enum QueryCmd {
#[clap(short = 'd', long = "domain", help = "cluster domain name")]
domain: Option<String>,
},
#[clap(
name = "certificates",
about = "Query certificates matching a specific filter"
)]
Certificates {
#[clap(short = 'f', long = "fingerprint", help = "certificate fingerprint")]
fingerprint: Option<String>,
#[clap(short = 'd', long = "domain", help = "domain name")]
domain: Option<String>,
},
}

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl CommandManager {
Ok(())
}

pub fn query_certificate(
pub fn query_certificates(
&mut self,
json: bool,
fingerprint: Option<String>,
Expand Down Expand Up @@ -400,7 +400,7 @@ impl CommandManager {
print_json_response(&response.message)?;
bail!("We received an error message");
} else {
bail!("could not query proxy state: {}", response.message);
bail!("could not get certificate: {}", response.message);
}
}
ResponseStatus::Ok => {
Expand Down
10 changes: 5 additions & 5 deletions bin/src/ctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ impl CommandManager {
ListenerCmd::Tcp { cmd } => self.tcp_listener_command(cmd),
ListenerCmd::List => self.list_listeners(),
},
SubCmd::Certificate { cmd } => match cmd {
SubCmd::Certificate { cmd, json } => match cmd {
CertificateCmd::Get {
fingerprint,
domain,
} => self.query_certificates(json, fingerprint, domain),
CertificateCmd::Add {
certificate,
chain,
Expand Down Expand Up @@ -146,10 +150,6 @@ impl CommandManager {
},
SubCmd::Query { cmd, json } => match cmd {
QueryCmd::Clusters { id, domain } => self.query_cluster(json, id, domain),
QueryCmd::Certificates {
fingerprint,
domain,
} => self.query_certificate(json, fingerprint, domain),
},
SubCmd::Config { cmd: _ } => Ok(()), // noop, handled at the beginning of the method
SubCmd::Events => self.events(),
Expand Down

0 comments on commit acdc8c9

Please sign in to comment.