Skip to content

Commit 90f9271

Browse files
committed
Rename Host -> HostName
1 parent acb84d8 commit 90f9271

File tree

5 files changed

+57
-55
lines changed

5 files changed

+57
-55
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9-
- BREAKING: Add `Host` type and use it within LDAP and OIDC AuthenticationClass as well as S3Connection ([#863]).
9+
- BREAKING: Add `HostName` type and use it within LDAP and OIDC AuthenticationClass as well as S3Connection ([#863]).
1010

1111
### Changed
1212

1313
- BREAKING: TLS verification struct now reside in the `commons::tls_verification` module, instead of being placed below `commons::authentication::tls` ([#863]).
14+
- BREAKING: Rename the `Hostname` type to `DomainName` to be consistent with RFC 1123 ([#863]).
1415

1516
### Fixed
1617

crates/stackable-operator/src/commons/authentication/ldap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
builder::pod::{container::ContainerBuilder, volume::VolumeMountBuilder, PodBuilder},
99
commons::{
1010
authentication::SECRET_BASE_PATH,
11-
networking::Host,
11+
networking::HostName,
1212
secret_class::{SecretClassVolume, SecretClassVolumeError},
1313
tls_verification::{TlsClientDetails, TlsClientDetailsError},
1414
},
@@ -36,7 +36,7 @@ pub enum Error {
3636
#[serde(rename_all = "camelCase")]
3737
pub struct AuthenticationProvider {
3838
/// Host of the LDAP server, for example: `my.ldap.server` or `127.0.0.1`.
39-
pub hostname: Host,
39+
pub hostname: HostName,
4040

4141
/// Port of the LDAP server. If TLS is used defaults to 636 otherwise to 389.
4242
port: Option<u16>,

crates/stackable-operator/src/commons/authentication/oidc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use url::{ParseError, Url};
1212
#[cfg(doc)]
1313
use crate::commons::authentication::AuthenticationClass;
1414
use crate::commons::{
15-
authentication::SECRET_BASE_PATH, networking::Host, tls_verification::TlsClientDetails,
15+
authentication::SECRET_BASE_PATH, networking::HostName, tls_verification::TlsClientDetails,
1616
};
1717

1818
pub type Result<T, E = Error> = std::result::Result<T, E>;
@@ -43,7 +43,7 @@ pub enum Error {
4343
#[serde(rename_all = "camelCase")]
4444
pub struct AuthenticationProvider {
4545
/// Host of the identity provider, e.g. `my.keycloak.corp` or `127.0.0.1`.
46-
hostname: Host,
46+
hostname: HostName,
4747

4848
/// Port of the identity provider. If TLS is used defaults to 443,
4949
/// otherwise to 80.
@@ -92,7 +92,7 @@ fn default_root_path() -> String {
9292

9393
impl AuthenticationProvider {
9494
pub fn new(
95-
hostname: Host,
95+
hostname: HostName,
9696
port: Option<u16>,
9797
root_path: String,
9898
tls: TlsClientDetails,

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

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,43 @@ use snafu::Snafu;
66

77
use crate::validation;
88

9-
/// A validated hostname type conforming to RFC 1123, e.g. not an IPv6 address.
9+
/// A validated domain name type conforming to RFC 1123, e.g. an IPv4, but not an IPv6 address.
1010
#[derive(
1111
Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, JsonSchema,
1212
)]
1313
#[serde(try_from = "String", into = "String")]
14-
pub struct Hostname(#[validate(regex(path = "validation::RFC_1123_SUBDOMAIN_REGEX"))] String);
14+
pub struct DomainName(#[validate(regex(path = "validation::RFC_1123_SUBDOMAIN_REGEX"))] String);
1515

16-
impl FromStr for Hostname {
16+
impl FromStr for DomainName {
1717
type Err = validation::Errors;
1818

1919
fn from_str(value: &str) -> Result<Self, Self::Err> {
2020
validation::is_rfc_1123_subdomain(value)?;
21-
Ok(Hostname(value.to_owned()))
21+
Ok(DomainName(value.to_owned()))
2222
}
2323
}
2424

25-
impl TryFrom<String> for Hostname {
25+
impl TryFrom<String> for DomainName {
2626
type Error = validation::Errors;
2727

2828
fn try_from(value: String) -> Result<Self, Self::Error> {
2929
value.parse()
3030
}
3131
}
3232

33-
impl From<Hostname> for String {
34-
fn from(value: Hostname) -> Self {
33+
impl From<DomainName> for String {
34+
fn from(value: DomainName) -> Self {
3535
value.0
3636
}
3737
}
3838

39-
impl Display for Hostname {
39+
impl Display for DomainName {
4040
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4141
f.write_str(&self.0)
4242
}
4343
}
4444

45-
impl Deref for Hostname {
45+
impl Deref for DomainName {
4646
type Target = str;
4747

4848
fn deref(&self) -> &Self::Target {
@@ -51,82 +51,82 @@ impl Deref for Hostname {
5151
}
5252

5353
#[derive(Debug, Snafu)]
54-
pub enum HostParseError {
54+
pub enum HostNameParseError {
5555
#[snafu(display(
56-
"the given host '{host}' is not a valid host, which needs to be either a hostname or IP address"
56+
"the given hostname '{hostname}' is not a valid hostname, which needs to be either a domain name or IP address"
5757
))]
58-
InvalidHost { host: String },
58+
InvalidHostname { hostname: String },
5959
}
6060

61-
/// A validated host (either a [`Hostname`] or IP address) type.
61+
/// A validated hostname (either a [`DomainName`] or IP address) type.
6262
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
6363
#[serde(try_from = "String", into = "String")]
64-
pub enum Host {
64+
pub enum HostName {
6565
IpAddress(IpAddr),
66-
Hostname(Hostname),
66+
DomainName(DomainName),
6767
}
6868

69-
impl JsonSchema for Host {
69+
impl JsonSchema for HostName {
7070
fn schema_name() -> String {
71-
"Host".to_owned()
71+
"HostName".to_owned()
7272
}
7373

7474
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
7575
String::json_schema(gen)
7676
}
7777
}
7878

79-
impl FromStr for Host {
80-
type Err = HostParseError;
79+
impl FromStr for HostName {
80+
type Err = HostNameParseError;
8181

8282
fn from_str(value: &str) -> Result<Self, Self::Err> {
8383
if let Ok(ip) = value.parse::<IpAddr>() {
84-
return Ok(Host::IpAddress(ip));
84+
return Ok(HostName::IpAddress(ip));
8585
}
8686

87-
if let Ok(hostname) = value.parse() {
88-
return Ok(Host::Hostname(hostname));
87+
if let Ok(domain_name) = value.parse() {
88+
return Ok(HostName::DomainName(domain_name));
8989
};
9090

91-
InvalidHostSnafu {
92-
host: value.to_owned(),
91+
InvalidHostnameSnafu {
92+
hostname: value.to_owned(),
9393
}
9494
.fail()
9595
}
9696
}
9797

98-
impl TryFrom<String> for Host {
99-
type Error = HostParseError;
98+
impl TryFrom<String> for HostName {
99+
type Error = HostNameParseError;
100100

101101
fn try_from(value: String) -> Result<Self, Self::Error> {
102102
value.parse()
103103
}
104104
}
105105

106-
impl From<Host> for String {
107-
fn from(value: Host) -> Self {
106+
impl From<HostName> for String {
107+
fn from(value: HostName) -> Self {
108108
value.to_string()
109109
}
110110
}
111111

112-
impl Display for Host {
112+
impl Display for HostName {
113113
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
114114
match self {
115-
Host::IpAddress(ip) => write!(f, "{ip}"),
116-
Host::Hostname(hostname) => write!(f, "{hostname}"),
115+
HostName::IpAddress(ip) => write!(f, "{ip}"),
116+
HostName::DomainName(domain_name) => write!(f, "{domain_name}"),
117117
}
118118
}
119119
}
120120

121-
impl Host {
121+
impl HostName {
122122
/// Formats the host in such a way that it can be used in URLs.
123123
pub fn as_url_host(&self) -> String {
124124
match self {
125-
Host::IpAddress(ip) => match ip {
125+
HostName::IpAddress(ip) => match ip {
126126
IpAddr::V4(ip) => ip.to_string(),
127127
IpAddr::V6(ip) => format!("[{ip}]"),
128128
},
129-
Host::Hostname(hostname) => hostname.to_string(),
129+
HostName::DomainName(domain_name) => domain_name.to_string(),
130130
}
131131
}
132132
}
@@ -176,37 +176,38 @@ mod tests {
176176
#[rstest]
177177
#[case("foo")]
178178
#[case("foo.bar")]
179-
// Well this is also a valid hostname I guess
179+
// This is also a valid domain name
180180
#[case("1.2.3.4")]
181-
fn test_host_and_hostname_parsing_success(#[case] hostname: String) {
182-
let parsed_hostname: Hostname = hostname.parse().expect("hostname can not be parsed");
183-
// Every hostname is also a valid host
184-
let parsed_host: Host = hostname.parse().expect("host can not be parsed");
181+
fn test_domain_name_and_host_name_parsing_success(#[case] domain_name: String) {
182+
let parsed_domain_name: DomainName =
183+
domain_name.parse().expect("domain name can not be parsed");
184+
// Every domain name is also a valid host name
185+
let parsed_host_name: HostName = domain_name.parse().expect("host name can not be parsed");
185186

186187
// Also test the round-trip
187-
assert_eq!(parsed_hostname.to_string(), hostname);
188-
assert_eq!(parsed_host.to_string(), hostname);
188+
assert_eq!(parsed_domain_name.to_string(), domain_name);
189+
assert_eq!(parsed_host_name.to_string(), domain_name);
189190
}
190191

191192
#[rstest]
192193
#[case("")]
193194
#[case("foo.bar:1234")]
194195
#[case("fe80::1")]
195-
fn test_hostname_parsing_invalid_input(#[case] hostname: &str) {
196-
assert!(hostname.parse::<Hostname>().is_err());
196+
fn test_domain_name_parsing_invalid_input(#[case] domain_name: &str) {
197+
assert!(domain_name.parse::<DomainName>().is_err());
197198
}
198199

199200
#[rstest]
200201
#[case("foo", "foo")]
201202
#[case("foo.bar", "foo.bar")]
202203
#[case("1.2.3.4", "1.2.3.4")]
203204
#[case("fe80::1", "[fe80::1]")]
204-
fn test_host_parsing_success(#[case] host: &str, #[case] expected_url_host: &str) {
205-
let parsed_host: Host = host.parse().expect("host can not be parsed");
205+
fn test_host_name_parsing_success(#[case] host: &str, #[case] expected_url_host: &str) {
206+
let parsed_host_name: HostName = host.parse().expect("host can not be parsed");
206207

207208
// Also test the round-trip
208-
assert_eq!(parsed_host.to_string(), host);
209+
assert_eq!(parsed_host_name.to_string(), host);
209210

210-
assert_eq!(parsed_host.as_url_host(), expected_url_host);
211+
assert_eq!(parsed_host_name.as_url_host(), expected_url_host);
211212
}
212213
}

crates/stackable-operator/src/commons/s3/crd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
44

55
use crate::commons::{
6-
networking::Host, secret_class::SecretClassVolume, tls_verification::TlsClientDetails,
6+
networking::HostName, secret_class::SecretClassVolume, tls_verification::TlsClientDetails,
77
};
88

99
use super::S3ConnectionInlineOrReference;
@@ -50,7 +50,7 @@ pub struct S3BucketSpec {
5050
#[serde(rename_all = "camelCase")]
5151
pub struct S3ConnectionSpec {
5252
/// Host of the S3 server without any protocol or port. For example: `west1.my-cloud.com`.
53-
pub host: Host,
53+
pub host: HostName,
5454

5555
/// Port the S3 server listens on.
5656
/// If not specified the product will determine the port to use.

0 commit comments

Comments
 (0)