-
-
Notifications
You must be signed in to change notification settings - Fork 15
Move validated Hostname type from secret-operator #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d1016d
Refactor validation module to use typed errors
nightkr 3dcf7fd
Remove separate regex_str parameter
nightkr 9f460da
Upstream Hostname from secret-operator
nightkr f09a790
Add kerberos realm name type
nightkr c8fd2ef
fmt
nightkr 8ea2a2e
Changelog
nightkr b5c129f
Remove module name from error types
nightkr 41fd8eb
Update crates/stackable-operator/CHANGELOG.md
nightkr b0207a3
Update crates/stackable-operator/src/commons/networking.rs
nightkr 1874aca
Update crates/stackable-operator/src/commons/networking.rs
nightkr f76649d
Update crates/stackable-operator/src/validation.rs
nightkr 4cffca4
Update crates/stackable-operator/src/validation.rs
nightkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
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 | ||
} | ||
} | ||
nightkr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// 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 | ||
} | ||
} | ||
nightkr marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.