@@ -77,52 +77,67 @@ pub enum Action {
77
77
PutCorrelation ,
78
78
}
79
79
80
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , serde:: Serialize , serde:: Deserialize ) ]
81
+ pub enum ParseableResourceType {
82
+ #[ serde( rename="stream" ) ]
83
+ Stream ( String ) ,
84
+ #[ serde( rename="llm" ) ]
85
+ Llm ( String ) ,
86
+ #[ serde( rename="all" ) ]
87
+ All
88
+ }
89
+
80
90
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
81
91
pub enum Permission {
82
92
Unit ( Action ) ,
83
- Stream ( Action , String ) ,
84
- StreamWithTag ( Action , String , Option < String > ) ,
85
- Resource ( Action , Option < String > , Option < String > ) ,
93
+ // Stream(Action, String),
94
+ // StreamWithTag(Action, String, Option<String>),
95
+ Resource ( Action , ParseableResourceType ) ,
86
96
SelfUser ,
87
97
}
88
98
89
99
// Currently Roles are tied to one stream
90
100
#[ derive( Debug , Default ) ]
91
101
pub struct RoleBuilder {
92
102
actions : Vec < Action > ,
93
- stream : Option < String > ,
94
- tag : Option < String > ,
95
- resource_id : Option < String > ,
96
- resource_type : Option < String > ,
103
+ // stream: Option<String>,
104
+ // tag: Option<String>,
105
+ // resource_id: Option<String>,
106
+ resource_type : Option < ParseableResourceType > ,
97
107
}
98
108
99
109
// R x P
100
110
impl RoleBuilder {
101
- pub fn with_stream ( mut self , stream : String ) -> Self {
102
- self . stream = Some ( stream) ;
111
+ pub fn with_resource (
112
+ mut self ,
113
+ resource_type : ParseableResourceType ,
114
+ // resource_id: String,
115
+ ) -> Self {
116
+ self . resource_type = Some ( resource_type) ;
117
+ // self.resource_id = Some(resource_id);
103
118
self
104
119
}
105
120
106
- pub fn with_tag ( mut self , tag : String ) -> Self {
107
- self . tag = Some ( tag ) ;
108
- self
109
- }
121
+ // pub fn with_stream (mut self, stream : String) -> Self {
122
+ // self.stream = Some(stream );
123
+ // self
124
+ // }
110
125
111
- pub fn with_resource ( mut self , resource_id : String , resource_type : String ) -> Self {
112
- self . resource_id = Some ( resource_id) ;
113
- self . resource_type = Some ( resource_type) ;
114
- self
115
- }
126
+ // pub fn with_tag(mut self, tag: String) -> Self {
127
+ // self.tag = Some(tag);
128
+ // self
129
+ // }
130
+
131
+ // pub fn with_resource(mut self, resource_id: String, resource_type: ParseableResourceType) -> Self {
132
+ // self.resource_id = Some(resource_id);
133
+ // self.resource_type = Some(resource_type);
134
+ // self
135
+ // }
116
136
117
137
pub fn build ( self ) -> Vec < Permission > {
118
138
let mut perms = Vec :: new ( ) ;
119
139
for action in self . actions {
120
140
let perm = match action {
121
- Action :: Query => Permission :: StreamWithTag (
122
- action,
123
- self . stream . clone ( ) . unwrap ( ) ,
124
- self . tag . clone ( ) ,
125
- ) ,
126
141
Action :: Login
127
142
| Action :: Metrics
128
143
| Action :: PutUser
@@ -164,23 +179,24 @@ impl RoleBuilder {
164
179
| Action :: DeleteUserGroup
165
180
| Action :: ModifyUserGroup
166
181
| Action :: GetAnalytics => Permission :: Unit ( action) ,
167
- Action :: QueryLLM
182
+ Action :: Query
183
+ | Action :: QueryLLM
168
184
| Action :: AddLLM
169
185
| Action :: DeleteLLM
170
186
| Action :: GetLLM
171
- | Action :: ListLLM => Permission :: Resource (
172
- action,
173
- self . resource_type . clone ( ) ,
174
- self . resource_id . clone ( ) ,
175
- ) ,
176
- Action :: Ingest
187
+ | Action :: ListLLM
188
+ | Action :: Ingest
177
189
| Action :: ListStream
178
190
| Action :: GetSchema
179
191
| Action :: DetectSchema
180
192
| Action :: GetStats
181
193
| Action :: GetRetention
182
194
| Action :: PutRetention
183
- | Action :: All => Permission :: Stream ( action, self . stream . clone ( ) . unwrap ( ) ) ,
195
+ | Action :: All => Permission :: Resource (
196
+ action,
197
+ self . resource_type . clone ( ) . unwrap ( ) ,
198
+ // self.resource_id.clone().unwrap(),
199
+ ) ,
184
200
} ;
185
201
perms. push ( perm) ;
186
202
}
@@ -193,26 +209,25 @@ impl RoleBuilder {
193
209
// we can put same model in the backend
194
210
// user -> Vec<DefaultRoles>
195
211
pub mod model {
212
+ use crate :: rbac:: role:: ParseableResourceType ;
213
+
196
214
use super :: { Action , RoleBuilder } ;
197
215
198
216
#[ derive( Debug , Clone , PartialEq , Eq , serde:: Serialize , serde:: Deserialize , Hash ) ]
199
- #[ serde( tag = "privilege" , content = "resource" , rename_all = "lowercase" ) ]
217
+ #[ serde( tag = "privilege" , rename_all = "lowercase" ) ]
200
218
pub enum DefaultPrivilege {
201
219
Admin ,
202
220
Editor ,
203
221
Writer {
204
- stream : String ,
222
+ resource : ParseableResourceType ,
223
+ // resource_id: String,
205
224
} ,
206
225
Ingestor {
207
- stream : String ,
226
+ resource : ParseableResourceType ,
208
227
} ,
209
228
Reader {
210
- stream : String ,
211
- tag : Option < String > ,
212
- } ,
213
- Resource {
214
- resource_id : String ,
215
- resource_type : String ,
229
+ resource : ParseableResourceType ,
230
+ // resource_id: String,
216
231
} ,
217
232
}
218
233
@@ -221,35 +236,29 @@ pub mod model {
221
236
match value {
222
237
DefaultPrivilege :: Admin => admin_perm_builder ( ) ,
223
238
DefaultPrivilege :: Editor => editor_perm_builder ( ) ,
224
- DefaultPrivilege :: Writer { stream } => {
225
- writer_perm_builder ( ) . with_stream ( stream. to_owned ( ) )
226
- }
227
- DefaultPrivilege :: Reader { stream, tag } => {
228
- let mut reader = reader_perm_builder ( ) . with_stream ( stream. to_owned ( ) ) ;
229
- if let Some ( tag) = tag {
230
- reader = reader. with_tag ( tag. to_owned ( ) )
231
- }
232
- reader
233
- }
234
- DefaultPrivilege :: Ingestor { stream } => {
235
- ingest_perm_builder ( ) . with_stream ( stream. to_owned ( ) )
236
- }
237
- DefaultPrivilege :: Resource {
238
- resource_id,
239
- resource_type,
240
- } => resource_perm_builder ( )
241
- . with_resource ( resource_id. clone ( ) , resource_type. clone ( ) ) ,
239
+ DefaultPrivilege :: Writer {
240
+ resource,
241
+ // resource_id,
242
+ } => writer_perm_builder ( )
243
+ . with_resource ( resource. to_owned ( ) ) ,
244
+ DefaultPrivilege :: Reader {
245
+ resource,
246
+ // resource_id,
247
+ } => reader_perm_builder ( )
248
+ . with_resource ( resource. to_owned ( ) ) ,
249
+ DefaultPrivilege :: Ingestor { resource } => ingest_perm_builder ( )
250
+ . with_resource ( resource. to_owned ( ) ) ,
242
251
}
243
252
}
244
253
}
245
254
246
255
fn admin_perm_builder ( ) -> RoleBuilder {
247
256
RoleBuilder {
248
257
actions : vec ! [ Action :: All ] ,
249
- stream : Some ( "*" . to_string ( ) ) ,
250
- tag : None ,
251
- resource_type : Some ( "*" . to_string ( ) ) ,
252
- resource_id : Some ( "*" . to_string ( ) ) ,
258
+ // stream: Some("*".to_string()),
259
+ // tag: None,
260
+ resource_type : Some ( ParseableResourceType :: All ) ,
261
+ // resource_id: Some("*".to_string()),
253
262
}
254
263
}
255
264
@@ -295,10 +304,10 @@ pub mod model {
295
304
Action :: DeleteDashboard ,
296
305
Action :: GetUserRoles ,
297
306
] ,
298
- stream : Some ( "*" . to_string ( ) ) ,
299
- tag : None ,
300
- resource_id : None ,
301
- resource_type : None ,
307
+ // stream: Some("*".to_string()),
308
+ // tag: None,
309
+ // resource_id: Some("*".to_string()) ,
310
+ resource_type : Some ( ParseableResourceType :: All ) ,
302
311
}
303
312
}
304
313
@@ -338,9 +347,9 @@ pub mod model {
338
347
Action :: DeleteFilter ,
339
348
Action :: GetUserRoles ,
340
349
] ,
341
- stream : None ,
342
- tag : None ,
343
- resource_id : None ,
350
+ // stream: None,
351
+ // tag: None,
352
+ // resource_id: None,
344
353
resource_type : None ,
345
354
}
346
355
}
@@ -374,29 +383,19 @@ pub mod model {
374
383
Action :: GetUserRoles ,
375
384
Action :: GetAlert ,
376
385
] ,
377
- stream : None ,
378
- tag : None ,
379
- resource_id : None ,
380
- resource_type : None ,
381
- }
382
- }
383
-
384
- fn resource_perm_builder ( ) -> RoleBuilder {
385
- RoleBuilder {
386
- actions : vec ! [ Action :: GetLLM , Action :: ListLLM , Action :: QueryLLM ] ,
387
- stream : None ,
388
- tag : None ,
389
- resource_id : None ,
386
+ // stream: None,
387
+ // tag: None,
388
+ // resource_id: None,
390
389
resource_type : None ,
391
390
}
392
391
}
393
392
394
393
fn ingest_perm_builder ( ) -> RoleBuilder {
395
394
RoleBuilder {
396
395
actions : vec ! [ Action :: Ingest ] ,
397
- stream : None ,
398
- tag : None ,
399
- resource_id : None ,
396
+ // stream: None,
397
+ // tag: None,
398
+ // resource_id: None,
400
399
resource_type : None ,
401
400
}
402
401
}
0 commit comments