Skip to content

Commit 9f460da

Browse files
committed
Upstream Hostname from secret-operator
1 parent 3dcf7fd commit 9f460da

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

crates/stackable-operator/src/commons/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ pub mod resources;
1212
pub mod s3;
1313
pub mod secret;
1414
pub mod secret_class;
15+
pub mod networking;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::{fmt::Display, ops::Deref};
2+
3+
use schemars::JsonSchema;
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::validation::{self, ValidationErrors};
7+
8+
/// A validated hostname type, for use in CRDs.
9+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10+
#[serde(try_from = "String", into = "String")]
11+
pub struct Hostname(#[validate(regex(path = "validation::RFC_1123_SUBDOMAIN_REGEX"))] String);
12+
13+
impl TryFrom<String> for Hostname {
14+
type Error = ValidationErrors;
15+
16+
fn try_from(value: String) -> Result<Self, Self::Error> {
17+
validation::is_rfc_1123_subdomain(&value)?;
18+
Ok(Hostname(value))
19+
}
20+
}
21+
impl From<Hostname> for String {
22+
fn from(value: Hostname) -> Self {
23+
value.0
24+
}
25+
}
26+
impl Display for Hostname {
27+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
f.write_str(&self.0)
29+
}
30+
}
31+
impl Deref for Hostname {
32+
type Target = str;
33+
34+
fn deref(&self) -> &Self::Target {
35+
&self.0
36+
}
37+
}

crates/stackable-operator/src/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const RFC_1035_LABEL_ERROR_MSG: &str = "a DNS-1035 label must consist of lower c
3333
const RFC_1035_LABEL_MAX_LENGTH: usize = 63;
3434

3535
// Lazily initialized regular expressions
36-
static RFC_1123_SUBDOMAIN_REGEX: LazyLock<Regex> = LazyLock::new(|| {
36+
pub(crate) static RFC_1123_SUBDOMAIN_REGEX: LazyLock<Regex> = LazyLock::new(|| {
3737
Regex::new(&format!("^{RFC_1123_SUBDOMAIN_FMT}$"))
3838
.expect("failed to compile RFC 1123 subdomain regex")
3939
});

0 commit comments

Comments
 (0)