pub trait ConfigSystemUserIds {
// Required method
fn system_user_ids(&self) -> HashSet<&SystemUserId>;
}Expand description
An interface for returning all SystemUserIds tracked by a configuration implementation.
§Example
use std::collections::HashSet;
use signstar_config::{
SystemUserId,
config::{ConfigSystemUserIds, MappingSystemUserId},
};
use signstar_crypto::{passphrase::Passphrase, traits::UserWithPassphrase};
#[derive(Debug, Eq, Hash, PartialEq)]
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),
}
}
}
#[derive(Debug)]
struct Config {
pub mappings: HashSet<ExampleUserMapping>,
}
impl ConfigSystemUserIds for Config {
fn system_user_ids(&self) -> HashSet<&SystemUserId> {
self.mappings
.iter()
.filter_map(|mapping| mapping.system_user_id())
.collect::<HashSet<_>>()
}
}
let config = Config {
mappings: HashSet::from_iter([
ExampleUserMapping::Admin { backend_id: 1 },
ExampleUserMapping::Backup {
backend_id: 2,
system_user: "backup".parse()?,
},
ExampleUserMapping::Metrics {
backend_id: 3,
system_user: "metrics".parse()?,
},
ExampleUserMapping::Signer {
backend_id: 3,
system_user: "signer".parse()?,
},
]),
};
let system_users: HashSet<SystemUserId> =
HashSet::from_iter(["backup".parse()?, "metrics".parse()?, "signer".parse()?]);
assert_eq!(
config.system_user_ids(),
system_users.iter().collect::<HashSet<_>>()
);Required Methods§
Sourcefn system_user_ids(&self) -> HashSet<&SystemUserId>
fn system_user_ids(&self) -> HashSet<&SystemUserId>
Returns the list of all SystemUserIds.