Skip to content

Commit

Permalink
create Request::QueryCertificateByFingerprint
Browse files Browse the repository at this point in the history
remove QueryCertificateType
  • Loading branch information
Keksoj committed Mar 22, 2023
1 parent 145d061 commit 81f4f39
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
10 changes: 6 additions & 4 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl CommandServer {
}
Request::Status => self.status(client_id).await,

Request::QueryCertificates(_)
Request::QueryCertificateByFingerprint(_)
| Request::QueryCertificatesByDomain(_)
| Request::QueryAllCertificates
| Request::QueryClusters(_)
| Request::QueryClustersHashes
| Request::QueryMetrics(_) => self.query(client_id, request).await,
Expand Down Expand Up @@ -1068,8 +1070,6 @@ impl CommandServer {
}
}));
}
Request::QueryCertificates(_) => {}
Request::QueryMetrics(_) => {}
_ => {}
};

Expand Down Expand Up @@ -1121,7 +1121,9 @@ impl CommandServer {
worker_responses.insert(String::from("main"), main);
ResponseContent::WorkerResponses(worker_responses)
}
&Request::QueryCertificates(_) => {
&Request::QueryCertificatesByDomain(_)
| &Request::QueryCertificateByFingerprint(_)
| &Request::QueryAllCertificates => {
info!("certificates query answer received: {:?}", worker_responses);
ResponseContent::WorkerResponses(worker_responses)
}
Expand Down
6 changes: 2 additions & 4 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use serde::Serialize;

use sozu_command_lib::{
request::{
QueryCertificateType, QueryClusterDomain, QueryClusterType, QueryMetricsOptions, Request,
},
request::{QueryClusterDomain, QueryClusterType, QueryMetricsOptions, Request},
response::{Response, ResponseContent, ResponseStatus, RunState, WorkerInfo},
};

Expand Down Expand Up @@ -393,7 +391,7 @@ impl CommandManager {
Err(e) => {
bail!("invalid fingerprint: {:?}", e);
}
Ok(f) => Request::QueryCertificates(QueryCertificateType::Fingerprint(f)),
Ok(f) => Request::QueryCertificateByFingerprint(f),
},
(None, Some(d)) => Request::QueryCertificatesByDomain(d),
(Some(_), Some(_)) => {
Expand Down
14 changes: 4 additions & 10 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ pub enum Request {
DeactivateListener(DeactivateListener),

QueryAllCertificates,
QueryCertificateByFingerprint(Vec<u8>),
QueryCertificatesByDomain(String),
QueryCertificates(QueryCertificateType),

QueryClusters(QueryClusterType),
QueryClustersHashes,
QueryMetrics(QueryMetricsOptions),
Expand Down Expand Up @@ -114,9 +115,9 @@ impl Request {
| Request::AddCertificate(_)
| Request::QueryAllCertificates
| Request::QueryCertificatesByDomain(_)
| Request::QueryCertificateByFingerprint(_)
| Request::ReplaceCertificate(_)
| Request::RemoveCertificate(_)
| Request::QueryCertificates(_) => proxy_destination.to_https_proxy = true,
| Request::RemoveCertificate(_) => proxy_destination.to_https_proxy = true,

Request::AddTcpFrontend(_) | Request::RemoveTcpFrontend(_) => {
proxy_destination.to_tcp_proxy = true
Expand Down Expand Up @@ -385,13 +386,6 @@ pub struct QueryClusterDomain {
pub path: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum QueryCertificateType {
// Domain(String),
Fingerprint(Vec<u8>),
}

/// Options originating from the command line
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "SCREAMING_SNAKE_CASE")]
Expand Down
1 change: 0 additions & 1 deletion command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl ConfigState {
&Request::Logging(_)
| &Request::Status
| &Request::SoftStop
| &Request::QueryCertificates(_)
| &Request::QueryClusters(_)
| &Request::QueryMetrics(_)
| &Request::QueryClustersHashes
Expand Down
28 changes: 12 additions & 16 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use sozu_command::{
config::Config,
ready::Ready,
request::{
ActivateListener, AddBackend, Cluster, DeactivateListener, ListenerType,
QueryCertificateType, QueryClusterType, RemoveBackend, Request, WorkerRequest,
ActivateListener, AddBackend, Cluster, DeactivateListener, ListenerType, QueryClusterType,
RemoveBackend, Request, WorkerRequest,
},
response::{
Event, HttpListenerConfig, HttpsListenerConfig, MessageId, ResponseContent, ResponseStatus,
Expand Down Expand Up @@ -907,20 +907,16 @@ impl Server {
push_queue(WorkerResponse::ok_with_content(message.id.clone(), content));
return;
}
Request::QueryCertificates(q) => {
match q {
// forward the query to the TLS implementation
QueryCertificateType::Fingerprint(f) => {
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ResponseContent::CertificateByFingerprint(get_certificate(
&self.config_state,
f,
)),
));
return;
}
}
Request::QueryCertificateByFingerprint(f) => {
// forward the query to the TLS implementation
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ResponseContent::CertificateByFingerprint(get_certificate(
&self.config_state,
f,
)),
));
return;
}
Request::QueryMetrics(query_metrics_options) => {
METRICS.with(|metrics| {
Expand Down

0 comments on commit 81f4f39

Please sign in to comment.