sylvia_iot_corelib/role.rs
1use std::collections::HashMap;
2
3/// Role definitions in sylvia-iot platform.
4pub struct Role;
5
6impl Role {
7 /// The system administrator who has all privileges.
8 pub const ADMIN: &'static str = "admin";
9 /// The developer who can create clients.
10 pub const DEV: &'static str = "dev";
11 /// The system manager who has much of priviledges than normal user.
12 pub const MANAGER: &'static str = "manager";
13 /// The service (process, program, client).
14 pub const SERVICE: &'static str = "service";
15
16 /// To check if a user who has `role_map` with the specific `role_name`.
17 pub fn is_role(role_map: &HashMap<String, bool>, role_name: &'static str) -> bool {
18 match role_map.get(role_name) {
19 None => false,
20 Some(map) => *map,
21 }
22 }
23}