Skip to content

Commit 8b83131

Browse files
committed
Add ConversionWebhookOptions struct
1 parent 29b0c6c commit 8b83131

File tree

7 files changed

+144
-118
lines changed

7 files changed

+144
-118
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-webhook/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ hyper.workspace = true
1919
k8s-openapi.workspace = true
2020
kube.workspace = true
2121
opentelemetry.workspace = true
22+
opentelemetry-semantic-conventions.workspace = true
2223
rand.workspace = true
2324
serde_json.workspace = true
2425
snafu.workspace = true

crates/stackable-webhook/src/lib.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
//! routes and their handler functions.
99
//!
1010
//! ```
11-
//! use stackable_webhook::{WebhookServer, Options};
11+
//! use stackable_webhook::{WebhookServer, WebhookOptions};
1212
//! use axum::Router;
1313
//!
1414
//! # async fn test() {
1515
//! let router = Router::new();
16-
//! let (server, cert_rx) = WebhookServer::new(router, Options::default())
16+
//! let (server, cert_rx) = WebhookServer::new(router, WebhookOptions::default())
1717
//! .await
1818
//! .expect("failed to create WebhookServer");
1919
//! # }
@@ -46,7 +46,7 @@ pub mod servers;
4646
pub mod tls;
4747

4848
// Selected re-exports
49-
pub use crate::options::Options;
49+
pub use crate::options::WebhookOptions;
5050

5151
/// A generic webhook handler receiving a request and sending back a response.
5252
///
@@ -88,23 +88,23 @@ pub struct WebhookServer {
8888
impl WebhookServer {
8989
/// Creates a new ready-to-use webhook server.
9090
///
91-
/// The server listens on `socket_addr` which is provided via the [`Options`]
92-
/// and handles routing based on the provided Axum `router`. Most of the time
93-
/// it is sufficient to use [`Options::default()`]. See the documentation
94-
/// for [`Options`] for more details on the default values.
91+
/// The server listens on `socket_addr` which is provided via the [`WebhookOptions`] and handles
92+
/// routing based on the provided Axum `router`. Most of the time it is sufficient to use
93+
/// [`WebhookOptions::default()`]. See the documentation for [`WebhookOptions`] for more details
94+
/// on the default values.
9595
///
9696
/// To start the server, use the [`WebhookServer::run()`] function. This will
9797
/// run the server using the Tokio runtime until it is terminated.
9898
///
9999
/// ### Basic Example
100100
///
101101
/// ```
102-
/// use stackable_webhook::{WebhookServer, Options};
102+
/// use stackable_webhook::{WebhookServer, WebhookOptions};
103103
/// use axum::Router;
104104
///
105105
/// # async fn test() {
106106
/// let router = Router::new();
107-
/// let (server, cert_rx) = WebhookServer::new(router, Options::default())
107+
/// let (server, cert_rx) = WebhookServer::new(router, WebhookOptions::default())
108108
/// .await
109109
/// .expect("failed to create WebhookServer");
110110
/// # }
@@ -113,11 +113,11 @@ impl WebhookServer {
113113
/// ### Example with Custom Options
114114
///
115115
/// ```
116-
/// use stackable_webhook::{WebhookServer, Options};
116+
/// use stackable_webhook::{WebhookServer, WebhookOptions};
117117
/// use axum::Router;
118118
///
119119
/// # async fn test() {
120-
/// let options = Options::builder()
120+
/// let options = WebhookOptions::builder()
121121
/// .bind_address([127, 0, 0, 1], 8080)
122122
/// .add_subject_alterative_dns_name("my-san-entry")
123123
/// .build();
@@ -130,7 +130,7 @@ impl WebhookServer {
130130
/// ```
131131
pub async fn new(
132132
router: Router,
133-
options: Options,
133+
options: WebhookOptions,
134134
) -> Result<(Self, mpsc::Receiver<Certificate>)> {
135135
tracing::trace!("create new webhook server");
136136

@@ -154,13 +154,9 @@ impl WebhookServer {
154154
.route("/health", get(|| async { "ok" }));
155155

156156
tracing::debug!("create TLS server");
157-
let (tls_server, cert_rx) = TlsServer::new(
158-
options.socket_addr,
159-
router,
160-
options.subject_alterative_dns_names,
161-
)
162-
.await
163-
.context(CreateTlsServerSnafu)?;
157+
let (tls_server, cert_rx) = TlsServer::new(router, options)
158+
.await
159+
.context(CreateTlsServerSnafu)?;
164160

165161
Ok((Self { tls_server }, cert_rx))
166162
}

crates/stackable-webhook/src/options.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,33 @@ use crate::constants::DEFAULT_SOCKET_ADDRESS;
1010

1111
/// Specifies available webhook server options.
1212
///
13-
/// The [`Default`] implemention for this struct contains the following
14-
/// values:
13+
/// The [`Default`] implementation for this struct contains the following values:
1514
///
1615
/// - The socket binds to 127.0.0.1 on port 8443 (HTTPS)
17-
/// - The TLS cert used gets auto-generated
16+
/// - An empty list of SANs is provided to the certificate the TLS server uses.
1817
///
1918
/// ### Example with Custom HTTPS IP Address and Port
2019
///
2120
/// ```
22-
/// use stackable_webhook::Options;
21+
/// use stackable_webhook::WebhookOptions;
2322
///
2423
/// // Set IP address and port at the same time
25-
/// let options = Options::builder()
24+
/// let options = WebhookOptions::builder()
2625
/// .bind_address([0, 0, 0, 0], 12345)
2726
/// .build();
2827
///
2928
/// // Set IP address only
30-
/// let options = Options::builder()
29+
/// let options = WebhookOptions::builder()
3130
/// .bind_ip([0, 0, 0, 0])
3231
/// .build();
3332
///
3433
/// // Set port only
35-
/// let options = Options::builder()
34+
/// let options = WebhookOptions::builder()
3635
/// .bind_port(12345)
3736
/// .build();
3837
/// ```
3938
#[derive(Debug)]
40-
pub struct Options {
39+
pub struct WebhookOptions {
4140
/// The default HTTPS socket address the [`TcpListener`][tokio::net::TcpListener]
4241
/// binds to.
4342
pub socket_addr: SocketAddr,
@@ -47,15 +46,15 @@ pub struct Options {
4746
pub subject_alterative_dns_names: Vec<String>,
4847
}
4948

50-
impl Default for Options {
49+
impl Default for WebhookOptions {
5150
fn default() -> Self {
5251
Self::builder().build()
5352
}
5453
}
5554

56-
impl Options {
55+
impl WebhookOptions {
5756
/// Returns the default [`OptionsBuilder`] which allows to selectively
58-
/// customize the options. See the documention for [`Options`] for more
57+
/// customize the options. See the documentation for [`Options`] for more
5958
/// information on available functions.
6059
pub fn builder() -> OptionsBuilder {
6160
OptionsBuilder::default()
@@ -106,7 +105,7 @@ impl OptionsBuilder {
106105
self
107106
}
108107

109-
/// Adds the (subject alterative DNS name to the list of names.
108+
/// Adds the subject alterative DNS name to the list of names.
110109
pub fn add_subject_alterative_dns_name(
111110
mut self,
112111
subject_alterative_dns_name: impl Into<String>,
@@ -118,8 +117,8 @@ impl OptionsBuilder {
118117

119118
/// Builds the final [`Options`] by using default values for any not
120119
/// explicitly set option.
121-
pub fn build(self) -> Options {
122-
Options {
120+
pub fn build(self) -> WebhookOptions {
121+
WebhookOptions {
123122
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDRESS),
124123
subject_alterative_dns_names: self.subject_alterative_dns_names,
125124
}

0 commit comments

Comments
 (0)