-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move validated Hostname type from secret-operator (#851)
* Refactor validation module to use typed errors * Remove separate regex_str parameter * Upstream Hostname from secret-operator * Add kerberos realm name type This used to use Hostname, but secret-op's Hostname had looser validation constraints * fmt * Changelog * Remove module name from error types * Update crates/stackable-operator/CHANGELOG.md Co-authored-by: Techassi <[email protected]> * Update crates/stackable-operator/src/commons/networking.rs Co-authored-by: Techassi <[email protected]> * Update crates/stackable-operator/src/commons/networking.rs Co-authored-by: Techassi <[email protected]> * Update crates/stackable-operator/src/validation.rs Co-authored-by: Techassi <[email protected]> * Update crates/stackable-operator/src/validation.rs Co-authored-by: Techassi <[email protected]> --------- Co-authored-by: Techassi <[email protected]>
- Loading branch information
Showing
5 changed files
with
284 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::{fmt::Display, ops::Deref}; | ||
|
||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::validation; | ||
|
||
/// A validated hostname type, for use in CRDs. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
#[serde(try_from = "String", into = "String")] | ||
pub struct Hostname(#[validate(regex(path = "validation::RFC_1123_SUBDOMAIN_REGEX"))] String); | ||
|
||
impl TryFrom<String> for Hostname { | ||
type Error = validation::Errors; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
validation::is_rfc_1123_subdomain(&value)?; | ||
Ok(Hostname(value)) | ||
} | ||
} | ||
|
||
impl From<Hostname> for String { | ||
fn from(value: Hostname) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl Display for Hostname { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(&self.0) | ||
} | ||
} | ||
|
||
impl Deref for Hostname { | ||
type Target = str; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
/// A validated kerberos realm name type, for use in CRDs. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
#[serde(try_from = "String", into = "String")] | ||
pub struct KerberosRealmName( | ||
#[validate(regex(path = "validation::KERBEROS_REALM_NAME_REGEX"))] String, | ||
); | ||
|
||
impl TryFrom<String> for KerberosRealmName { | ||
type Error = validation::Errors; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
validation::is_kerberos_realm_name(&value)?; | ||
Ok(KerberosRealmName(value)) | ||
} | ||
} | ||
|
||
impl From<KerberosRealmName> for String { | ||
fn from(value: KerberosRealmName) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl Display for KerberosRealmName { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(&self.0) | ||
} | ||
} | ||
|
||
impl Deref for KerberosRealmName { | ||
type Target = str; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
Oops, something went wrong.