@xen-orchestra/rest-api 0.12.0 → 0.13.1
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/groups/group.controller.mjs +82 -3
- package/dist/groups/group.type.mjs +1 -0
- package/dist/hosts/host.service.mjs +4 -4
- package/dist/middlewares/generic-error-handler.middleware.mjs +4 -3
- package/dist/open-api/common/response.common.mjs +4 -0
- package/dist/open-api/oa-examples/group.oa-example.mjs +3 -0
- package/dist/open-api/routes/routes.js +334 -16
- package/dist/pools/pool.service.mjs +1 -1
- package/dist/users/user.controller.mjs +44 -2
- package/dist/users/user.type.mjs +1 -0
- package/dist/vbds/vbd.controller.mjs +34 -2
- package/dist/vifs/vif.controller.mjs +34 -2
- package/dist/vm-controller/vm-controller.controller.mjs +34 -2
- package/dist/vm-snapshots/vm-snapshot.controller.mjs +34 -2
- package/dist/vms/vm.controller.mjs +34 -2
- package/open-api/spec/swagger.json +968 -198
- package/package.json +1 -1
|
@@ -7,10 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { Delete, Example, Get, Path, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
|
|
10
|
+
import { Body, Delete, Example, Get, Middlewares, Patch, Path, Post, Put, Query, Request, Response, Route, Security, SuccessResponse, Tags, } from 'tsoa';
|
|
11
|
+
import { json } from 'express';
|
|
11
12
|
import { provide } from 'inversify-binding-decorators';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { forbiddenOperation } from 'xo-common/api-errors.js';
|
|
14
|
+
import { createdResp, forbiddenOperationResp, invalidParameters, noContentResp, notFoundResp, resourceAlreadyExists, unauthorizedResp, } from '../open-api/common/response.common.mjs';
|
|
15
|
+
import { group, groupId, groupIds, partialGroups } from '../open-api/oa-examples/group.oa-example.mjs';
|
|
14
16
|
import { XoController } from '../abstract-classes/xo-controller.mjs';
|
|
15
17
|
let GroupController = class GroupController extends XoController {
|
|
16
18
|
// --- abstract methods
|
|
@@ -34,6 +36,26 @@ let GroupController = class GroupController extends XoController {
|
|
|
34
36
|
getGroup(id) {
|
|
35
37
|
return this.getObject(id);
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @example id "c98395a7-26d8-4e09-b055-d5f0f4a98312"
|
|
41
|
+
* @example body { "name": "new group name" }
|
|
42
|
+
*/
|
|
43
|
+
async updateGroup(id, body) {
|
|
44
|
+
const group = await this.getObject(id);
|
|
45
|
+
if (group.provider !== undefined) {
|
|
46
|
+
throw forbiddenOperation('update group', 'synchronized group');
|
|
47
|
+
}
|
|
48
|
+
await this.restApi.xoApp.updateGroup(group.id, body);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @example body {
|
|
52
|
+
* "name": "new group"
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
async createGroup(body) {
|
|
56
|
+
const group = await this.restApi.xoApp.createGroup(body);
|
|
57
|
+
return { id: group.id };
|
|
58
|
+
}
|
|
37
59
|
/**
|
|
38
60
|
* @example id "7d98fee4-3357-41a7-ac3f-9124212badb7"
|
|
39
61
|
*/
|
|
@@ -41,6 +63,28 @@ let GroupController = class GroupController extends XoController {
|
|
|
41
63
|
const groupId = id;
|
|
42
64
|
await this.restApi.xoApp.deleteGroup(groupId);
|
|
43
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @example id "c98395a7-26d8-4e09-b055-d5f0f4a98312"
|
|
68
|
+
* @example userId "722d17b9-699b-49d2-8193-be1ac573d3de"
|
|
69
|
+
*/
|
|
70
|
+
async removeUserFromGroup(id, userId) {
|
|
71
|
+
const group = await this.getObject(id);
|
|
72
|
+
if (group.provider !== undefined) {
|
|
73
|
+
throw forbiddenOperation('remove user from group', 'synchronized group');
|
|
74
|
+
}
|
|
75
|
+
await this.restApi.xoApp.removeUserFromGroup(userId, group.id);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @example id "6c81b5e1-afc1-43ea-8f8d-939ceb5f3f90"
|
|
79
|
+
* @example userId "722d17b9-699b-49d2-8193-be1ac573d3de"
|
|
80
|
+
*/
|
|
81
|
+
async addUserToGroup(id, userId) {
|
|
82
|
+
const group = await this.getObject(id);
|
|
83
|
+
if (group.provider !== undefined) {
|
|
84
|
+
throw forbiddenOperation('add user to group', 'synchronized group');
|
|
85
|
+
}
|
|
86
|
+
await this.restApi.xoApp.addUserToGroup(userId, group.id);
|
|
87
|
+
}
|
|
44
88
|
};
|
|
45
89
|
__decorate([
|
|
46
90
|
Example(groupIds),
|
|
@@ -58,12 +102,47 @@ __decorate([
|
|
|
58
102
|
Response(notFoundResp.status, notFoundResp.description),
|
|
59
103
|
__param(0, Path())
|
|
60
104
|
], GroupController.prototype, "getGroup", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
Patch('{id}'),
|
|
107
|
+
Middlewares(json()),
|
|
108
|
+
SuccessResponse(noContentResp.status, noContentResp.description),
|
|
109
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
110
|
+
Response(resourceAlreadyExists.status, resourceAlreadyExists.description),
|
|
111
|
+
Response(forbiddenOperationResp.status, forbiddenOperationResp.description),
|
|
112
|
+
__param(0, Path()),
|
|
113
|
+
__param(1, Body())
|
|
114
|
+
], GroupController.prototype, "updateGroup", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
Example(groupId),
|
|
117
|
+
Post(''),
|
|
118
|
+
Middlewares(json()),
|
|
119
|
+
SuccessResponse(createdResp.status, createdResp.description),
|
|
120
|
+
Response(invalidParameters.status, invalidParameters.description),
|
|
121
|
+
Response(resourceAlreadyExists.status, resourceAlreadyExists.description),
|
|
122
|
+
__param(0, Body())
|
|
123
|
+
], GroupController.prototype, "createGroup", null);
|
|
61
124
|
__decorate([
|
|
62
125
|
Delete('{id}'),
|
|
63
126
|
SuccessResponse(noContentResp.status, noContentResp.description),
|
|
64
127
|
Response(notFoundResp.status, notFoundResp.description),
|
|
65
128
|
__param(0, Path())
|
|
66
129
|
], GroupController.prototype, "deleteGroup", null);
|
|
130
|
+
__decorate([
|
|
131
|
+
Delete('{id}/users/{userId}'),
|
|
132
|
+
SuccessResponse(noContentResp.status, noContentResp.description),
|
|
133
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
134
|
+
Response(forbiddenOperationResp.status, forbiddenOperationResp.description),
|
|
135
|
+
__param(0, Path()),
|
|
136
|
+
__param(1, Path())
|
|
137
|
+
], GroupController.prototype, "removeUserFromGroup", null);
|
|
138
|
+
__decorate([
|
|
139
|
+
Put('{id}/users/{userId}'),
|
|
140
|
+
SuccessResponse(noContentResp.status, noContentResp.description),
|
|
141
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
142
|
+
Response(forbiddenOperationResp.status, forbiddenOperationResp.description),
|
|
143
|
+
__param(0, Path()),
|
|
144
|
+
__param(1, Path())
|
|
145
|
+
], GroupController.prototype, "addUserToGroup", null);
|
|
67
146
|
GroupController = __decorate([
|
|
68
147
|
Route('groups'),
|
|
69
148
|
Security('*'),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -17,12 +17,12 @@ export class HostService {
|
|
|
17
17
|
for (const id in hosts) {
|
|
18
18
|
total++;
|
|
19
19
|
const host = hosts[id];
|
|
20
|
-
if (!host.enabled) {
|
|
21
|
-
nDisabled++;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
20
|
switch (host.power_state) {
|
|
25
21
|
case HOST_POWER_STATE.RUNNING:
|
|
22
|
+
if (!host.enabled) {
|
|
23
|
+
nDisabled++;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
26
|
nRunning++;
|
|
27
27
|
break;
|
|
28
28
|
case HOST_POWER_STATE.HALTED:
|
|
@@ -9,7 +9,10 @@ export default function genericErrorHandler(error, req, res, _next) {
|
|
|
9
9
|
res.status(500).json({ error });
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const responseError = {
|
|
12
|
+
const responseError = {
|
|
13
|
+
error: error.message,
|
|
14
|
+
data: 'data' in error ? error.data : undefined,
|
|
15
|
+
};
|
|
13
16
|
let statusCode;
|
|
14
17
|
if (noSuchObject.is(error)) {
|
|
15
18
|
statusCode = 404;
|
|
@@ -19,7 +22,6 @@ export default function genericErrorHandler(error, req, res, _next) {
|
|
|
19
22
|
}
|
|
20
23
|
else if (featureUnauthorized.is(error)) {
|
|
21
24
|
statusCode = 403;
|
|
22
|
-
responseError.data = error.data;
|
|
23
25
|
}
|
|
24
26
|
else if (invalidCredentials.is(error)) {
|
|
25
27
|
statusCode = 401;
|
|
@@ -35,7 +37,6 @@ export default function genericErrorHandler(error, req, res, _next) {
|
|
|
35
37
|
}
|
|
36
38
|
else if (incorrectState.is(error)) {
|
|
37
39
|
statusCode = 409;
|
|
38
|
-
responseError.data = error.data;
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
41
42
|
if (error.name === 'XapiError') {
|