Skip to content

Commit f43fb30

Browse files
committed
Add terse routes.
1 parent 75c25c4 commit f43fb30

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

lib/config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ cfg.routes = {
3232
credentialsStatus: '/credentials/status',
3333
// `slcs` route must be a prefix for `publishSlc` and `slc`
3434
publishSlc: '/slcs/:slcId/publish',
35+
publishTerseSlc: '/slcs/terse/:statusPurpose/:listIndex',
3536
slc: '/slcs/:slcId',
36-
slcs: '/slcs'
37+
slcs: '/slcs',
38+
terseSlc: '/slcs/terse/:statusPurpose/:listIndex',
39+
terseSlcs: '/slcs/terse'
3740
};
3841

3942
// create dev application identity for vc-issuer (must be overridden in

lib/http.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export async function addRoutes({app, service} = {}) {
3737
credentialsIssue: `${baseUrl}${cfg.routes.credentialsIssue}`,
3838
credentialsStatus: `${baseUrl}${cfg.routes.credentialsStatus}`,
3939
publishSlc: `${baseUrl}${cfg.routes.publishSlc}`,
40-
slc: `${baseUrl}${cfg.routes.slc}`
40+
publishTerseSlc: `${baseUrl}${cfg.routes.publishTerseSlc}`,
41+
slc: `${baseUrl}${cfg.routes.slc}`,
42+
terseSlc: `${baseUrl}${cfg.routes.terseSlc}`
4143
};
4244

4345
const getConfigMiddleware = middleware.createGetConfigMiddleware({service});
@@ -106,7 +108,7 @@ export async function addRoutes({app, service} = {}) {
106108
metering.reportOperationUsage({req});
107109
}));
108110

109-
// publish the latest SLC from EDV storage
111+
// publish the latest non-terse SLC from EDV storage
110112
app.options(routes.publishSlc, cors());
111113
app.post(
112114
routes.publishSlc,
@@ -126,7 +128,7 @@ export async function addRoutes({app, service} = {}) {
126128
metering.reportOperationUsage({req});
127129
}));
128130

129-
// get latest published SLC, no-authz required
131+
// get latest published non-terse SLC, no-authz required
130132
app.get(
131133
routes.slc,
132134
cors(),
@@ -138,4 +140,39 @@ export async function addRoutes({app, service} = {}) {
138140
const {credential} = await slcs.getFresh({id, config});
139141
res.json(credential);
140142
}));
143+
144+
// publish the latest terse SLC from EDV storage
145+
app.options(routes.publishTerseSlc, cors());
146+
app.post(
147+
routes.publishTerseSlc,
148+
cors(),
149+
validate({bodySchema: publishSlcBody}),
150+
getConfigMiddleware,
151+
middleware.authorizeServiceObjectRequest(),
152+
asyncHandler(async (req, res) => {
153+
const {config} = req.serviceObject;
154+
const {statusPurpose, listIndex} = req.params;
155+
const id = `${config.id}${cfg.routes.terseSlcs}/` +
156+
`${encodeURIComponent(statusPurpose)}/${listIndex}`;
157+
158+
await slcs.refresh({id, config});
159+
res.sendStatus(204);
160+
161+
// meter operation usage
162+
metering.reportOperationUsage({req});
163+
}));
164+
165+
// get latest published terse SLC, no-authz required
166+
app.get(
167+
routes.terseSlc,
168+
cors(),
169+
getConfigMiddleware,
170+
asyncHandler(async (req, res) => {
171+
const {config} = req.serviceObject;
172+
const {statusPurpose, listIndex} = req.params;
173+
const id = `${config.id}${cfg.routes.terseSlcs}/` +
174+
`${encodeURIComponent(statusPurpose)}/${listIndex}`;
175+
const {credential} = await slcs.getFresh({id, config});
176+
res.json(credential);
177+
}));
141178
}

lib/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ async function validateConfigFn({config, op, existingConfig} = {}) {
133133
'Each status list configuration requires an "indexAllocator".');
134134
}
135135

136-
// FIXME: hard require `baseUrl` once status service is separated
137-
// ensure base URL is set for new status list creation
138-
if(statusConfig.baseUrl === undefined) {
139-
statusConfig.baseUrl = config.id +
140-
bedrock.config['vc-issuer'].routes.slcs;
141-
}
142-
143136
// set default options
144137
const options = {
145138
blockCount: DEFAULT_BLOCK_COUNT,
@@ -173,6 +166,15 @@ async function validateConfigFn({config, op, existingConfig} = {}) {
173166
}
174167
statusConfig.options = options;
175168

169+
// FIXME: hard require `baseUrl` once status service is separated
170+
// ensure base URL is set for new status list creation
171+
if(statusConfig.baseUrl === undefined) {
172+
const suffix = options.listCount === undefined ?
173+
bedrock.config['vc-issuer'].routes.slcs :
174+
bedrock.config['vc-issuer'].routes.terseSlcs;
175+
statusConfig.baseUrl = config.id + suffix;
176+
}
177+
176178
getSuiteParams({config, suiteName});
177179
}
178180
} catch(error) {

0 commit comments

Comments
 (0)