20
20
// parts we need for authorization.
21
21
22
22
use super :: actor:: AnyActor ;
23
- use super :: context:: Authorize ;
23
+ use super :: context:: AuthorizedResource ;
24
24
use super :: roles:: {
25
25
load_roles_for_resource, load_roles_for_resource_tree, RoleSet ,
26
26
} ;
@@ -37,9 +37,7 @@ use uuid::Uuid;
37
37
38
38
/// Describes an authz resource that corresponds to an API resource that has a
39
39
/// corresponding ResourceType and is stored in the database
40
- ///
41
- /// This is a helper trait used to impl [`AuthzResource`].
42
- pub trait AuthzApiResource : Clone + Send + Sync + ' static {
40
+ pub trait ApiResource : Clone + Send + Sync + ' static {
43
41
/// If roles can be assigned to this resource, return the type and id of the
44
42
/// database record describing this resource
45
43
///
@@ -49,14 +47,14 @@ pub trait AuthzApiResource: Clone + Send + Sync + 'static {
49
47
/// If this resource has a parent in the API hierarchy whose assigned roles
50
48
/// can affect access to this resource, return the parent resource.
51
49
/// Otherwise, returns `None`.
52
- fn parent ( & self ) -> Option < & dyn Authorize > ;
50
+ fn parent ( & self ) -> Option < & dyn AuthorizedResource > ;
53
51
54
52
/// Returns an error as though this resource were not found, suitable for
55
53
/// use when an actor should not be able to see that this resource exists
56
54
fn not_found ( & self ) -> Error ;
57
55
}
58
56
59
- impl < T : AuthzApiResource + oso:: PolarClass > Authorize for T {
57
+ impl < T : ApiResource + oso:: PolarClass > AuthorizedResource for T {
60
58
fn load_roles < ' a , ' b , ' c , ' d , ' e , ' f > (
61
59
& ' a self ,
62
60
opctx : & ' b OpContext ,
@@ -81,21 +79,21 @@ impl<T: AuthzApiResource + oso::PolarClass> Authorize for T {
81
79
error : Error ,
82
80
actor : AnyActor ,
83
81
action : Action ,
84
- ) -> Result < ( ) , Error > {
82
+ ) -> Error {
85
83
if action == Action :: Read {
86
- return Err ( self . not_found ( ) ) ;
84
+ return self . not_found ( ) ;
87
85
}
88
86
89
87
// If the user failed an authz check, and they can't even read this
90
88
// resource, then we should produce a 404 rather than a 401/403.
91
89
match authz. is_allowed ( & actor, Action :: Read , self ) {
92
- Err ( error) => Err ( Error :: internal_error ( & format ! (
90
+ Err ( error) => Error :: internal_error ( & format ! (
93
91
"failed to compute read authorization to determine visibility: \
94
92
{:#}",
95
93
error
96
- ) ) ) ,
97
- Ok ( false ) => Err ( self . not_found ( ) ) ,
98
- Ok ( true ) => Err ( error) ,
94
+ ) ) ,
95
+ Ok ( false ) => self . not_found ( ) ,
96
+ Ok ( true ) => error,
99
97
}
100
98
}
101
99
}
@@ -163,13 +161,13 @@ impl oso::PolarClass for Fleet {
163
161
}
164
162
}
165
163
166
- impl Authorize for Fleet {
164
+ impl AuthorizedResource for Fleet {
167
165
fn load_roles < ' a , ' b , ' c , ' d , ' e , ' f > (
168
166
& ' a self ,
169
- opctx : & ' b crate :: context :: OpContext ,
170
- datastore : & ' c crate :: db :: DataStore ,
171
- authn : & ' d crate :: authn:: Context ,
172
- roleset : & ' e mut super :: roles :: RoleSet ,
167
+ opctx : & ' b OpContext ,
168
+ datastore : & ' c DataStore ,
169
+ authn : & ' d authn:: Context ,
170
+ roleset : & ' e mut RoleSet ,
173
171
) -> futures:: future:: BoxFuture < ' f , Result < ( ) , Error > >
174
172
where
175
173
' a : ' f ,
@@ -195,8 +193,8 @@ impl Authorize for Fleet {
195
193
error : Error ,
196
194
_: AnyActor ,
197
195
_: Action ,
198
- ) -> Result < ( ) , Error > {
199
- Err ( error)
196
+ ) -> Error {
197
+ error
200
198
}
201
199
}
202
200
@@ -232,12 +230,12 @@ impl oso::PolarClass for FleetChild {
232
230
}
233
231
}
234
232
235
- impl AuthzApiResource for FleetChild {
233
+ impl ApiResource for FleetChild {
236
234
fn db_resource ( & self ) -> Option < ( ResourceType , Uuid ) > {
237
235
None
238
236
}
239
237
240
- fn parent ( & self ) -> Option < & dyn Authorize > {
238
+ fn parent ( & self ) -> Option < & dyn AuthorizedResource > {
241
239
Some ( & FLEET )
242
240
}
243
241
@@ -303,12 +301,12 @@ impl oso::PolarClass for Organization {
303
301
}
304
302
}
305
303
306
- impl AuthzApiResource for Organization {
304
+ impl ApiResource for Organization {
307
305
fn db_resource ( & self ) -> Option < ( ResourceType , Uuid ) > {
308
306
Some ( ( ResourceType :: Organization , self . organization_id ) )
309
307
}
310
308
311
- fn parent ( & self ) -> Option < & dyn Authorize > {
309
+ fn parent ( & self ) -> Option < & dyn AuthorizedResource > {
312
310
Some ( & FLEET )
313
311
}
314
312
@@ -382,12 +380,12 @@ impl oso::PolarClass for Project {
382
380
}
383
381
}
384
382
385
- impl AuthzApiResource for Project {
383
+ impl ApiResource for Project {
386
384
fn db_resource ( & self ) -> Option < ( ResourceType , Uuid ) > {
387
385
Some ( ( ResourceType :: Project , self . project_id ) )
388
386
}
389
387
390
- fn parent ( & self ) -> Option < & dyn Authorize > {
388
+ fn parent ( & self ) -> Option < & dyn AuthorizedResource > {
391
389
Some ( & self . parent )
392
390
}
393
391
@@ -438,13 +436,13 @@ impl oso::PolarClass for ProjectChild {
438
436
}
439
437
}
440
438
441
- impl AuthzApiResource for ProjectChild {
439
+ impl ApiResource for ProjectChild {
442
440
fn db_resource ( & self ) -> Option < ( ResourceType , Uuid ) > {
443
441
// We do not support assigning roles to children of Projects.
444
442
None
445
443
}
446
444
447
- fn parent ( & self ) -> Option < & dyn Authorize > {
445
+ fn parent ( & self ) -> Option < & dyn AuthorizedResource > {
448
446
Some ( & self . parent )
449
447
}
450
448
0 commit comments