Skip to content

Commit

Permalink
merge certificate types in CertificatesWithFingerprints
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 22, 2023
1 parent a71f485 commit 4776d5f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 57 deletions.
16 changes: 7 additions & 9 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use sozu_command_lib::{
logging,
parser::parse_several_commands,
proto::command::{
request::RequestType, response_content::ContentType, AggregatedMetrics,
AllCertificatesInTheState, AvailableMetrics, CertificatesMatchingADomainName,
CertificatesMatchingAFingerprint, ClusterHashes, ClusterInformations, FrontendFilters,
request::RequestType, response_content::ContentType, AggregatedMetrics, AvailableMetrics,
CertificatesWithFingerprints, ClusterHashes, ClusterInformations, FrontendFilters,
MetricsConfiguration, Request, Response, ResponseContent, ResponseStatus,
ReturnListenSockets, RunState, SoftStop, Status, WorkerInfo, WorkerInfos, WorkerResponses,
},
Expand Down Expand Up @@ -394,7 +393,7 @@ impl CommandServer {
let certs = self.state.get_certificates_by_domain_name(domain_name);

Ok(Some(Success::CertificatesByDomainNameFromTheState(
ContentType::CertificatesMatchingADomainName(CertificatesMatchingADomainName { certs })
ContentType::CertificatesWithFingerprints(CertificatesWithFingerprints { certs })
.into(),
)))
}
Expand All @@ -406,18 +405,17 @@ impl CommandServer {
let certs = self.state.get_certificate_by_fingerprint(fingerprint);

Ok(Some(Success::CertificatesByFingerprintFromTheState(
ContentType::CertificatesMatchingAFingerprint(CertificatesMatchingAFingerprint {
certs,
})
.into(),
ContentType::CertificatesWithFingerprints(CertificatesWithFingerprints { certs })
.into(),
)))
}

pub fn query_all_certificates_in_the_state(&self) -> anyhow::Result<Option<Success>> {
let certs = self.state.get_all_certificates();

Ok(Some(Success::AllCertificatesInTheState(
ContentType::AllCertificatesInTheState(AllCertificatesInTheState { certs }).into(),
ContentType::CertificatesWithFingerprints(CertificatesWithFingerprints { certs })
.into(),
)))
}

Expand Down
5 changes: 1 addition & 4 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,7 @@ impl CommandManager {

if let Some(response_content) = response.content {
let certs = match response_content.content_type {
Some(ContentType::CertificatesMatchingADomainName(certs)) => {
certs.certs
}
Some(ContentType::AllCertificatesInTheState(certs)) => certs.certs,
Some(ContentType::CertificatesWithFingerprints(certs)) => certs.certs,
_ => bail!(format!("Wrong response content {:?}", response_content)),
};
if certs.is_empty() {
Expand Down
14 changes: 5 additions & 9 deletions bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use prettytable::{Row, Table};
use sozu_command_lib::proto::{
command::{
filtered_metrics, response_content::ContentType, AggregatedMetrics, AvailableMetrics,
CertificateAndKey, CertificatesMatchingAFingerprint, ClusterMetrics, FilteredMetrics,
CertificateAndKey, CertificatesWithFingerprints, ClusterMetrics, FilteredMetrics,
ListedFrontends, ListenersList, ResponseContent, WorkerInfos, WorkerMetrics,
},
display::concatenate_vector,
Expand Down Expand Up @@ -660,14 +660,10 @@ pub fn print_certificates(
println!();
}
}
Some(ContentType::CertificatesMatchingAFingerprint(
CertificatesMatchingAFingerprint { certs },
)) => print_certificates_with_validity(certs.clone())?,
Some(ContentType::CertificatesMatchingADomainName(certs)) => {
for (fingerprint, cert) in &certs.certs {
println!("\tfingerprint: {}\n\tcertificate: {}", fingerprint, cert);
}
}
Some(ContentType::CertificatesWithFingerprints(CertificatesWithFingerprints {
certs,
})) => print_certificates_with_validity(certs.clone())?,

_ => {}
}
println!();
Expand Down
32 changes: 6 additions & 26 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ message CertificateSummary {
required string fingerprint = 2;
}

// Used by workers to reply to some certificate queries
message ListOfCertificatesByAddress {
repeated CertificatesByAddress certificates = 1;
}
Expand All @@ -323,26 +324,12 @@ message CertificateWithNames {
repeated string names = 2;
}

// TODO: tidy this up
// to reply to QueryCertificateByDomainInTheState
message CertificatesMatchingADomainName {
// to reply to several certificate queries
message CertificatesWithFingerprints {
// a map of fingerprint -> certificate_and_key
map<string, CertificateAndKey> certs = 1;
}

// to reply to QueryAllCertificatesInTheState
message AllCertificatesInTheState {
// a map of fingerprint -> certificate_and_key
map<string, CertificateAndKey> certs = 1;
}

// to reply to QueryCertificateByFingerprintInTheState
message CertificatesMatchingAFingerprint {
// a map of fingerprint -> certificate_and_key
map<string, CertificateAndKey> certs = 1;
}


enum TlsVersion {
SSL_V2 = 0;
SSL_V3 = 1;
Expand Down Expand Up @@ -471,17 +458,10 @@ message ResponseContent {
ClusterInformations clusters = 9;
// collection of hashes of cluster information,
ClusterHashes cluster_hashes = 10;
// a list of certificates for each socket address
// a list of certificates, sorted by socket address, returned by workers
ListOfCertificatesByAddress certificates = 11;
// returns the certificate matching a request by fingerprint,
// and the list of domain names associated
CertificatesMatchingAFingerprint certificate_by_fingerprint = 12;
// to reply to QueryCertificateByDomainInTheState
CertificatesMatchingADomainName certificates_matching_a_domain_name = 13;
// to reply to QueryAllCertificatesInTheState
AllCertificatesInTheState all_certificates_in_the_state = 14;
// to reply to QueryCertificateByFingerprintInTheState
CertificatesMatchingAFingerprint certificates_matching_a_fingerprint = 15;
// a map of complete certificates using fingerprints as key
CertificatesWithFingerprints certificates_with_fingerprints = 12;
}
}

Expand Down
17 changes: 8 additions & 9 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ use mio::{
};
use slab::Slab;
use sozu_command::{
certificate::Fingerprint,
channel::Channel,
config::Config,
proto::command::{
request::RequestType, response_content::ContentType, ActivateListener, AddBackend,
CertificatesMatchingAFingerprint, Cluster, ClusterHashes, ClusterInformations,
DeactivateListener, Event, HttpListenerConfig, HttpsListenerConfig, ListenerType,
LoadBalancingAlgorithms, LoadMetric, MetricsConfiguration, RemoveBackend, ResponseStatus,
TcpListenerConfig as CommandTcpListener,
request::RequestType, response_content::ContentType, ActivateListener, AddBackend, Cluster,
ClusterHashes, ClusterInformations, DeactivateListener, Event, HttpListenerConfig,
HttpsListenerConfig, ListenerType, LoadBalancingAlgorithms, LoadMetric,
MetricsConfiguration, RemoveBackend, ResponseStatus,
TcpListenerConfig as CommandTcpListener, CertificatesWithFingerprints,
},
ready::Ready,
request::WorkerRequest,
Expand Down Expand Up @@ -926,9 +925,9 @@ impl Server {
let response = if certs.len() >= 1 {
WorkerResponse::ok_with_content(
message.id.clone(),
ContentType::CertificatesMatchingAFingerprint(
CertificatesMatchingAFingerprint { certs },
)
ContentType::CertificatesWithFingerprints(CertificatesWithFingerprints {
certs,
})
.into(),
)
} else {
Expand Down

0 comments on commit 4776d5f

Please sign in to comment.