diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 26e734d18..dbad2afaf 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -9,6 +9,7 @@ - [REST API] Add `/groups` collection [Forum#70500](https://xcp-ng.org/forum/post/70500) - [REST API] Add `/groups/:id/users` and `/users/:id/groups` collection [Forum#70500](https://xcp-ng.org/forum/post/70500) +- [REST API] Expose messages associated to XAPI objects at `/:collection/:object/messages` ### Bug fixes diff --git a/packages/xo-server/src/xo-mixins/rest-api.mjs b/packages/xo-server/src/xo-mixins/rest-api.mjs index 6d4c17f4f..dae329b52 100644 --- a/packages/xo-server/src/xo-mixins/rest-api.mjs +++ b/packages/xo-server/src/xo-mixins/rest-api.mjs @@ -182,6 +182,7 @@ export default class RestApi { { const types = [ 'host', + 'message', 'network', 'pool', 'SR', @@ -208,13 +209,30 @@ export default class RestApi { limit, }) } + async function messages(req, res) { + const { + object: { id }, + query, + } = req + await sendObjects( + app.getObjects({ + filter: every(_ => _.type === 'message' && _.$object === id, handleOptionalUserFilter(query.filter)), + limit: ifDef(query.limit, Number), + }), + req, + res, + '/messages' + ) + } for (const type of types) { const id = type.toLocaleLowerCase() + 's' - collections[id] = { getObject, getObjects, isCorrectType: _ => _.type === type, type } + collections[id] = { getObject, getObjects, routes: { messages }, isCorrectType: _ => _.type === type, type } } collections.hosts.routes = { + ...collections.hosts.routes, + async 'audit.txt'(req, res) { const host = req.xapiObject @@ -238,6 +256,8 @@ export default class RestApi { } collections.pools.routes = { + ...collections.pools.routes, + async missing_patches(req, res) { await app.checkFeatureAuthorization('LIST_MISSING_PATCHES')