nethsm::user

Enum UserId

source
pub enum UserId {
    SystemWide(String),
    Namespace(NamespaceId, String),
}
Expand description

The ID for a NetHsm user

UserIds are an essential part of the user management for a NetHSM. They come in two types: system-wide and in a namespace.

UserIds for system-wide users only consist of characters in the set [a-z0-9] (e.g. user1) and must be at least one char long.

The UserIds of users in a namespace consist of characters in the set [a-z0-9~] and contain the name of the namespace (see NamespaceId) they are in. These UserIds must be at least three chars long. The ~ character serves as delimiter between the namespace part and the user part (e.g. namespace1~user1).

Variants§

§

SystemWide(String)

A system-wide user

§

Namespace(NamespaceId, String)

A user in a namespace

Implementations§

source§

impl UserId

source

pub fn new(user_id: String) -> Result<Self, Error>

Creates a new UserId from owned String

The provided string must be in the character set [a-z0-9~] and at least one char long. The ~ character can not be used as the first character and can only occur once.

§Errors

Returns an Error if

  • the provided string contains an invalid character
  • the ~ character is used as the first character
  • the ~ character is used more than once
§Examples
use nethsm::UserId;

// the UserId of a system-wide user
assert!(UserId::new("user1".to_string()).is_ok());
// the UserId of a namespace user
assert!(UserId::new("namespace1~user1".to_string()).is_ok());

// the input can not contain invalid chars
assert!(UserId::new("user1X".to_string()).is_err());
assert!(UserId::new("user;-".to_string()).is_err());

// the '~' character must be surrounded by other characters and only occur once
assert!(UserId::new("~user1".to_string()).is_err());
assert!(UserId::new("namespace~user~else".to_string()).is_err());
source

pub fn namespace(&self) -> Option<String>

Returns the namespace of the UserId

§Examples
use nethsm::UserId;

// the UserId of a system-wide user
assert_eq!(UserId::new("user1".to_string())?.namespace(), None);
// the UserId of a namespace user
assert_eq!(
    UserId::new("namespace1~user1".to_string())?.namespace(),
    Some("namespace1".to_string())
);
source

pub fn is_namespaced(&self) -> bool

Returns whether the UserId contains a namespace

§Examples
use nethsm::UserId;

// the UserId of a system-wide user
assert_eq!(UserId::new("user1".to_string())?.is_namespaced(), false);
// the UserId of a namespace user
assert_eq!(
    UserId::new("namespace1~user1".to_string())?.is_namespaced(),
    true
);
source

pub fn validate_namespace_access( &self, support: NamespaceSupport, target: Option<&UserId>, role: Option<&UserRole>, ) -> Result<(), Error>

Validates whether the UserId can be used in a given context

Ensures that UserId can be used in its context (e.g. calls to system-wide or namespace resources) by defining namespace support of the context. Additionally ensures the validity of calls to resources targeting other users (provided by target), which are themselves system-wide or in a namespace. When role is provided, the validity of targeting the UserRole is evaluated.

§Errors

This call returns an

Trait Implementations§

source§

impl Clone for UserId

source§

fn clone(&self) -> UserId

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UserId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for UserId

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for UserId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<UserId> for String

source§

fn from(value: UserId) -> Self

Converts to this type from the input type.
source§

impl FromStr for UserId

source§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for UserId

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for UserId

source§

fn eq(&self, other: &UserId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for UserId

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&String> for UserId

source§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: &String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&str> for UserId

source§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for UserId

source§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for UserId

source§

impl StructuralPartialEq for UserId

Auto Trait Implementations§

§

impl Freeze for UserId

§

impl RefUnwindSafe for UserId

§

impl Send for UserId

§

impl Sync for UserId

§

impl Unpin for UserId

§

impl UnwindSafe for UserId

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T