MappingSystemUserId

Trait MappingSystemUserId 

Source
pub trait MappingSystemUserId {
    // Required method
    fn system_user_id(&self) -> Option<&SystemUserId>;

    // Provided methods
    fn system_user_id_as_existing_unix_user(
        &self,
    ) -> Result<Option<User>, Error> { ... }
    fn system_user_id_as_current_unix_user(&self) -> Result<Option<User>, Error> { ... }
}
Expand description

An interface for returning an optional SystemUserId or a [User].

It is implemented by mapping implementations, that track system user data.

§Example

use signstar_config::{SystemUserId, config::MappingSystemUserId};
use signstar_crypto::{passphrase::Passphrase, traits::UserWithPassphrase};

#[derive(Debug)]
enum ExampleUserMapping {
    Admin {
        backend_id: u8,
    },
    Backup {
        backend_id: u8,
        system_user: SystemUserId,
    },
    Metrics {
        backend_id: u8,
        system_user: SystemUserId,
    },
    Signer {
        backend_id: u8,
        system_user: SystemUserId,
    },
}

impl ExampleUserMapping {
    pub fn backend_user_id(&self) -> u8 {
        match self {
            Self::Admin { backend_id }
            | Self::Backup { backend_id, .. }
            | Self::Metrics { backend_id, .. }
            | Self::Signer { backend_id, .. } => *backend_id,
        }
    }
}

impl MappingSystemUserId for ExampleUserMapping {
    fn system_user_id(&self) -> Option<&SystemUserId> {
        match self {
            Self::Admin { .. } => None,
            Self::Backup { system_user, .. }
            | Self::Metrics { system_user, .. }
            | Self::Signer { system_user, .. } => Some(system_user),
        }
    }
}

Required Methods§

Source

fn system_user_id(&self) -> Option<&SystemUserId>

Returns a reference to the SystemUserId.

§Note

Should return None, if the user mapping implementation does not track a system user.

Provided Methods§

Source

fn system_user_id_as_existing_unix_user(&self) -> Result<Option<User>, Error>

Returns the tracked system user ID as [User] if it exists.

This is a default implementation and should require no specific implementation.

§Note

Returns Ok(None), if MappingSystemUserId::system_user_id returns None (the user mapping implementation tracks no system user).

§Errors

Returns an error if no Unix user of the mapping’s system user name exists.

Source

fn system_user_id_as_current_unix_user(&self) -> Result<Option<User>, Error>

Returns the tracked system user ID as the current [User] if it exists.

This is a default implementation and should require no specific implementation.

§Note

Returns Ok(None), if MappingSystemUserId::system_user_id returns None (the user mapping implementation tracks no system user).

§Errors

Returns an error if

Implementors§