@@ -176,44 +176,31 @@ export class APIv2 {
176176 /* XXX The permissions here only handle Kerberos identities. */
177177
178178 async id_list ( req , res ) {
179- const tok = await this . data . check_targ ( req . auth , Perm . ReadKrb , true ) ;
180- if ( ! tok ) fail ( 403 ) ;
181-
182- const ids = await this . data . find_identities ( i => tok ( i . uuid ) ) ;
183- const rv = [ ...new Set ( ids . map ( i => i . uuid ) ) ] ;
179+ const idr = await this . data . find_identities ( req . auth ) ;
184180
185- return res . status ( 200 ) . json ( rv ) ;
181+ idr . uniq ( i => i . uuid ) . toExpress ( res ) ;
186182 }
187183
188- async _id_get_all ( uuid , res ) {
189- const ids = await this . data . find_identities ( i => i . uuid == uuid ) ;
190- if ( ! ids . length ) fail ( 404 ) ;
184+ async _id_get_all ( upn , uuid , res ) {
185+ const idr = await this . data . find_identities ( upn , { uuid } ) ;
191186
192- const rv = Object . fromEntries (
193- ids . map ( i => [ i . kind , i . name ] )
194- . concat ( [ [ "uuid" , uuid ] ] ) ) ;
195- return res . status ( 200 ) . json ( rv ) ;
187+ idr . map ( ids =>
188+ Object . fromEntries (
189+ ids . map ( i => [ i . kind , i . name ] )
190+ . concat ( [ [ "uuid" , uuid ] ] ) ) )
191+ . toExpress ( res ) ;
196192 }
197193
198194 async id_get_all ( req , res ) {
199195 const { uuid } = req . params ;
200- if ( ! valid_uuid ( uuid ) ) fail ( 410 ) ;
201-
202- await this . check_acl ( req , Perm . ReadKrb , uuid ) ;
203-
204- return this . _id_get_all ( uuid , res ) ;
196+ return this . _id_get_all ( req . auth , uuid , res ) ;
205197 }
206198
207199 async id_get ( req , res ) {
208200 const { uuid, kind } = req . params ;
209- if ( ! valid_uuid ( uuid ) ) fail ( 410 ) ;
210-
211- await this . check_acl ( req , Perm . ReadKrb , uuid ) ;
212-
213- const id = await this . data . find_identities ( i => i . uuid == uuid && i . kind == kind ) ;
214- if ( ! id . length ) fail ( 404 ) ;
215201
216- return res . status ( 200 ) . json ( id [ 0 ] . name ) ;
202+ const idr = await this . data . find_identities ( req . auth , { uuid, kind } ) ;
203+ idr . single ( ) . map ( id => id . name ) . toExpress ( res ) ;
217204 }
218205
219206 async _id_put ( name , req , res ) {
@@ -235,52 +222,37 @@ export class APIv2 {
235222 }
236223
237224 async id_kinds ( req , res ) {
238- const ids = await this . data . find_identities ( ) ;
239- const rv = [ ... new Set ( ids . map ( i => i . kind ) ) ]
240- return res . status ( 200 ) . json ( rv ) ;
225+ /* XXX This should not be hardcoded. But it cannot change at
226+ * runtime. */
227+ return res . status ( 200 ) . json ( [ "kerberos" ] ) ;
241228 }
242229
243230 async id_list_kind ( req , res ) {
244231 const { kind } = req . params ;
245232
246- const tok = await this . data . check_targ ( req . auth , Perm . ReadKrb , true ) ;
247- if ( ! tok ) fail ( 403 ) ;
248-
249- const ids = await this . data . find_identities ( i => i . kind == kind ) ;
250- if ( ! ids . length ) fail ( 404 ) ;
251-
252- const rv = ids
253- . filter ( i => tok ( i . uuid ) )
254- . map ( i => i . name ) ;
255-
256- return res . status ( 200 ) . json ( rv ) ;
233+ const idr = await this . data . find_identities ( req . auth , { kind } ) ;
234+ idr . uniq ( i => i . name ) . toExpress ( res ) ;
257235 }
258236
259237 async id_find ( req , res ) {
260238 const { kind, name } = req . params ;
261239
262- const tok = await this . data . check_targ ( req . auth , Perm . ReadKrb , true ) ;
263- if ( ! tok ) fail ( 403 ) ;
264-
265- const ids = await this . data . find_identities ( i =>
266- i . kind == kind && i . name == name && tok ( i . uuid ) ) ;
267- if ( ! ids . length ) fail ( 404 ) ;
268-
269- return res . status ( 200 ) . json ( ids [ 0 ] . uuid ) ;
240+ const idr = await this . data . find_identities ( req . auth , { kind, name } ) ;
241+ idr . single ( ) . map ( id => id . uuid ) . toExpress ( res ) ;
270242 }
271243
272244 /* There is no auth check here; any authenticated user can look up
273245 * their own identities. This will only look up based on Kerberos
274246 * auth identity. */
275247
276248 async id_whoami ( req , res ) {
277- const uuid = await this . data . whoami ( req . auth ) ;
249+ const uuid = await this . data . find_kerberos ( req . auth ) ;
278250 if ( ! uuid ) fail ( 404 ) ;
279- return this . _id_get_all ( uuid , res ) ;
251+ return this . _id_get_all ( this . data . root , uuid , res ) ;
280252 }
281253
282254 async id_whoami_uuid ( req , res ) {
283- const uuid = await this . data . whoami ( req . auth ) ;
255+ const uuid = await this . data . find_kerberos ( req . auth ) ;
284256 if ( ! uuid ) fail ( 404 ) ;
285257 return res . status ( 200 ) . json ( uuid ) ;
286258 }
0 commit comments