track which namespaces we control

This commit is contained in:
Robin Appelman 2025-11-01 16:42:34 +01:00
commit 32fc90debe
5 changed files with 59 additions and 14 deletions

View file

@ -1,11 +1,25 @@
use serde::de::{Error, Unexpected, Visitor};
use serde::{Deserialize, Deserializer};
use std::ffi::OsString;
use std::fmt::{Display, Formatter};
use std::path::Path;
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct NamespaceName(String);
impl TryFrom<OsString> for NamespaceName {
type Error = ();
fn try_from(value: OsString) -> Result<Self, Self::Error> {
let str = value.into_string().map_err(|_| ())?;
if validate_name(&str) {
Ok(NamespaceName(str))
} else {
Err(())
}
}
}
impl Display for NamespaceName {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
@ -80,7 +94,7 @@ fn validate_name(name: &str) -> bool {
#[test]
fn test_de() {
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};
assert_de_tokens(&NamespaceName("foo".into()), &[Token::String("foo")]);