@twin.org/rights-management-service 0.0.2-next.5 → 0.0.2-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +392 -578
- package/dist/esm/index.mjs +386 -577
- package/dist/types/index.d.ts +4 -3
- package/dist/types/policyAdministrationPointRoutes.d.ts +53 -0
- package/dist/types/policyEnforcementPointRoutes.d.ts +21 -0
- package/dist/types/policyNegotiationAdminPointRoutes.d.ts +45 -0
- package/dist/types/policyNegotiationPointRoutes.d.ts +37 -0
- package/docs/changelog.md +44 -0
- package/docs/open-api/spec.json +28 -190
- package/docs/reference/functions/generateRestRoutesPolicyAdministrationPoint.md +25 -0
- package/docs/reference/functions/{generateRestRoutesRightsManagement.md → generateRestRoutesPolicyEnforcementPoint.md} +3 -3
- package/docs/reference/functions/generateRestRoutesPolicyNegotiationAdminPoint.md +25 -0
- package/docs/reference/functions/generateRestRoutesPolicyNegotiationPoint.md +25 -0
- package/docs/reference/functions/{papRetrieve.md → papGet.md} +5 -5
- package/docs/reference/index.md +12 -14
- package/docs/reference/variables/papTags.md +5 -0
- package/docs/reference/variables/pepTags.md +5 -0
- package/docs/reference/variables/pnapTags.md +5 -0
- package/docs/reference/variables/pnpTags.md +5 -0
- package/locales/en.json +1 -18
- package/package.json +2 -2
- package/dist/types/models/IRightsManagementServiceConstructorOptions.d.ts +0 -25
- package/dist/types/rightsManagementRoutes.d.ts +0 -117
- package/dist/types/rightsManagementService.d.ts +0 -124
- package/docs/reference/classes/RightsManagementService.md +0 -488
- package/docs/reference/interfaces/IRightsManagementServiceConstructorOptions.md +0 -59
- package/docs/reference/variables/tags.md +0 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -10,27 +10,27 @@ var web = require('@twin.org/web');
|
|
|
10
10
|
/**
|
|
11
11
|
* The source used when communicating about these routes.
|
|
12
12
|
*/
|
|
13
|
-
const ROUTES_SOURCE = "
|
|
13
|
+
const ROUTES_SOURCE$3 = "policyAdministrationPointRoutes";
|
|
14
14
|
/**
|
|
15
15
|
* The tag to associate with the routes.
|
|
16
16
|
*/
|
|
17
|
-
const
|
|
17
|
+
const papTags = [
|
|
18
18
|
{
|
|
19
19
|
name: "Policy Administration Point",
|
|
20
20
|
description: "Endpoints for managing ODRL policies in the Policy Administration Point"
|
|
21
21
|
}
|
|
22
22
|
];
|
|
23
23
|
/**
|
|
24
|
-
* The REST routes for the
|
|
24
|
+
* The REST routes for the Policy Administration Point.
|
|
25
25
|
* @param baseRouteName Prefix to prepend to the paths.
|
|
26
26
|
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
27
27
|
* @returns The generated routes.
|
|
28
28
|
*/
|
|
29
|
-
function
|
|
29
|
+
function generateRestRoutesPolicyAdministrationPoint(baseRouteName, componentName) {
|
|
30
30
|
const papCreateRoute = {
|
|
31
31
|
operationId: "papCreate",
|
|
32
32
|
summary: "Create a policy",
|
|
33
|
-
tag:
|
|
33
|
+
tag: papTags[0].name,
|
|
34
34
|
method: "POST",
|
|
35
35
|
path: `${baseRouteName}/pap/`,
|
|
36
36
|
handler: async (httpRequestContext, request) => papCreate(httpRequestContext, componentName, request),
|
|
@@ -74,7 +74,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
74
74
|
const papUpdateRoute = {
|
|
75
75
|
operationId: "papUpdate",
|
|
76
76
|
summary: "Update a policy",
|
|
77
|
-
tag:
|
|
77
|
+
tag: papTags[0].name,
|
|
78
78
|
method: "PUT",
|
|
79
79
|
path: `${baseRouteName}/pap/:id`,
|
|
80
80
|
handler: async (httpRequestContext, request) => papUpdate(httpRequestContext, componentName, request),
|
|
@@ -108,18 +108,18 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
108
108
|
}
|
|
109
109
|
]
|
|
110
110
|
};
|
|
111
|
-
const
|
|
112
|
-
operationId: "
|
|
113
|
-
summary: "
|
|
114
|
-
tag:
|
|
111
|
+
const papGetRoute = {
|
|
112
|
+
operationId: "papGet",
|
|
113
|
+
summary: "Get a policy",
|
|
114
|
+
tag: papTags[0].name,
|
|
115
115
|
method: "GET",
|
|
116
116
|
path: `${baseRouteName}/pap/:id`,
|
|
117
|
-
handler: async (httpRequestContext, request) =>
|
|
117
|
+
handler: async (httpRequestContext, request) => papGet(httpRequestContext, componentName, request),
|
|
118
118
|
requestType: {
|
|
119
|
-
type: "
|
|
119
|
+
type: "IPapGetRequest",
|
|
120
120
|
examples: [
|
|
121
121
|
{
|
|
122
|
-
id: "
|
|
122
|
+
id: "papGetRequestExample",
|
|
123
123
|
request: {
|
|
124
124
|
pathParams: {
|
|
125
125
|
id: "urn:rights-management:abc123def456"
|
|
@@ -130,10 +130,10 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
130
130
|
},
|
|
131
131
|
responseType: [
|
|
132
132
|
{
|
|
133
|
-
type: "
|
|
133
|
+
type: "IPapGetResponse",
|
|
134
134
|
examples: [
|
|
135
135
|
{
|
|
136
|
-
id: "
|
|
136
|
+
id: "papGetResponseExample",
|
|
137
137
|
response: {
|
|
138
138
|
body: {
|
|
139
139
|
"@context": standardsW3cOdrl.OdrlContexts.ContextRoot,
|
|
@@ -155,7 +155,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
155
155
|
const papRemoveRoute = {
|
|
156
156
|
operationId: "papRemove",
|
|
157
157
|
summary: "Remove a policy",
|
|
158
|
-
tag:
|
|
158
|
+
tag: papTags[0].name,
|
|
159
159
|
method: "DELETE",
|
|
160
160
|
path: `${baseRouteName}/pap/:id`,
|
|
161
161
|
handler: async (httpRequestContext, request) => papRemove(httpRequestContext, componentName, request),
|
|
@@ -181,7 +181,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
181
181
|
const papQueryRoute = {
|
|
182
182
|
operationId: "papQuery",
|
|
183
183
|
summary: "Query policies",
|
|
184
|
-
tag:
|
|
184
|
+
tag: papTags[0].name,
|
|
185
185
|
method: "GET",
|
|
186
186
|
path: `${baseRouteName}/pap/query`,
|
|
187
187
|
handler: async (httpRequestContext, request) => papQuery(httpRequestContext, componentName, request),
|
|
@@ -227,10 +227,123 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
227
227
|
}
|
|
228
228
|
]
|
|
229
229
|
};
|
|
230
|
+
return [papCreateRoute, papUpdateRoute, papGetRoute, papRemoveRoute, papQueryRoute];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* PAP: Create a policy.
|
|
234
|
+
* @param httpRequestContext The request context for the API.
|
|
235
|
+
* @param componentName The name of the component to use in the routes.
|
|
236
|
+
* @param request The request.
|
|
237
|
+
* @returns The response object with additional http response properties.
|
|
238
|
+
*/
|
|
239
|
+
async function papCreate(httpRequestContext, componentName, request) {
|
|
240
|
+
core.Guards.object(ROUTES_SOURCE$3, "request", request);
|
|
241
|
+
core.Guards.object(ROUTES_SOURCE$3, "request.body", request.body);
|
|
242
|
+
const component = core.ComponentFactory.get(componentName);
|
|
243
|
+
const policy = request.body;
|
|
244
|
+
const uid = await component.create(policy);
|
|
245
|
+
return {
|
|
246
|
+
statusCode: web.HttpStatusCode.created,
|
|
247
|
+
headers: {
|
|
248
|
+
location: uid
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* PAP: Update a policy.
|
|
254
|
+
* @param httpRequestContext The request context for the API.
|
|
255
|
+
* @param componentName The name of the component to use in the routes.
|
|
256
|
+
* @param request The request.
|
|
257
|
+
* @returns The response object with additional http response properties.
|
|
258
|
+
*/
|
|
259
|
+
async function papUpdate(httpRequestContext, componentName, request) {
|
|
260
|
+
core.Guards.object(ROUTES_SOURCE$3, "request", request);
|
|
261
|
+
core.Guards.object(ROUTES_SOURCE$3, "request.pathParams", request.pathParams);
|
|
262
|
+
core.Guards.stringValue(ROUTES_SOURCE$3, "request.pathParams.id", request.pathParams.id);
|
|
263
|
+
core.Guards.object(ROUTES_SOURCE$3, "request.body", request.body);
|
|
264
|
+
const component = core.ComponentFactory.get(componentName);
|
|
265
|
+
await component.update(request.body);
|
|
266
|
+
return {
|
|
267
|
+
statusCode: web.HttpStatusCode.noContent
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* PAP: Get a policy.
|
|
272
|
+
* @param httpRequestContext The request context for the API.
|
|
273
|
+
* @param componentName The name of the component to use in the routes.
|
|
274
|
+
* @param request The request.
|
|
275
|
+
* @returns The response object with additional http response properties.
|
|
276
|
+
*/
|
|
277
|
+
async function papGet(httpRequestContext, componentName, request) {
|
|
278
|
+
core.Guards.object(ROUTES_SOURCE$3, "request", request);
|
|
279
|
+
core.Guards.object(ROUTES_SOURCE$3, "request.pathParams", request.pathParams);
|
|
280
|
+
core.Guards.stringValue(ROUTES_SOURCE$3, "request.pathParams.id", request.pathParams.id);
|
|
281
|
+
const component = core.ComponentFactory.get(componentName);
|
|
282
|
+
const policy = await component.get(request.pathParams.id);
|
|
283
|
+
return {
|
|
284
|
+
body: policy
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* PAP: Remove a policy.
|
|
289
|
+
* @param httpRequestContext The request context for the API.
|
|
290
|
+
* @param componentName The name of the component to use in the routes.
|
|
291
|
+
* @param request The request.
|
|
292
|
+
* @returns The response object with additional http response properties.
|
|
293
|
+
*/
|
|
294
|
+
async function papRemove(httpRequestContext, componentName, request) {
|
|
295
|
+
core.Guards.object(ROUTES_SOURCE$3, "request", request);
|
|
296
|
+
core.Guards.object(ROUTES_SOURCE$3, "request.pathParams", request.pathParams);
|
|
297
|
+
core.Guards.stringValue(ROUTES_SOURCE$3, "request.pathParams.id", request.pathParams.id);
|
|
298
|
+
const component = core.ComponentFactory.get(componentName);
|
|
299
|
+
await component.remove(request.pathParams.id);
|
|
300
|
+
return {
|
|
301
|
+
statusCode: web.HttpStatusCode.noContent
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* PAP: Query policies.
|
|
306
|
+
* @param httpRequestContext The request context for the API.
|
|
307
|
+
* @param componentName The name of the component to use in the routes.
|
|
308
|
+
* @param request The request.
|
|
309
|
+
* @returns The response object with additional http response properties.
|
|
310
|
+
*/
|
|
311
|
+
async function papQuery(httpRequestContext, componentName, request) {
|
|
312
|
+
core.Guards.object(ROUTES_SOURCE$3, "request", request);
|
|
313
|
+
const component = core.ComponentFactory.get(componentName);
|
|
314
|
+
const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.cursor, core.Coerce.integer(request.query?.pageSize));
|
|
315
|
+
return {
|
|
316
|
+
body: {
|
|
317
|
+
cursor: result.cursor,
|
|
318
|
+
policies: result.policies
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The source used when communicating about these routes.
|
|
325
|
+
*/
|
|
326
|
+
const ROUTES_SOURCE$2 = "policyEnforcementPointRoutes";
|
|
327
|
+
/**
|
|
328
|
+
* The tag to associate with the routes.
|
|
329
|
+
*/
|
|
330
|
+
const pepTags = [
|
|
331
|
+
{
|
|
332
|
+
name: "Policy Enforcement Point",
|
|
333
|
+
description: "Endpoints for managing ODRL policies in the Policy Enforcement Point"
|
|
334
|
+
}
|
|
335
|
+
];
|
|
336
|
+
/**
|
|
337
|
+
* The REST routes for the Policy Enforcement Point.
|
|
338
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
339
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
340
|
+
* @returns The generated routes.
|
|
341
|
+
*/
|
|
342
|
+
function generateRestRoutesPolicyEnforcementPoint(baseRouteName, componentName) {
|
|
230
343
|
const pepInterceptRoute = {
|
|
231
344
|
operationId: "pepIntercept",
|
|
232
345
|
summary: "Intercept a request",
|
|
233
|
-
tag:
|
|
346
|
+
tag: pepTags[0].name,
|
|
234
347
|
method: "POST",
|
|
235
348
|
path: `${baseRouteName}/pep/intercept`,
|
|
236
349
|
handler: async (httpRequestContext, request) => pepIntercept(httpRequestContext, componentName, request),
|
|
@@ -270,147 +383,52 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
270
383
|
}
|
|
271
384
|
]
|
|
272
385
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
proof: {
|
|
293
|
-
created: "2024-08-22T11:56:56.272Z",
|
|
294
|
-
type: "DataIntegrityProof",
|
|
295
|
-
cryptosuite: "eddsa-jcs-2022",
|
|
296
|
-
proofPurpose: "assertionMethod",
|
|
297
|
-
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
298
|
-
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
]
|
|
304
|
-
},
|
|
305
|
-
responseType: [
|
|
306
|
-
{
|
|
307
|
-
type: "IPnpNegotiateResponse",
|
|
308
|
-
examples: [
|
|
309
|
-
{
|
|
310
|
-
id: "IPnpNegotiateResponseExample",
|
|
311
|
-
response: {
|
|
312
|
-
body: {
|
|
313
|
-
id: "policy-1",
|
|
314
|
-
status: "approved"
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
]
|
|
319
|
-
}
|
|
320
|
-
],
|
|
321
|
-
skipAuth: true
|
|
322
|
-
};
|
|
323
|
-
const papNegotiationStateRoute = {
|
|
324
|
-
operationId: "pnpNegotiationState",
|
|
325
|
-
summary: "Get the state of a policy",
|
|
326
|
-
tag: tags[0].name,
|
|
327
|
-
method: "POST",
|
|
328
|
-
path: `${baseRouteName}/pnp/:policyId`,
|
|
329
|
-
handler: async (httpRequestContext, request) => pnpNegotiationState(httpRequestContext, componentName, request),
|
|
330
|
-
requestType: {
|
|
331
|
-
type: "IPnpNegotiationStateRequest",
|
|
332
|
-
examples: [
|
|
333
|
-
{
|
|
334
|
-
id: "pnpNegotiationStateRequestExample",
|
|
335
|
-
request: {
|
|
336
|
-
pathParams: {
|
|
337
|
-
policyId: "policy-1"
|
|
338
|
-
},
|
|
339
|
-
body: {
|
|
340
|
-
nodeIdentity: "urn:example:node:1",
|
|
341
|
-
proof: {
|
|
342
|
-
created: "2024-08-22T11:56:56.272Z",
|
|
343
|
-
type: "DataIntegrityProof",
|
|
344
|
-
cryptosuite: "eddsa-jcs-2022",
|
|
345
|
-
proofPurpose: "assertionMethod",
|
|
346
|
-
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
347
|
-
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
]
|
|
353
|
-
},
|
|
354
|
-
responseType: [
|
|
355
|
-
{
|
|
356
|
-
type: "IPnpNegotiationStateResponse",
|
|
357
|
-
examples: [
|
|
358
|
-
{
|
|
359
|
-
id: "IPnpNegotiationStateResponseExample",
|
|
360
|
-
response: {
|
|
361
|
-
body: {
|
|
362
|
-
id: "policy-1",
|
|
363
|
-
status: "approved"
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
]
|
|
368
|
-
}
|
|
369
|
-
],
|
|
370
|
-
skipAuth: true
|
|
371
|
-
};
|
|
372
|
-
const pnpNegotiationCancelRoute = {
|
|
373
|
-
operationId: "pnpCancel",
|
|
374
|
-
summary: "Cancel a policy negotiation",
|
|
375
|
-
tag: tags[0].name,
|
|
376
|
-
method: "DELETE",
|
|
377
|
-
path: `${baseRouteName}/pnp/:policyId`,
|
|
378
|
-
handler: async (httpRequestContext, request) => pnpNegotiationCancel(httpRequestContext, componentName, request),
|
|
379
|
-
requestType: {
|
|
380
|
-
type: "IPnpNegotiationCancelRequest",
|
|
381
|
-
examples: [
|
|
382
|
-
{
|
|
383
|
-
id: "pnpNegotiationCancelRequestExample",
|
|
384
|
-
request: {
|
|
385
|
-
pathParams: {
|
|
386
|
-
policyId: "policy-1"
|
|
387
|
-
},
|
|
388
|
-
body: {
|
|
389
|
-
nodeIdentity: "urn:example:node:1",
|
|
390
|
-
proof: {
|
|
391
|
-
created: "2024-08-22T11:56:56.272Z",
|
|
392
|
-
type: "DataIntegrityProof",
|
|
393
|
-
cryptosuite: "eddsa-jcs-2022",
|
|
394
|
-
proofPurpose: "assertionMethod",
|
|
395
|
-
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
396
|
-
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
]
|
|
402
|
-
},
|
|
403
|
-
responseType: [
|
|
404
|
-
{
|
|
405
|
-
type: "INoContentResponse"
|
|
406
|
-
}
|
|
407
|
-
],
|
|
408
|
-
skipAuth: true
|
|
386
|
+
return [pepInterceptRoute];
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* PEP: Intercept.
|
|
390
|
+
* @param httpRequestContext The request context for the API.
|
|
391
|
+
* @param componentName The name of the component to use in the routes.
|
|
392
|
+
* @param request The request.
|
|
393
|
+
* @returns The response object with additional http response properties.
|
|
394
|
+
*/
|
|
395
|
+
async function pepIntercept(httpRequestContext, componentName, request) {
|
|
396
|
+
core.Guards.object(ROUTES_SOURCE$2, "request", request);
|
|
397
|
+
const component = core.ComponentFactory.get(componentName);
|
|
398
|
+
const result = await component.intercept(request.body.assetType, request.body.action, {
|
|
399
|
+
...(request.body.context ?? {}),
|
|
400
|
+
userIdentity: httpRequestContext.userIdentity,
|
|
401
|
+
nodeIdentity: httpRequestContext.nodeIdentity
|
|
402
|
+
}, request.body.data);
|
|
403
|
+
return {
|
|
404
|
+
body: result
|
|
409
405
|
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The source used when communicating about these routes.
|
|
410
|
+
*/
|
|
411
|
+
const ROUTES_SOURCE$1 = "policyNegotiationAdminPointRoutes";
|
|
412
|
+
/**
|
|
413
|
+
* The tag to associate with the routes.
|
|
414
|
+
*/
|
|
415
|
+
const pnapTags = [
|
|
416
|
+
{
|
|
417
|
+
name: "Policy Negotiation Administration Point",
|
|
418
|
+
description: "Endpoints for managing ODRL policies in the Policy Negotiation Administration Point"
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
/**
|
|
422
|
+
* The REST routes for the Policy Negotiation Administration Point.
|
|
423
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
424
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
425
|
+
* @returns The generated routes.
|
|
426
|
+
*/
|
|
427
|
+
function generateRestRoutesPolicyNegotiationAdminPoint(baseRouteName, componentName) {
|
|
410
428
|
const pnapGetRoute = {
|
|
411
429
|
operationId: "pnapGet",
|
|
412
430
|
summary: "Get a policy negotiation",
|
|
413
|
-
tag:
|
|
431
|
+
tag: pnapTags[0].name,
|
|
414
432
|
method: web.HttpMethod.GET,
|
|
415
433
|
path: `${baseRouteName}/pnap/:policyId`,
|
|
416
434
|
handler: async (httpRequestContext, request) => pnapGet(httpRequestContext, componentName, request),
|
|
@@ -449,7 +467,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
449
467
|
const pnapSetRoute = {
|
|
450
468
|
operationId: "pnapSet",
|
|
451
469
|
summary: "Set a policy negotiation",
|
|
452
|
-
tag:
|
|
470
|
+
tag: pnapTags[0].name,
|
|
453
471
|
method: web.HttpMethod.PUT,
|
|
454
472
|
path: `${baseRouteName}/pnap/:policyId`,
|
|
455
473
|
handler: async (httpRequestContext, request) => pnapSet(httpRequestContext, componentName, request),
|
|
@@ -477,7 +495,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
477
495
|
const pnapRemoveRoute = {
|
|
478
496
|
operationId: "pnapRemove",
|
|
479
497
|
summary: "Remove a policy negotiation",
|
|
480
|
-
tag:
|
|
498
|
+
tag: pnapTags[0].name,
|
|
481
499
|
method: web.HttpMethod.DELETE,
|
|
482
500
|
path: `${baseRouteName}/pnap/:policyId`,
|
|
483
501
|
handler: async (httpRequestContext, request) => pnapRemove(httpRequestContext, componentName, request),
|
|
@@ -497,7 +515,7 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
497
515
|
const pnapQueryRoute = {
|
|
498
516
|
operationId: "pnapQuery",
|
|
499
517
|
summary: "Query policy negotiations",
|
|
500
|
-
tag:
|
|
518
|
+
tag: pnapTags[0].name,
|
|
501
519
|
method: web.HttpMethod.GET,
|
|
502
520
|
path: `${baseRouteName}/pnap`,
|
|
503
521
|
handler: async (httpRequestContext, request) => pnapQuery(httpRequestContext, componentName, request),
|
|
@@ -538,130 +556,237 @@ function generateRestRoutesRightsManagement(baseRouteName, componentName) {
|
|
|
538
556
|
}
|
|
539
557
|
]
|
|
540
558
|
};
|
|
541
|
-
return [
|
|
542
|
-
papCreateRoute,
|
|
543
|
-
papUpdateRoute,
|
|
544
|
-
papRetrieveRoute,
|
|
545
|
-
papRemoveRoute,
|
|
546
|
-
papQueryRoute,
|
|
547
|
-
pepInterceptRoute,
|
|
548
|
-
papNegotiateRoute,
|
|
549
|
-
papNegotiationStateRoute,
|
|
550
|
-
pnpNegotiationCancelRoute,
|
|
551
|
-
pnapGetRoute,
|
|
552
|
-
pnapSetRoute,
|
|
553
|
-
pnapRemoveRoute,
|
|
554
|
-
pnapQueryRoute
|
|
555
|
-
];
|
|
559
|
+
return [pnapGetRoute, pnapSetRoute, pnapRemoveRoute, pnapQueryRoute];
|
|
556
560
|
}
|
|
557
561
|
/**
|
|
558
|
-
*
|
|
562
|
+
* PNAP: Get a policy negotiation.
|
|
559
563
|
* @param httpRequestContext The request context for the API.
|
|
560
564
|
* @param componentName The name of the component to use in the routes.
|
|
561
565
|
* @param request The request.
|
|
562
566
|
* @returns The response object with additional http response properties.
|
|
563
567
|
*/
|
|
564
|
-
async function
|
|
565
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
566
|
-
core.Guards.object(ROUTES_SOURCE, "request.
|
|
568
|
+
async function pnapGet(httpRequestContext, componentName, request) {
|
|
569
|
+
core.Guards.object(ROUTES_SOURCE$1, "request", request);
|
|
570
|
+
core.Guards.object(ROUTES_SOURCE$1, "request.pathParams", request.pathParams);
|
|
571
|
+
core.Guards.stringValue(ROUTES_SOURCE$1, "request.pathParams.policyId", request.pathParams.policyId);
|
|
567
572
|
const component = core.ComponentFactory.get(componentName);
|
|
568
|
-
const
|
|
569
|
-
const uid = await component.papCreate(policy);
|
|
573
|
+
const negotiation = await component.get(request.pathParams.policyId);
|
|
570
574
|
return {
|
|
571
|
-
|
|
572
|
-
headers: {
|
|
573
|
-
location: uid
|
|
574
|
-
}
|
|
575
|
+
body: negotiation
|
|
575
576
|
};
|
|
576
577
|
}
|
|
577
578
|
/**
|
|
578
|
-
*
|
|
579
|
+
* PNAP: Set a policy negotiation.
|
|
579
580
|
* @param httpRequestContext The request context for the API.
|
|
580
581
|
* @param componentName The name of the component to use in the routes.
|
|
581
582
|
* @param request The request.
|
|
582
583
|
* @returns The response object with additional http response properties.
|
|
583
584
|
*/
|
|
584
|
-
async function
|
|
585
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
586
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
587
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.
|
|
588
|
-
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
585
|
+
async function pnapSet(httpRequestContext, componentName, request) {
|
|
586
|
+
core.Guards.object(ROUTES_SOURCE$1, "request", request);
|
|
587
|
+
core.Guards.object(ROUTES_SOURCE$1, "request.pathParams", request.pathParams);
|
|
588
|
+
core.Guards.stringValue(ROUTES_SOURCE$1, "request.pathParams.policyId", request.pathParams.policyId);
|
|
589
|
+
core.Guards.object(ROUTES_SOURCE$1, "request.body", request.body);
|
|
589
590
|
const component = core.ComponentFactory.get(componentName);
|
|
590
|
-
await component.
|
|
591
|
+
await component.set(request.body);
|
|
591
592
|
return {
|
|
592
593
|
statusCode: web.HttpStatusCode.noContent
|
|
593
594
|
};
|
|
594
595
|
}
|
|
595
596
|
/**
|
|
596
|
-
*
|
|
597
|
-
* @param httpRequestContext The request context for the API.
|
|
598
|
-
* @param componentName The name of the component to use in the routes.
|
|
599
|
-
* @param request The request.
|
|
600
|
-
* @returns The response object with additional http response properties.
|
|
601
|
-
*/
|
|
602
|
-
async function papRetrieve(httpRequestContext, componentName, request) {
|
|
603
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
604
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
605
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
606
|
-
const component = core.ComponentFactory.get(componentName);
|
|
607
|
-
const policy = await component.papRetrieve(request.pathParams.id);
|
|
608
|
-
return {
|
|
609
|
-
body: policy
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* PAP: Remove a policy.
|
|
597
|
+
* PNAP: Remove a policy negotiation.
|
|
614
598
|
* @param httpRequestContext The request context for the API.
|
|
615
599
|
* @param componentName The name of the component to use in the routes.
|
|
616
600
|
* @param request The request.
|
|
617
601
|
* @returns The response object with additional http response properties.
|
|
618
602
|
*/
|
|
619
|
-
async function
|
|
620
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
621
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
622
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.
|
|
603
|
+
async function pnapRemove(httpRequestContext, componentName, request) {
|
|
604
|
+
core.Guards.object(ROUTES_SOURCE$1, "request", request);
|
|
605
|
+
core.Guards.object(ROUTES_SOURCE$1, "request.pathParams", request.pathParams);
|
|
606
|
+
core.Guards.stringValue(ROUTES_SOURCE$1, "request.pathParams.policyId", request.pathParams.policyId);
|
|
623
607
|
const component = core.ComponentFactory.get(componentName);
|
|
624
|
-
await component.
|
|
608
|
+
await component.remove(request.pathParams.policyId);
|
|
625
609
|
return {
|
|
626
610
|
statusCode: web.HttpStatusCode.noContent
|
|
627
611
|
};
|
|
628
612
|
}
|
|
629
613
|
/**
|
|
630
|
-
*
|
|
614
|
+
* PNAP: Query policy negotiations.
|
|
631
615
|
* @param httpRequestContext The request context for the API.
|
|
632
616
|
* @param componentName The name of the component to use in the routes.
|
|
633
617
|
* @param request The request.
|
|
634
618
|
* @returns The response object with additional http response properties.
|
|
635
619
|
*/
|
|
636
|
-
async function
|
|
637
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
620
|
+
async function pnapQuery(httpRequestContext, componentName, request) {
|
|
621
|
+
core.Guards.object(ROUTES_SOURCE$1, "request", request);
|
|
638
622
|
const component = core.ComponentFactory.get(componentName);
|
|
639
|
-
const result = await component.
|
|
623
|
+
const result = await component.query(request.query?.status, request.query?.cursor);
|
|
640
624
|
return {
|
|
641
625
|
body: {
|
|
642
|
-
|
|
643
|
-
|
|
626
|
+
items: result.items,
|
|
627
|
+
cursor: result.cursor
|
|
644
628
|
}
|
|
645
629
|
};
|
|
646
630
|
}
|
|
631
|
+
|
|
647
632
|
/**
|
|
648
|
-
*
|
|
649
|
-
* @param httpRequestContext The request context for the API.
|
|
650
|
-
* @param componentName The name of the component to use in the routes.
|
|
651
|
-
* @param request The request.
|
|
652
|
-
* @returns The response object with additional http response properties.
|
|
633
|
+
* The source used when communicating about these routes.
|
|
653
634
|
*/
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
635
|
+
const ROUTES_SOURCE = "policyNegotiationPointRoutes";
|
|
636
|
+
/**
|
|
637
|
+
* The tag to associate with the routes.
|
|
638
|
+
*/
|
|
639
|
+
const pnpTags = [
|
|
640
|
+
{
|
|
641
|
+
name: "Policy Negotiation Point",
|
|
642
|
+
description: "Endpoints for managing ODRL policies in the Policy Negotiation Point"
|
|
643
|
+
}
|
|
644
|
+
];
|
|
645
|
+
/**
|
|
646
|
+
* The REST routes for the Policy Negotiation Point.
|
|
647
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
648
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
649
|
+
* @returns The generated routes.
|
|
650
|
+
*/
|
|
651
|
+
function generateRestRoutesPolicyNegotiationPoint(baseRouteName, componentName) {
|
|
652
|
+
const pnpNegotiateRoute = {
|
|
653
|
+
operationId: "pnpNegotiate",
|
|
654
|
+
summary: "Negotiate a policy",
|
|
655
|
+
tag: pnpTags[0].name,
|
|
656
|
+
method: "POST",
|
|
657
|
+
path: `${baseRouteName}/pnp/negotiate`,
|
|
658
|
+
handler: async (httpRequestContext, request) => pnpNegotiate(httpRequestContext, componentName, request),
|
|
659
|
+
requestType: {
|
|
660
|
+
type: "IPnpNegotiateRequest",
|
|
661
|
+
examples: [
|
|
662
|
+
{
|
|
663
|
+
id: "pnpNegotiateRequestExample",
|
|
664
|
+
request: {
|
|
665
|
+
body: {
|
|
666
|
+
assetType: "document",
|
|
667
|
+
action: "view",
|
|
668
|
+
context: {
|
|
669
|
+
nodeIdentity: "urn:example:node:1"
|
|
670
|
+
},
|
|
671
|
+
proof: {
|
|
672
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
673
|
+
type: "DataIntegrityProof",
|
|
674
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
675
|
+
proofPurpose: "assertionMethod",
|
|
676
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
677
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
]
|
|
683
|
+
},
|
|
684
|
+
responseType: [
|
|
685
|
+
{
|
|
686
|
+
type: "IPnpNegotiateResponse",
|
|
687
|
+
examples: [
|
|
688
|
+
{
|
|
689
|
+
id: "IPnpNegotiateResponseExample",
|
|
690
|
+
response: {
|
|
691
|
+
body: {
|
|
692
|
+
id: "policy-1",
|
|
693
|
+
status: "approved"
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
],
|
|
700
|
+
skipAuth: true
|
|
701
|
+
};
|
|
702
|
+
const papNegotiationStateRoute = {
|
|
703
|
+
operationId: "pnpNegotiationState",
|
|
704
|
+
summary: "Get the state of a policy",
|
|
705
|
+
tag: pnpTags[0].name,
|
|
706
|
+
method: "POST",
|
|
707
|
+
path: `${baseRouteName}/pnp/:policyId`,
|
|
708
|
+
handler: async (httpRequestContext, request) => pnpNegotiationState(httpRequestContext, componentName, request),
|
|
709
|
+
requestType: {
|
|
710
|
+
type: "IPnpNegotiationStateRequest",
|
|
711
|
+
examples: [
|
|
712
|
+
{
|
|
713
|
+
id: "pnpNegotiationStateRequestExample",
|
|
714
|
+
request: {
|
|
715
|
+
pathParams: {
|
|
716
|
+
policyId: "policy-1"
|
|
717
|
+
},
|
|
718
|
+
body: {
|
|
719
|
+
nodeIdentity: "urn:example:node:1",
|
|
720
|
+
proof: {
|
|
721
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
722
|
+
type: "DataIntegrityProof",
|
|
723
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
724
|
+
proofPurpose: "assertionMethod",
|
|
725
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
726
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
]
|
|
732
|
+
},
|
|
733
|
+
responseType: [
|
|
734
|
+
{
|
|
735
|
+
type: "IPnpNegotiationStateResponse",
|
|
736
|
+
examples: [
|
|
737
|
+
{
|
|
738
|
+
id: "IPnpNegotiationStateResponseExample",
|
|
739
|
+
response: {
|
|
740
|
+
body: {
|
|
741
|
+
id: "policy-1",
|
|
742
|
+
status: "approved"
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
]
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
skipAuth: true
|
|
750
|
+
};
|
|
751
|
+
const pnpNegotiationCancelRoute = {
|
|
752
|
+
operationId: "pnpCancel",
|
|
753
|
+
summary: "Cancel a policy negotiation",
|
|
754
|
+
tag: pnpTags[0].name,
|
|
755
|
+
method: "DELETE",
|
|
756
|
+
path: `${baseRouteName}/pnp/:policyId`,
|
|
757
|
+
handler: async (httpRequestContext, request) => pnpNegotiationCancel(httpRequestContext, componentName, request),
|
|
758
|
+
requestType: {
|
|
759
|
+
type: "IPnpNegotiationCancelRequest",
|
|
760
|
+
examples: [
|
|
761
|
+
{
|
|
762
|
+
id: "pnpNegotiationCancelRequestExample",
|
|
763
|
+
request: {
|
|
764
|
+
pathParams: {
|
|
765
|
+
policyId: "policy-1"
|
|
766
|
+
},
|
|
767
|
+
body: {
|
|
768
|
+
nodeIdentity: "urn:example:node:1",
|
|
769
|
+
proof: {
|
|
770
|
+
created: "2024-08-22T11:56:56.272Z",
|
|
771
|
+
type: "DataIntegrityProof",
|
|
772
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
773
|
+
proofPurpose: "assertionMethod",
|
|
774
|
+
proofValue: "z3Vcuh2BP9ShC4UEJ3yRZgcTJ6gmRtydDrh6AmY1zEciQqEWTvXfBZNxxjTzdJjT44cmn9VDWbBHqxFsX9fjsfXzK",
|
|
775
|
+
verificationMethod: "did:entity-storage:0x6363636363636363636363636363636363636363636363636363636363636363#assertion"
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
]
|
|
781
|
+
},
|
|
782
|
+
responseType: [
|
|
783
|
+
{
|
|
784
|
+
type: "INoContentResponse"
|
|
785
|
+
}
|
|
786
|
+
],
|
|
787
|
+
skipAuth: true
|
|
664
788
|
};
|
|
789
|
+
return [pnpNegotiateRoute, papNegotiationStateRoute, pnpNegotiationCancelRoute];
|
|
665
790
|
}
|
|
666
791
|
/**
|
|
667
792
|
* PNP: Negotiate.
|
|
@@ -673,7 +798,7 @@ async function pepIntercept(httpRequestContext, componentName, request) {
|
|
|
673
798
|
async function pnpNegotiate(httpRequestContext, componentName, request) {
|
|
674
799
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
675
800
|
const component = core.ComponentFactory.get(componentName);
|
|
676
|
-
const result = await component.
|
|
801
|
+
const result = await component.negotiate(request.body.assetType, request.body.action, request.body.resourceId, request.body.context, request.body.requesterInformation, request.body.proof);
|
|
677
802
|
return {
|
|
678
803
|
body: result
|
|
679
804
|
};
|
|
@@ -689,7 +814,7 @@ async function pnpNegotiationState(httpRequestContext, componentName, request) {
|
|
|
689
814
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
690
815
|
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
691
816
|
const component = core.ComponentFactory.get(componentName);
|
|
692
|
-
const result = await component.
|
|
817
|
+
const result = await component.negotiationState(request.pathParams.policyId, request.body.nodeIdentity, request.body.proof);
|
|
693
818
|
return {
|
|
694
819
|
body: result
|
|
695
820
|
};
|
|
@@ -705,372 +830,61 @@ async function pnpNegotiationCancel(httpRequestContext, componentName, request)
|
|
|
705
830
|
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
706
831
|
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
707
832
|
const component = core.ComponentFactory.get(componentName);
|
|
708
|
-
await component.
|
|
709
|
-
return {
|
|
710
|
-
statusCode: web.HttpStatusCode.noContent
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* PNAP: Get a policy negotiation.
|
|
715
|
-
* @param httpRequestContext The request context for the API.
|
|
716
|
-
* @param componentName The name of the component to use in the routes.
|
|
717
|
-
* @param request The request.
|
|
718
|
-
* @returns The response object with additional http response properties.
|
|
719
|
-
*/
|
|
720
|
-
async function pnapGet(httpRequestContext, componentName, request) {
|
|
721
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
722
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
723
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
724
|
-
const component = core.ComponentFactory.get(componentName);
|
|
725
|
-
const negotiation = await component.pnapGet(request.pathParams.policyId);
|
|
726
|
-
return {
|
|
727
|
-
body: negotiation
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* PNAP: Set a policy negotiation.
|
|
732
|
-
* @param httpRequestContext The request context for the API.
|
|
733
|
-
* @param componentName The name of the component to use in the routes.
|
|
734
|
-
* @param request The request.
|
|
735
|
-
* @returns The response object with additional http response properties.
|
|
736
|
-
*/
|
|
737
|
-
async function pnapSet(httpRequestContext, componentName, request) {
|
|
738
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
739
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
740
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
741
|
-
core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
742
|
-
const component = core.ComponentFactory.get(componentName);
|
|
743
|
-
await component.pnapSet(request.body);
|
|
744
|
-
return {
|
|
745
|
-
statusCode: web.HttpStatusCode.noContent
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* PNAP: Remove a policy negotiation.
|
|
750
|
-
* @param httpRequestContext The request context for the API.
|
|
751
|
-
* @param componentName The name of the component to use in the routes.
|
|
752
|
-
* @param request The request.
|
|
753
|
-
* @returns The response object with additional http response properties.
|
|
754
|
-
*/
|
|
755
|
-
async function pnapRemove(httpRequestContext, componentName, request) {
|
|
756
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
757
|
-
core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
758
|
-
core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.policyId", request.pathParams.policyId);
|
|
759
|
-
const component = core.ComponentFactory.get(componentName);
|
|
760
|
-
await component.pnapRemove(request.pathParams.policyId);
|
|
833
|
+
await component.negotiationCancel(request.pathParams.policyId, request.body.nodeIdentity, request.body.proof);
|
|
761
834
|
return {
|
|
762
835
|
statusCode: web.HttpStatusCode.noContent
|
|
763
836
|
};
|
|
764
837
|
}
|
|
765
|
-
/**
|
|
766
|
-
* PNAP: Query policy negotiations.
|
|
767
|
-
* @param httpRequestContext The request context for the API.
|
|
768
|
-
* @param componentName The name of the component to use in the routes.
|
|
769
|
-
* @param request The request.
|
|
770
|
-
* @returns The response object with additional http response properties.
|
|
771
|
-
*/
|
|
772
|
-
async function pnapQuery(httpRequestContext, componentName, request) {
|
|
773
|
-
core.Guards.object(ROUTES_SOURCE, "request", request);
|
|
774
|
-
const component = core.ComponentFactory.get(componentName);
|
|
775
|
-
const result = await component.pnapQuery(request.query?.status, request.query?.cursor);
|
|
776
|
-
return {
|
|
777
|
-
body: {
|
|
778
|
-
items: result.items,
|
|
779
|
-
cursor: result.cursor
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// Copyright 2024 IOTA Stiftung.
|
|
785
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
786
|
-
/**
|
|
787
|
-
* Service for performing Rights Management operations.
|
|
788
|
-
* This is a unified service that provides access to all Rights Management components.
|
|
789
|
-
*/
|
|
790
|
-
class RightsManagementService {
|
|
791
|
-
/**
|
|
792
|
-
* Runtime name for the class.
|
|
793
|
-
*/
|
|
794
|
-
CLASS_NAME = "RightsManagementService";
|
|
795
|
-
/**
|
|
796
|
-
* The PAP component implementation.
|
|
797
|
-
* @internal
|
|
798
|
-
*/
|
|
799
|
-
_policyAdministrationPointComponent;
|
|
800
|
-
/**
|
|
801
|
-
* The PEP component implementation.
|
|
802
|
-
* @internal
|
|
803
|
-
*/
|
|
804
|
-
_policyEnforcementPointComponent;
|
|
805
|
-
/**
|
|
806
|
-
* The PNP component implementation.
|
|
807
|
-
* @internal
|
|
808
|
-
*/
|
|
809
|
-
_policyNegotiationPointComponent;
|
|
810
|
-
/**
|
|
811
|
-
* The PNAP component implementation.
|
|
812
|
-
* @internal
|
|
813
|
-
*/
|
|
814
|
-
_policyNegotiationAdminPointComponent;
|
|
815
|
-
/**
|
|
816
|
-
* Create a new instance of RightsManagementService.
|
|
817
|
-
* @param options The options for the service.
|
|
818
|
-
*/
|
|
819
|
-
constructor(options) {
|
|
820
|
-
this._policyAdministrationPointComponent =
|
|
821
|
-
core.ComponentFactory.get(options?.policyAdministrationPointComponentType ?? "policy-administration-point");
|
|
822
|
-
this._policyEnforcementPointComponent = core.ComponentFactory.get(options?.policyEnforcementPointComponentType ?? "policy-enforcement-point");
|
|
823
|
-
this._policyNegotiationPointComponent = core.ComponentFactory.get(options?.policyNegotiationPointComponentType ?? "policy-negotiation-point");
|
|
824
|
-
this._policyNegotiationAdminPointComponent =
|
|
825
|
-
core.ComponentFactory.get(options?.policyNegotiationAdminPointComponentType ?? "policy-negotiation-admin-point");
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* PAP: Create a new policy with auto-generated UID.
|
|
829
|
-
* @param policy The policy to create (uid will be auto-generated).
|
|
830
|
-
* @returns The UID of the created policy.
|
|
831
|
-
*/
|
|
832
|
-
async papCreate(policy) {
|
|
833
|
-
core.Guards.object(this.CLASS_NAME, "policy", policy);
|
|
834
|
-
try {
|
|
835
|
-
const result = await this._policyAdministrationPointComponent.create(policy);
|
|
836
|
-
return result;
|
|
837
|
-
}
|
|
838
|
-
catch (error) {
|
|
839
|
-
throw new core.GeneralError(this.CLASS_NAME, "papCreateFailed", undefined, error);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* PAP: Update an existing policy.
|
|
844
|
-
* @param policy The policy to update (must include uid).
|
|
845
|
-
* @returns Nothing.
|
|
846
|
-
*/
|
|
847
|
-
async papUpdate(policy) {
|
|
848
|
-
core.Guards.object(this.CLASS_NAME, "policy", policy);
|
|
849
|
-
try {
|
|
850
|
-
await this._policyAdministrationPointComponent.update(policy);
|
|
851
|
-
}
|
|
852
|
-
catch (error) {
|
|
853
|
-
throw new core.GeneralError(this.CLASS_NAME, "papUpdateFailed", undefined, error);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* PAP: Retrieve a policy.
|
|
858
|
-
* @param policyId The id of the policy to retrieve.
|
|
859
|
-
* @returns The policy.
|
|
860
|
-
*/
|
|
861
|
-
async papRetrieve(policyId) {
|
|
862
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
863
|
-
try {
|
|
864
|
-
const policy = await this._policyAdministrationPointComponent.retrieve(policyId);
|
|
865
|
-
return policy;
|
|
866
|
-
}
|
|
867
|
-
catch (error) {
|
|
868
|
-
throw new core.GeneralError(this.CLASS_NAME, "papRetrieveFailed", undefined, error);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* PAP: Remove a policy.
|
|
873
|
-
* @param policyId The id of the policy to remove.
|
|
874
|
-
* @returns Nothing.
|
|
875
|
-
*/
|
|
876
|
-
async papRemove(policyId) {
|
|
877
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
878
|
-
try {
|
|
879
|
-
await this._policyAdministrationPointComponent.remove(policyId);
|
|
880
|
-
}
|
|
881
|
-
catch (error) {
|
|
882
|
-
throw new core.GeneralError(this.CLASS_NAME, "papRemoveFailed", undefined, error);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* PAP: Query the policies using the specified conditions.
|
|
887
|
-
* @param conditions The conditions to use for the query.
|
|
888
|
-
* @param cursor The cursor to use for pagination.
|
|
889
|
-
* @param pageSize The number of results to return per page.
|
|
890
|
-
* @returns Cursor for next page of results and the policies matching the query.
|
|
891
|
-
*/
|
|
892
|
-
async papQuery(conditions, cursor, pageSize) {
|
|
893
|
-
if (!core.Is.empty(conditions)) {
|
|
894
|
-
core.Guards.object(this.CLASS_NAME, "conditions", conditions);
|
|
895
|
-
}
|
|
896
|
-
if (!core.Is.empty(cursor)) {
|
|
897
|
-
core.Guards.stringValue(this.CLASS_NAME, "cursor", cursor);
|
|
898
|
-
}
|
|
899
|
-
if (!core.Is.empty(pageSize)) {
|
|
900
|
-
core.Guards.integer(this.CLASS_NAME, "pageSize", pageSize);
|
|
901
|
-
}
|
|
902
|
-
try {
|
|
903
|
-
const result = await this._policyAdministrationPointComponent.query(conditions, cursor, pageSize);
|
|
904
|
-
return result;
|
|
905
|
-
}
|
|
906
|
-
catch (error) {
|
|
907
|
-
throw new core.GeneralError(this.CLASS_NAME, "papQueryFailed", undefined, error);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* PEP: Process the data using Policy Decision Point (PDP) and return the manipulated data.
|
|
912
|
-
* @param assetType The type of asset being processed.
|
|
913
|
-
* @param action The action being performed on the asset.
|
|
914
|
-
* @param context The context to use in the decision making.
|
|
915
|
-
* @param data The data to process.
|
|
916
|
-
* @returns The manipulated data with any policies applied.
|
|
917
|
-
*/
|
|
918
|
-
async pepIntercept(assetType, action, context, data) {
|
|
919
|
-
core.Guards.stringValue(this.CLASS_NAME, "assetType", assetType);
|
|
920
|
-
core.Guards.stringValue(this.CLASS_NAME, "action", action);
|
|
921
|
-
try {
|
|
922
|
-
const result = await this._policyEnforcementPointComponent.intercept(assetType, action, context, data);
|
|
923
|
-
return result;
|
|
924
|
-
}
|
|
925
|
-
catch (error) {
|
|
926
|
-
throw new core.GeneralError(this.CLASS_NAME, "pepInterceptFailed", undefined, error);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
/**
|
|
930
|
-
* PNP: Negotiates the creation of a policy for the requested resource.
|
|
931
|
-
* @param assetType The type of asset being processed.
|
|
932
|
-
* @param action The action being performed on the asset.
|
|
933
|
-
* @param resourceId The ID of the resource being requested, can be empty if asset type access requested.
|
|
934
|
-
* @param context The context from the requesting node.
|
|
935
|
-
* @param requesterInformation Information provided by the requester to determine if a policy can be created.
|
|
936
|
-
* @param proof The proof provided by the requester to support the policy creation.
|
|
937
|
-
* @returns The state of the policy.
|
|
938
|
-
*/
|
|
939
|
-
async pnpNegotiate(assetType, action, resourceId, context, requesterInformation, proof) {
|
|
940
|
-
core.Guards.stringValue(this.CLASS_NAME, "assetType", assetType);
|
|
941
|
-
core.Guards.stringValue(this.CLASS_NAME, "action", action);
|
|
942
|
-
core.Guards.stringValue(this.CLASS_NAME, "resourceId", resourceId);
|
|
943
|
-
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
944
|
-
try {
|
|
945
|
-
const result = await this._policyNegotiationPointComponent.negotiate(assetType, action, resourceId, context, requesterInformation, proof);
|
|
946
|
-
return result;
|
|
947
|
-
}
|
|
948
|
-
catch (error) {
|
|
949
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiateFailed", undefined, error);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* PNP: Retrieves the current state of a policy.
|
|
954
|
-
* @param policyId The ID of the policy to retrieve the state for.
|
|
955
|
-
* @param nodeIdentity The identity of the node requesting the state.
|
|
956
|
-
* @param proof The proof provided by the requester.
|
|
957
|
-
* @returns The current state of the policy.
|
|
958
|
-
*/
|
|
959
|
-
async pnpNegotiationState(policyId, nodeIdentity, proof) {
|
|
960
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
961
|
-
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
962
|
-
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
963
|
-
try {
|
|
964
|
-
const result = await this._policyNegotiationPointComponent.negotiationState(policyId, nodeIdentity, proof);
|
|
965
|
-
return result;
|
|
966
|
-
}
|
|
967
|
-
catch (error) {
|
|
968
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiationState", undefined, error);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* PNP: Cancels an ongoing negotiation for a resource.
|
|
973
|
-
* @param policyId The ID of the policy to cancel.
|
|
974
|
-
* @param nodeIdentity The identity of the node requesting the cancellation.
|
|
975
|
-
* @param proof The proof provided by the requester.
|
|
976
|
-
* @returns Nothing.
|
|
977
|
-
*/
|
|
978
|
-
async pnpNegotiationCancel(policyId, nodeIdentity, proof) {
|
|
979
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
980
|
-
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
981
|
-
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
982
|
-
try {
|
|
983
|
-
await this._policyNegotiationPointComponent.negotiationCancel(policyId, nodeIdentity, proof);
|
|
984
|
-
}
|
|
985
|
-
catch (error) {
|
|
986
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnpNegotiationCancelFailed", undefined, error);
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
* PNAP: Retrieves a policy negotiation.
|
|
991
|
-
* @param policyId The ID of the policy to retrieve the negotiation for.
|
|
992
|
-
* @returns The policy negotiation.
|
|
993
|
-
*/
|
|
994
|
-
async pnapGet(policyId) {
|
|
995
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
996
|
-
try {
|
|
997
|
-
return this._policyNegotiationAdminPointComponent.get(policyId);
|
|
998
|
-
}
|
|
999
|
-
catch (error) {
|
|
1000
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnapGetFailed", undefined, error);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* PNAP: Sets a policy negotiation.
|
|
1005
|
-
* @param negotiation The updated policy negotiation.
|
|
1006
|
-
* @returns Nothing.
|
|
1007
|
-
*/
|
|
1008
|
-
async pnapSet(negotiation) {
|
|
1009
|
-
core.Guards.object(this.CLASS_NAME, "negotiation", negotiation);
|
|
1010
|
-
try {
|
|
1011
|
-
return this._policyNegotiationAdminPointComponent.set(negotiation);
|
|
1012
|
-
}
|
|
1013
|
-
catch (error) {
|
|
1014
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnapSetFailed", undefined, error);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* PNAP: Removes a policy negotiation record.
|
|
1019
|
-
* @param policyId The ID of the policy negotiation to remove.
|
|
1020
|
-
* @returns Nothing.
|
|
1021
|
-
*/
|
|
1022
|
-
async pnapRemove(policyId) {
|
|
1023
|
-
core.Guards.stringValue(this.CLASS_NAME, "policyId", policyId);
|
|
1024
|
-
try {
|
|
1025
|
-
await this._policyNegotiationAdminPointComponent.remove(policyId);
|
|
1026
|
-
}
|
|
1027
|
-
catch (error) {
|
|
1028
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnapRemoveFailed", undefined, error);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* PNAP: Get a list of the negotiations.
|
|
1033
|
-
* @param status The state of the negotiations to retrieve.
|
|
1034
|
-
* @param cursor The cursor to use for pagination.
|
|
1035
|
-
* @returns A list of negotiations and cursor if there are more entries.
|
|
1036
|
-
*/
|
|
1037
|
-
async pnapQuery(status, cursor) {
|
|
1038
|
-
try {
|
|
1039
|
-
const result = await this._policyNegotiationAdminPointComponent.query(status, cursor);
|
|
1040
|
-
return result;
|
|
1041
|
-
}
|
|
1042
|
-
catch (error) {
|
|
1043
|
-
throw new core.GeneralError(this.CLASS_NAME, "pnapQueryFailed", undefined, error);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
838
|
|
|
1048
839
|
/**
|
|
1049
840
|
* Entry points for the REST API.
|
|
1050
841
|
*/
|
|
1051
842
|
const restEntryPoints = [
|
|
1052
843
|
{
|
|
1053
|
-
name: "
|
|
844
|
+
name: "policy-administration-point",
|
|
845
|
+
defaultBaseRoute: "rights-management",
|
|
846
|
+
tags: papTags,
|
|
847
|
+
generateRoutes: generateRestRoutesPolicyAdministrationPoint
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
name: "policy-enforcement-point",
|
|
851
|
+
defaultBaseRoute: "rights-management",
|
|
852
|
+
tags: pepTags,
|
|
853
|
+
generateRoutes: generateRestRoutesPolicyEnforcementPoint
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
name: "policy-negotiation-point",
|
|
857
|
+
defaultBaseRoute: "rights-management",
|
|
858
|
+
tags: pnpTags,
|
|
859
|
+
generateRoutes: generateRestRoutesPolicyNegotiationPoint
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
name: "policy-negotiation-admin-point",
|
|
1054
863
|
defaultBaseRoute: "rights-management",
|
|
1055
|
-
tags,
|
|
1056
|
-
generateRoutes:
|
|
864
|
+
tags: pnapTags,
|
|
865
|
+
generateRoutes: generateRestRoutesPolicyNegotiationAdminPoint
|
|
1057
866
|
}
|
|
1058
867
|
];
|
|
1059
868
|
|
|
1060
|
-
exports.
|
|
1061
|
-
exports.
|
|
869
|
+
exports.generateRestRoutesPolicyAdministrationPoint = generateRestRoutesPolicyAdministrationPoint;
|
|
870
|
+
exports.generateRestRoutesPolicyEnforcementPoint = generateRestRoutesPolicyEnforcementPoint;
|
|
871
|
+
exports.generateRestRoutesPolicyNegotiationAdminPoint = generateRestRoutesPolicyNegotiationAdminPoint;
|
|
872
|
+
exports.generateRestRoutesPolicyNegotiationPoint = generateRestRoutesPolicyNegotiationPoint;
|
|
1062
873
|
exports.papCreate = papCreate;
|
|
874
|
+
exports.papGet = papGet;
|
|
1063
875
|
exports.papQuery = papQuery;
|
|
1064
876
|
exports.papRemove = papRemove;
|
|
1065
|
-
exports.
|
|
877
|
+
exports.papTags = papTags;
|
|
1066
878
|
exports.papUpdate = papUpdate;
|
|
1067
879
|
exports.pepIntercept = pepIntercept;
|
|
880
|
+
exports.pepTags = pepTags;
|
|
1068
881
|
exports.pnapGet = pnapGet;
|
|
1069
882
|
exports.pnapQuery = pnapQuery;
|
|
1070
883
|
exports.pnapRemove = pnapRemove;
|
|
1071
884
|
exports.pnapSet = pnapSet;
|
|
885
|
+
exports.pnapTags = pnapTags;
|
|
1072
886
|
exports.pnpNegotiate = pnpNegotiate;
|
|
1073
887
|
exports.pnpNegotiationCancel = pnpNegotiationCancel;
|
|
1074
888
|
exports.pnpNegotiationState = pnpNegotiationState;
|
|
889
|
+
exports.pnpTags = pnpTags;
|
|
1075
890
|
exports.restEntryPoints = restEntryPoints;
|
|
1076
|
-
exports.tags = tags;
|