File tree 3 files changed +26
-16
lines changed
db-queries/src/db/datastore
3 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -219,19 +219,11 @@ impl<'a> LookupPath<'a> {
219
219
)
220
220
}
221
221
222
+ // TODO: do the same conversion for this
223
+
222
224
/// Select a resource of type DeviceAccessToken, identified by its `token`
223
- pub fn device_access_token < ' b , ' c > (
224
- self ,
225
- token : & ' b str ,
226
- ) -> DeviceAccessToken < ' c >
227
- where
228
- ' a : ' c ,
229
- ' b : ' c ,
230
- {
231
- DeviceAccessToken :: PrimaryKey (
232
- Root { lookup_root : self } ,
233
- token. to_string ( ) ,
234
- )
225
+ pub fn device_access_token_id ( self , id : Uuid ) -> DeviceAccessToken < ' a > {
226
+ DeviceAccessToken :: PrimaryKey ( Root { lookup_root : self } , id)
235
227
}
236
228
237
229
/// Select a resource of type RoleBuiltin, identified by its `name`
@@ -772,7 +764,7 @@ lookup_resource! {
772
764
lookup_by_name = false ,
773
765
soft_deletes = false ,
774
766
primary_key_columns = [
775
- { column_name = "token " , rust_type = String } ,
767
+ { column_name = "id " , rust_type = Uuid } ,
776
768
]
777
769
}
778
770
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ use async_bb8_diesel::AsyncRunQueryDsl;
13
13
use diesel:: prelude:: * ;
14
14
use nexus_db_errors:: ErrorHandler ;
15
15
use nexus_db_errors:: public_error_from_diesel;
16
+ use nexus_db_schema:: schema:: device_access_token;
16
17
use omicron_common:: api:: external:: CreateResult ;
17
18
use omicron_common:: api:: external:: Error ;
18
19
use omicron_common:: api:: external:: LookupResult ;
@@ -21,6 +22,23 @@ use omicron_common::api::external::ResourceType;
21
22
use uuid:: Uuid ;
22
23
23
24
impl DataStore {
25
+ pub async fn device_token_lookup_by_token (
26
+ & self ,
27
+ opctx : & OpContext ,
28
+ token : String ,
29
+ ) -> LookupResult < DeviceAccessToken > {
30
+ // TODO: some special system authz because the presence of the token _is_ the authz
31
+ device_access_token:: table
32
+ . filter ( device_access_token:: token. eq ( token) )
33
+ . select ( DeviceAccessToken :: as_returning ( ) )
34
+ . get_result_async ( & * self . pool_connection_authorized ( opctx) . await ?)
35
+ . await
36
+ . map_err ( |_e| Error :: ObjectNotFound {
37
+ type_name : ResourceType :: DeviceAccessToken ,
38
+ lookup_type : LookupType :: ByOther ( "access token" . to_string ( ) ) ,
39
+ } )
40
+ }
41
+
24
42
/// Start a device authorization grant flow by recording the request
25
43
/// and initial response parameters.
26
44
pub async fn device_auth_request_create (
Original file line number Diff line number Diff line change @@ -166,9 +166,9 @@ impl super::Nexus {
166
166
opctx : & OpContext ,
167
167
token : String ,
168
168
) -> Result < Actor , Reason > {
169
- let ( .. , db_access_token) = LookupPath :: new ( opctx , & self . db_datastore )
170
- . device_access_token ( & token )
171
- . fetch ( )
169
+ let db_access_token = self
170
+ . db_datastore
171
+ . device_token_lookup_by_token ( opctx , token )
172
172
. await
173
173
. map_err ( |e| match e {
174
174
Error :: ObjectNotFound { .. } => Reason :: UnknownActor {
You can’t perform that action at this time.
0 commit comments