11/*!
2- * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
2+ * Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
33 */
44import * as bedrock from '@bedrock/core' ;
55import * as brZCapStorage from '@bedrock/zcap-storage' ;
@@ -17,13 +17,12 @@ import {
1717} from '@bedrock/kms' ;
1818import { reportOperationUsage , SERVICE_TYPE } from './metering.js' ;
1919import { asyncHandler } from '@bedrock/express' ;
20- import { BedrockKeystoreConfigStorage } from './BedrockKeystoreConfigStorage.js' ;
2120import { generateRandom } from '@digitalbazaar/webkms-switch' ;
2221import { meters } from '@bedrock/meter-usage-reporter' ;
2322import { createValidateMiddleware as validate } from '@bedrock/validation' ;
2423
2524const { config, util : { BedrockError} } = bedrock ;
26- const { cors} = middleware ;
25+ const { cors, storage } = middleware ;
2726
2827bedrock . events . on ( 'bedrock-express.configure.routes' , app => {
2928 const cfg = config [ 'kms-http' ] ;
@@ -43,10 +42,6 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
4342 routes . key = `${ routes . keys } /:keyId` ;
4443 routes . revocations = `${ routes . keystore } /zcaps/revocations/:revocationId` ;
4544
46- const { baseUri} = bedrock . config . server ;
47-
48- const storage = new BedrockKeystoreConfigStorage ( ) ;
49-
5045 // create middleware for handling KMS operations
5146 const handleOperation = middleware . createKmsOperationMiddleware ( ) ;
5247
@@ -57,30 +52,6 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
5752 /* Note: CORS is used on all endpoints. This is safe because authorization
5853 uses HTTP signatures + capabilities, not cookies; CSRF is not possible. */
5954
60- // get all keystores with root controller
61- app . options ( routes . keystores , cors ( ) ) ;
62- app . get (
63- routes . keystores ,
64- cors ( ) ,
65- validate ( { querySchema : getConfigsQuery } ) ,
66- middleware . authorizeZcapInvocation ( {
67- async getExpectedValues ( ) {
68- return {
69- host : bedrock . config . server . host ,
70- rootInvocationTarget : baseUri + routes . keystores
71- } ;
72- } ,
73- async getRootController ( { req} ) {
74- return req . query . controller ;
75- }
76- } ) ,
77- asyncHandler ( async ( req , res ) => {
78- const controller = req . query . controller ;
79- const options = { projection : { _id : 0 , config : 1 } , limit : 100 } ;
80- const results = await storage . getAll ( { controller, req, options} ) ;
81- res . json ( { results} ) ;
82- } ) ) ;
83-
8455 // create a new keystore
8556 app . options ( routes . keystores , cors ( ) ) ;
8657 app . post (
@@ -204,6 +175,30 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
204175 reportOperationUsage ( { req} ) ;
205176 } ) ) ;
206177
178+ // get all keystores with root controller
179+ app . get (
180+ routes . keystores ,
181+ cors ( ) ,
182+ validate ( { querySchema : getConfigsQuery } ) ,
183+ middleware . authorizeZcapInvocation ( {
184+ async getExpectedValues ( ) {
185+ const { baseUri, host} = bedrock . config . server ;
186+ return {
187+ host,
188+ rootInvocationTarget : `${ baseUri } ${ routes . keystores } `
189+ } ;
190+ } ,
191+ async getRootController ( { req} ) {
192+ return req . query . controller ;
193+ }
194+ } ) ,
195+ asyncHandler ( async ( req , res ) => {
196+ const controller = req . query . controller ;
197+ const options = { projection : { _id : 0 , config : 1 } , limit : 100 } ;
198+ const results = await storage . getAll ( { controller, req, options} ) ;
199+ res . json ( { results} ) ;
200+ } ) ) ;
201+
207202 // get a keystore config
208203 app . get (
209204 routes . keystore ,
0 commit comments