Skip to content

Commit

Permalink
write AddCertificate in protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 4, 2023
1 parent 36f01dc commit 00f82cf
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 37 deletions.
6 changes: 4 additions & 2 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use sozu_command_lib::{
certificate::{calculate_fingerprint, split_certificate_chain, Fingerprint},
channel::Channel,
config::Config,
proto::command::{CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition, TlsVersion},
request::{AddBackend, AddCertificate, RemoveBackend, ReplaceCertificate, Request},
proto::command::{
AddCertificate, CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition, TlsVersion,
},
request::{AddBackend, RemoveBackend, ReplaceCertificate, Request},
response::{Response, ResponseStatus},
};

Expand Down
5 changes: 3 additions & 2 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use sozu_command_lib::{
certificate::{calculate_fingerprint, split_certificate_chain, Fingerprint},
config::{Config, ListenerBuilder, ProxyProtocolConfig},
proto::command::{
CertificateAndKey, FrontendFilters, PathRule, RequestHttpFrontend, RulePosition, TlsVersion,
AddCertificate, CertificateAndKey, FrontendFilters, PathRule, RequestHttpFrontend,
RulePosition, TlsVersion,
},
request::{
ActivateListener, AddBackend, AddCertificate, Cluster, DeactivateListener, ListenerType,
ActivateListener, AddBackend, Cluster, DeactivateListener, ListenerType,
LoadBalancingParams, MetricsConfiguration, RemoveBackend, RemoveCertificate,
RemoveListener, ReplaceCertificate, Request, RequestTcpFrontend,
},
Expand Down
4 changes: 3 additions & 1 deletion command/assets/add_certificate.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
4,
5
]
}
},
"names": [],
"expired_at": null
}
}
8 changes: 8 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ enum RulePosition {
TREE = 2;
}

message AddCertificate {
required string address = 1;
required CertificateAndKey certificate = 2;
repeated string names = 3;
// A unix timestamp. Overrides certificate expiration.
optional int64 expired_at = 4;
}

message CertificateAndKey {
required string certificate = 1;
repeated string certificate_chain = 2;
Expand Down
9 changes: 5 additions & 4 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ use toml;

use crate::{
certificate::split_certificate_chain,
proto::command::{CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition, TlsVersion},
proto::command::{
AddCertificate, CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition, TlsVersion,
},
request::{
ActivateListener, AddBackend, AddCertificate, Cluster, ListenerType,
LoadBalancingAlgorithms, LoadBalancingParams, LoadMetric, Request, RequestTcpFrontend,
WorkerRequest,
ActivateListener, AddBackend, Cluster, ListenerType, LoadBalancingAlgorithms,
LoadBalancingParams, LoadMetric, Request, RequestTcpFrontend, WorkerRequest,
},
response::{HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig},
};
Expand Down
15 changes: 2 additions & 13 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
certificate::Fingerprint,
config::ProxyProtocolConfig,
proto::command::{
CertificateAndKey, FrontendFilters, PathRuleKind, RequestHttpFrontend, RulePosition,
AddCertificate, CertificateAndKey, FrontendFilters, PathRuleKind, RequestHttpFrontend,
RulePosition,
},
response::{
HttpFrontend, HttpListenerConfig, HttpsListenerConfig, MessageId, TcpListenerConfig,
Expand Down Expand Up @@ -275,18 +276,6 @@ pub struct DeactivateListener {
pub to_scm: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct AddCertificate {
pub address: String,
pub certificate: CertificateAndKey,
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub names: Vec<String>,
/// The `expired_at` override certificate expiration, the value of the field
/// is a unix timestamp
#[serde(skip_serializing_if = "Option::is_none")]
pub expired_at: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RemoveCertificate {
pub address: String,
Expand Down
7 changes: 3 additions & 4 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ use anyhow::{bail, Context};

use crate::{
certificate::{calculate_fingerprint, Fingerprint},
proto::command::{CertificateAndKey, PathRule, PathRuleKind, RequestHttpFrontend},
proto::command::{AddCertificate, CertificateAndKey, PathRule, RequestHttpFrontend},
request::{
ActivateListener, AddBackend, AddCertificate, Cluster, DeactivateListener, ListenerType,
RemoveBackend, RemoveCertificate, RemoveListener, ReplaceCertificate, Request,
RequestTcpFrontend,
ActivateListener, AddBackend, Cluster, DeactivateListener, ListenerType, RemoveBackend,
RemoveCertificate, RemoveListener, ReplaceCertificate, Request, RequestTcpFrontend,
},
response::{
Backend, ClusterInformation, HttpFrontend, HttpListenerConfig, HttpsListenerConfig,
Expand Down
4 changes: 2 additions & 2 deletions e2e/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use sozu_command_lib::{
config::{FileConfig, ListenerBuilder},
info,
logging::{Logger, LoggerBackend},
proto::command::{CertificateAndKey, RequestHttpFrontend},
request::{ActivateListener, AddCertificate, ListenerType, RemoveBackend, Request},
proto::command::{AddCertificate, CertificateAndKey, RequestHttpFrontend},
request::{ActivateListener, ListenerType, RemoveBackend, Request},
state::ConfigState,
};

Expand Down
6 changes: 4 additions & 2 deletions lib/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ use sozu_command::config::ListenerBuilder;
use sozu_command::{
channel::Channel,
logging::{Logger, LoggerBackend},
proto::command::{CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition},
request::{AddBackend, AddCertificate, LoadBalancingParams, Request, WorkerRequest},
proto::command::{
AddCertificate, CertificateAndKey, PathRule, RequestHttpFrontend, RulePosition,
},
request::{AddBackend, LoadBalancingParams, Request, WorkerRequest},
};

fn main() -> anyhow::Result<()> {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ use sozu_command::{
certificate::Fingerprint,
config::DEFAULT_CIPHER_SUITES,
logging,
proto::command::{CertificateSummary, RequestHttpFrontend, TlsVersion},
proto::command::{AddCertificate, CertificateSummary, RequestHttpFrontend, TlsVersion},
ready::Ready,
request::{
AddCertificate, Cluster, RemoveCertificate, RemoveListener, ReplaceCertificate, Request,
WorkerRequest,
Cluster, RemoveCertificate, RemoveListener, ReplaceCertificate, Request, WorkerRequest,
},
response::{HttpFrontend, HttpsListenerConfig, ResponseContent, WorkerResponse},
scm_socket::ScmSocket,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use x509_parser::{
use crate::router::trie::*;
use sozu_command::{
certificate::Fingerprint,
proto::command::{CertificateAndKey, TlsVersion},
request::{AddCertificate, RemoveCertificate, ReplaceCertificate},
proto::command::{AddCertificate, CertificateAndKey, TlsVersion},
request::{RemoveCertificate, ReplaceCertificate},
};

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -652,10 +652,10 @@ mod tests {
GenericCertificateResolverError,
};

use crate::sozu_command::request::{AddCertificate, RemoveCertificate};
use crate::sozu_command::request::RemoveCertificate;

use rand::{seq::SliceRandom, thread_rng};
use sozu_command::proto::command::CertificateAndKey;
use sozu_command::proto::command::{AddCertificate, CertificateAndKey};
use x509_parser::pem::parse_x509_pem;

#[test]
Expand Down

0 comments on commit 00f82cf

Please sign in to comment.