@xen-orchestra/rest-api 0.25.0 → 0.26.0
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/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import tsoaToXoErrorHandler from './middlewares/tsoa-to-xo-error.middleware.mjs'
|
|
|
5
5
|
import { RegisterRoutes } from './open-api/routes/routes.js';
|
|
6
6
|
import { setupContainer } from './ioc/ioc.mjs';
|
|
7
7
|
import { setupApiContext } from './middlewares/authentication.middleware.mjs';
|
|
8
|
+
import { logMiddleware } from './middlewares/log.middleware.mjs';
|
|
8
9
|
// Avoid using "import from" to import a json file as this requires assert/with and will break compatibility with recent node versions
|
|
9
10
|
// https://github.com/nodejs/node/issues/51622
|
|
10
11
|
const require = createRequire(import.meta.url);
|
|
@@ -34,6 +35,7 @@ const SWAGGER_UI_OPTIONS = {
|
|
|
34
35
|
export default function setupRestApi(express, xoApp) {
|
|
35
36
|
setupContainer(xoApp);
|
|
36
37
|
express.use(BASE_URL, setupApiContext(xoApp));
|
|
38
|
+
express.use(BASE_URL, logMiddleware);
|
|
37
39
|
RegisterRoutes(express);
|
|
38
40
|
express.get(`${BASE_URL}/docs/swagger.json`, (_req, res) => {
|
|
39
41
|
res.setHeader('Content-Type', 'application/json');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createLogger } from '@xen-orchestra/log';
|
|
2
|
+
const log = createLogger('xo:rest-api');
|
|
3
|
+
export function logMiddleware(req, res, next) {
|
|
4
|
+
const start = Date.now();
|
|
5
|
+
res.on('finish', () => {
|
|
6
|
+
const duration = Date.now() - start;
|
|
7
|
+
const { method, originalUrl } = req;
|
|
8
|
+
const { statusCode } = res;
|
|
9
|
+
log.debug(`[${new Date().toISOString()}] ${method} ${originalUrl} ${statusCode} ${duration}ms`);
|
|
10
|
+
});
|
|
11
|
+
next();
|
|
12
|
+
}
|
|
@@ -4747,6 +4747,34 @@ export function RegisterRoutes(app) {
|
|
|
4747
4747
|
}
|
|
4748
4748
|
});
|
|
4749
4749
|
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
4750
|
+
const argsSrController_scanSr = {
|
|
4751
|
+
id: { "in": "path", "name": "id", "required": true, "dataType": "string" },
|
|
4752
|
+
sync: { "in": "query", "name": "sync", "dataType": "boolean" },
|
|
4753
|
+
};
|
|
4754
|
+
app.post('/rest/v0/srs/:id/actions/scan', authenticateMiddleware([{ "*": [] }]), ...(fetchMiddlewares(SrController)), ...(fetchMiddlewares(SrController.prototype.scanSr)), async function SrController_scanSr(request, response, next) {
|
|
4755
|
+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
4756
|
+
let validatedArgs = [];
|
|
4757
|
+
try {
|
|
4758
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsSrController_scanSr, request, response });
|
|
4759
|
+
const container = typeof iocContainer === 'function' ? iocContainer(request) : iocContainer;
|
|
4760
|
+
const controller = await container.get(SrController);
|
|
4761
|
+
if (typeof controller['setStatus'] === 'function') {
|
|
4762
|
+
controller.setStatus(undefined);
|
|
4763
|
+
}
|
|
4764
|
+
await templateService.apiHandler({
|
|
4765
|
+
methodName: 'scanSr',
|
|
4766
|
+
controller,
|
|
4767
|
+
response,
|
|
4768
|
+
next,
|
|
4769
|
+
validatedArgs,
|
|
4770
|
+
successStatus: 202,
|
|
4771
|
+
});
|
|
4772
|
+
}
|
|
4773
|
+
catch (err) {
|
|
4774
|
+
return next(err);
|
|
4775
|
+
}
|
|
4776
|
+
});
|
|
4777
|
+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
4750
4778
|
const argsSmController_getSrs = {
|
|
4751
4779
|
req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
|
|
4752
4780
|
fields: { "in": "query", "name": "fields", "dataType": "string" },
|
|
@@ -21,7 +21,7 @@ import { vdiId } from '../open-api/oa-examples/vdi.oa-example.mjs';
|
|
|
21
21
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
22
22
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
23
23
|
import { messageIds, partialMessages } from '../open-api/oa-examples/message.oa-example.mjs';
|
|
24
|
-
import { taskIds, partialTasks } from '../open-api/oa-examples/task.oa-example.mjs';
|
|
24
|
+
import { taskIds, partialTasks, taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
|
|
25
25
|
let SrController = class SrController extends XapiXoController {
|
|
26
26
|
#alarmService;
|
|
27
27
|
constructor(restApi, alarmService) {
|
|
@@ -132,6 +132,24 @@ let SrController = class SrController extends XapiXoController {
|
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* @example id "b61a5c92-700e-4966-a13b-00633f03eea8"
|
|
137
|
+
*/
|
|
138
|
+
async scanSr(id, sync) {
|
|
139
|
+
const srId = id;
|
|
140
|
+
const action = async () => {
|
|
141
|
+
const sr = this.getXapiObject(srId);
|
|
142
|
+
await sr.$xapi.callAsync('SR.scan', sr.$ref);
|
|
143
|
+
};
|
|
144
|
+
return this.createAction(action, {
|
|
145
|
+
sync,
|
|
146
|
+
statusCode: noContentResp.status,
|
|
147
|
+
taskProperties: {
|
|
148
|
+
name: 'SR scan',
|
|
149
|
+
objectId: srId,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
135
153
|
};
|
|
136
154
|
__decorate([
|
|
137
155
|
Example(srIds),
|
|
@@ -214,6 +232,7 @@ __decorate([
|
|
|
214
232
|
__param(1, Path())
|
|
215
233
|
], SrController.prototype, "deleteSrTag", null);
|
|
216
234
|
__decorate([
|
|
235
|
+
Example(taskLocation),
|
|
217
236
|
Post('{id}/actions/reclaim_space'),
|
|
218
237
|
SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description),
|
|
219
238
|
Response(noContentResp.status, noContentResp.description),
|
|
@@ -223,6 +242,17 @@ __decorate([
|
|
|
223
242
|
__param(0, Path()),
|
|
224
243
|
__param(1, Query())
|
|
225
244
|
], SrController.prototype, "reclaimSpaceSr", null);
|
|
245
|
+
__decorate([
|
|
246
|
+
Example(taskLocation),
|
|
247
|
+
Post('{id}/actions/scan'),
|
|
248
|
+
SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description),
|
|
249
|
+
Response(noContentResp.status, noContentResp.description),
|
|
250
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
251
|
+
Response(invalidParametersResp.status, invalidParametersResp.description),
|
|
252
|
+
Response(internalServerErrorResp.status, internalServerErrorResp.description),
|
|
253
|
+
__param(0, Path()),
|
|
254
|
+
__param(1, Query())
|
|
255
|
+
], SrController.prototype, "scanSr", null);
|
|
226
256
|
SrController = __decorate([
|
|
227
257
|
Route('srs'),
|
|
228
258
|
Security('*'),
|
|
@@ -12346,7 +12346,7 @@
|
|
|
12346
12346
|
},
|
|
12347
12347
|
"info": {
|
|
12348
12348
|
"title": "@xen-orchestra/rest-api",
|
|
12349
|
-
"version": "0.
|
|
12349
|
+
"version": "0.26.0",
|
|
12350
12350
|
"description": "REST API to manage your XOA",
|
|
12351
12351
|
"license": {
|
|
12352
12352
|
"name": "AGPL-3.0-or-later"
|
|
@@ -23024,6 +23024,82 @@
|
|
|
23024
23024
|
"application/json": {
|
|
23025
23025
|
"schema": {
|
|
23026
23026
|
"$ref": "#/components/schemas/CreateActionReturnType_void_"
|
|
23027
|
+
},
|
|
23028
|
+
"examples": {
|
|
23029
|
+
"Example 1": {
|
|
23030
|
+
"value": {
|
|
23031
|
+
"taskId": "0m7kl0j9l"
|
|
23032
|
+
}
|
|
23033
|
+
}
|
|
23034
|
+
}
|
|
23035
|
+
}
|
|
23036
|
+
}
|
|
23037
|
+
},
|
|
23038
|
+
"204": {
|
|
23039
|
+
"description": "No content"
|
|
23040
|
+
},
|
|
23041
|
+
"400": {
|
|
23042
|
+
"description": "Bad request"
|
|
23043
|
+
},
|
|
23044
|
+
"401": {
|
|
23045
|
+
"description": "Authentication required"
|
|
23046
|
+
},
|
|
23047
|
+
"404": {
|
|
23048
|
+
"description": "Resource not found"
|
|
23049
|
+
},
|
|
23050
|
+
"422": {
|
|
23051
|
+
"description": "Invalid parameters"
|
|
23052
|
+
},
|
|
23053
|
+
"500": {
|
|
23054
|
+
"description": "Internal server error, XenServer/XCP-ng error"
|
|
23055
|
+
}
|
|
23056
|
+
},
|
|
23057
|
+
"tags": [
|
|
23058
|
+
"srs"
|
|
23059
|
+
],
|
|
23060
|
+
"security": [
|
|
23061
|
+
{
|
|
23062
|
+
"*": []
|
|
23063
|
+
}
|
|
23064
|
+
],
|
|
23065
|
+
"parameters": [
|
|
23066
|
+
{
|
|
23067
|
+
"in": "path",
|
|
23068
|
+
"name": "id",
|
|
23069
|
+
"required": true,
|
|
23070
|
+
"schema": {
|
|
23071
|
+
"type": "string"
|
|
23072
|
+
},
|
|
23073
|
+
"example": "b61a5c92-700e-4966-a13b-00633f03eea8"
|
|
23074
|
+
},
|
|
23075
|
+
{
|
|
23076
|
+
"in": "query",
|
|
23077
|
+
"name": "sync",
|
|
23078
|
+
"required": false,
|
|
23079
|
+
"schema": {
|
|
23080
|
+
"type": "boolean"
|
|
23081
|
+
}
|
|
23082
|
+
}
|
|
23083
|
+
]
|
|
23084
|
+
}
|
|
23085
|
+
},
|
|
23086
|
+
"/srs/{id}/actions/scan": {
|
|
23087
|
+
"post": {
|
|
23088
|
+
"operationId": "ScanSr",
|
|
23089
|
+
"responses": {
|
|
23090
|
+
"202": {
|
|
23091
|
+
"description": "Action executed asynchronously",
|
|
23092
|
+
"content": {
|
|
23093
|
+
"application/json": {
|
|
23094
|
+
"schema": {
|
|
23095
|
+
"$ref": "#/components/schemas/CreateActionReturnType_void_"
|
|
23096
|
+
},
|
|
23097
|
+
"examples": {
|
|
23098
|
+
"Example 1": {
|
|
23099
|
+
"value": {
|
|
23100
|
+
"taskId": "0m7kl0j9l"
|
|
23101
|
+
}
|
|
23102
|
+
}
|
|
23027
23103
|
}
|
|
23028
23104
|
}
|
|
23029
23105
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
7
7
|
"name": "@xen-orchestra/rest-api",
|
|
8
8
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/rest-api",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.26.0",
|
|
10
10
|
"description": "REST API to manage your XOA",
|
|
11
11
|
"license": "AGPL-3.0-or-later",
|
|
12
12
|
"private": false,
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"@vates/async-each": "^1.0.1",
|
|
37
37
|
"@vates/task": "^0.6.1",
|
|
38
38
|
"@vates/types": "^1.20.0",
|
|
39
|
-
"@xen-orchestra/backups": "^0.69.
|
|
39
|
+
"@xen-orchestra/backups": "^0.69.1",
|
|
40
40
|
"@xen-orchestra/log": "^0.7.1",
|
|
41
41
|
"@xen-orchestra/xapi": "^8.6.6",
|
|
42
|
-
"complex-matcher": "^1.
|
|
42
|
+
"complex-matcher": "^1.1.0",
|
|
43
43
|
"golike-defer": "^0.5.1",
|
|
44
44
|
"inversify": "^6.2.2",
|
|
45
45
|
"inversify-binding-decorators": "^4.0.0",
|