couchbase_core/mgmtx/
user.rs1use chrono::{DateTime, FixedOffset};
20use std::fmt::Display;
21
22#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
23pub struct Role {
24 pub name: String,
25 pub bucket: Option<String>,
26 pub scope: Option<String>,
27 pub collection: Option<String>,
28}
29
30impl Role {
31 pub fn new(name: impl Into<String>) -> Self {
32 Self {
33 name: name.into(),
34 bucket: None,
35 scope: None,
36 collection: None,
37 }
38 }
39
40 pub fn bucket(mut self, bucket: impl Into<String>) -> Self {
41 self.bucket = Some(bucket.into());
42 self
43 }
44
45 pub fn scope(mut self, scope: impl Into<String>) -> Self {
46 self.scope = Some(scope.into());
47 self
48 }
49
50 pub fn collection(mut self, collection: impl Into<String>) -> Self {
51 self.collection = Some(collection.into());
52 self
53 }
54}
55
56#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
57pub struct RoleAndDescription {
58 pub role: Role,
59 pub display_name: String,
60 pub description: String,
61}
62
63#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
64pub struct Origin {
65 pub origin_type: String,
66 pub name: Option<String>,
67}
68
69#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
70pub struct RoleAndOrigins {
71 pub role: Role,
72 pub origins: Vec<Origin>,
73}
74
75#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
76pub struct Group {
77 pub name: String,
78 pub description: Option<String>,
79 pub roles: Vec<Role>,
80 pub ldap_group_reference: Option<String>,
81}
82
83impl Group {
84 pub fn new(name: impl Into<String>, description: impl Into<String>, roles: Vec<Role>) -> Self {
85 Self {
86 name: name.into(),
87 description: Some(description.into()),
88 roles,
89 ldap_group_reference: None,
90 }
91 }
92
93 pub fn ldap_group_reference(mut self, reference: impl Into<String>) -> Self {
94 self.ldap_group_reference = Some(reference.into());
95 self
96 }
97}
98
99#[derive(Debug, Clone, PartialOrd, Eq, PartialEq)]
100pub struct User {
101 pub username: String,
102 pub display_name: String,
103 pub groups: Vec<String>,
104 pub roles: Vec<Role>,
105
106 pub password: Option<String>,
107}
108
109impl User {
110 pub fn new(
111 username: impl Into<String>,
112 display_name: impl Into<String>,
113 roles: Vec<Role>,
114 ) -> Self {
115 Self {
116 username: username.into(),
117 display_name: display_name.into(),
118 groups: Vec::new(),
119 roles,
120 password: None,
121 }
122 }
123
124 pub fn groups(mut self, groups: Vec<String>) -> Self {
125 self.groups = groups;
126 self
127 }
128
129 pub fn password(mut self, password: impl Into<String>) -> Self {
130 self.password = Some(password.into());
131 self
132 }
133}
134
135#[derive(Debug, Clone, PartialOrd, PartialEq)]
136pub struct UserAndMetadata {
137 pub domain: String,
138 pub user: User,
139 pub effective_roles: Vec<RoleAndOrigins>,
140 pub password_changed: Option<DateTime<FixedOffset>>,
141 pub external_groups: Vec<String>,
142}