@xen-orchestra/rest-api 0.4.0 → 0.5.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.
@@ -0,0 +1,26 @@
1
+ export const userIds = [
2
+ '/rest/v0/users/088124f3-41b6-4258-9653-6eedc7b46111',
3
+ '/rest/v0/users/a8715f02-20e7-4881-8b02-28ce2260c39d',
4
+ ];
5
+ export const partialUsers = [
6
+ {
7
+ permission: 'none',
8
+ name: 'testName',
9
+ id: '088124f3-41b6-4258-9653-6eedc7b46111',
10
+ href: '/rest/v0/users/088124f3-41b6-4258-9653-6eedc7b46111',
11
+ },
12
+ {
13
+ permission: 'none',
14
+ id: 'a8715f02-20e7-4881-8b02-28ce2260c39d',
15
+ href: '/rest/v0/users/a8715f02-20e7-4881-8b02-28ce2260c39d',
16
+ },
17
+ ];
18
+ export const user = {
19
+ email: 'admin@admin.net',
20
+ permission: 'admin',
21
+ pw_hash: '***obfuscated***',
22
+ groups: ['7d98fee4-3357-41a7-ac3f-9124212badb7', '7981ba62-c395-4546-bfa4-d1261653a77f'],
23
+ name: 'admin@admin.net',
24
+ preferences: {},
25
+ id: '722d17b9-699b-49d2-8193-be1ac573d3de',
26
+ };
@@ -69,7 +69,7 @@ export const vmTemplate = {
69
69
  $VGPUs: [],
70
70
  xenStoreData: {},
71
71
  vga: 'std',
72
- videoram: '8',
72
+ videoram: 8,
73
73
  id: 'b7569d99-30f8-178a-7d94-801de3e29b5b-f873abe0-b138-4995-8f6f-498b423d234d',
74
74
  isDefaultTemplate: true,
75
75
  template_info: {
@@ -16,6 +16,8 @@ import { VdiSnapshotController } from './../../vdi-snapshots/vdi-snapshot.contro
16
16
  // 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
17
17
  import { VbdController } from './../../vbds/vbd.controller.mjs';
18
18
  // 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
19
+ import { UserController } from './../../users/user.controller.mjs';
20
+ // 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
19
21
  import { SrController } from './../../srs/sr.controller.mjs';
20
22
  // 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
21
23
  import { ServerController } from './../../servers/server.controller.mjs';
@@ -220,6 +222,21 @@ const models = {
220
222
  "type": { "dataType": "nestedObjectLiteral", "nestedProperties": { "$pool": { "dataType": "string", "required": true }, "$poolId": { "dataType": "string", "required": true }, "_xapiRef": { "dataType": "string", "required": true }, "uuid": { "dataType": "string", "required": true }, "attached": { "dataType": "boolean", "required": true }, "bootable": { "dataType": "boolean", "required": true }, "device": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "enum", "enums": [null] }], "required": true }, "id": { "dataType": "string", "required": true }, "is_cd_drive": { "dataType": "boolean", "required": true }, "position": { "dataType": "string", "required": true }, "read_only": { "dataType": "boolean", "required": true }, "type": { "dataType": "enum", "enums": ["VBD"], "required": true }, "VDI": { "dataType": "string", "required": true }, "VM": { "dataType": "string", "required": true } }, "validators": {} },
221
223
  },
222
224
  // 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
225
+ "Partial_Unbrand_XoUser__": {
226
+ "dataType": "refAlias",
227
+ "type": { "dataType": "nestedObjectLiteral", "nestedProperties": { "authProviders": { "dataType": "union", "subSchemas": [{ "ref": "Record_string.string_" }, { "dataType": "undefined" }] }, "email": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "groups": { "dataType": "union", "subSchemas": [{ "dataType": "array", "array": { "dataType": "string" } }, { "dataType": "undefined" }] }, "id": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "name": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "permission": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "pw_hash": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "preferences": { "dataType": "union", "subSchemas": [{ "ref": "Record_string.string_" }, { "dataType": "undefined" }] } }, "validators": {} },
228
+ },
229
+ // 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
230
+ "WithHref_Partial_Unbrand_XoUser___": {
231
+ "dataType": "refAlias",
232
+ "type": { "dataType": "intersection", "subSchemas": [{ "ref": "Partial_Unbrand_XoUser__" }, { "dataType": "nestedObjectLiteral", "nestedProperties": { "href": { "dataType": "string", "required": true } } }], "validators": {} },
233
+ },
234
+ // 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
235
+ "Unbrand_XoUser_": {
236
+ "dataType": "refAlias",
237
+ "type": { "dataType": "nestedObjectLiteral", "nestedProperties": { "authProviders": { "dataType": "union", "subSchemas": [{ "ref": "Record_string.string_" }, { "dataType": "undefined" }] }, "email": { "dataType": "string", "required": true }, "groups": { "dataType": "array", "array": { "dataType": "string" }, "required": true }, "id": { "dataType": "string", "required": true }, "name": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "permission": { "dataType": "string", "required": true }, "pw_hash": { "dataType": "union", "subSchemas": [{ "dataType": "string" }, { "dataType": "undefined" }] }, "preferences": { "ref": "Record_string.string_", "required": true } }, "validators": {} },
238
+ },
239
+ // 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
223
240
  "Record_string.STORAGE_OPERATIONS_": {
224
241
  "dataType": "refAlias",
225
242
  "type": { "dataType": "nestedObjectLiteral", "nestedProperties": {}, "validators": {} },
@@ -900,6 +917,63 @@ export function RegisterRoutes(app) {
900
917
  }
901
918
  });
902
919
  // 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
920
+ const argsUserController_getUsers = {
921
+ req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
922
+ fields: { "in": "query", "name": "fields", "dataType": "string" },
923
+ filter: { "in": "query", "name": "filter", "dataType": "string" },
924
+ limit: { "in": "query", "name": "limit", "dataType": "double" },
925
+ };
926
+ app.get('/rest/v0/users', authenticateMiddleware([{ "*": [] }]), ...(fetchMiddlewares(UserController)), ...(fetchMiddlewares(UserController.prototype.getUsers)), async function UserController_getUsers(request, response, next) {
927
+ // 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
928
+ let validatedArgs = [];
929
+ try {
930
+ validatedArgs = templateService.getValidatedArgs({ args: argsUserController_getUsers, request, response });
931
+ const container = typeof iocContainer === 'function' ? iocContainer(request) : iocContainer;
932
+ const controller = await container.get(UserController);
933
+ if (typeof controller['setStatus'] === 'function') {
934
+ controller.setStatus(undefined);
935
+ }
936
+ await templateService.apiHandler({
937
+ methodName: 'getUsers',
938
+ controller,
939
+ response,
940
+ next,
941
+ validatedArgs,
942
+ successStatus: undefined,
943
+ });
944
+ }
945
+ catch (err) {
946
+ return next(err);
947
+ }
948
+ });
949
+ // 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
950
+ const argsUserController_getUser = {
951
+ id: { "in": "path", "name": "id", "required": true, "dataType": "string" },
952
+ };
953
+ app.get('/rest/v0/users/:id', authenticateMiddleware([{ "*": [] }]), ...(fetchMiddlewares(UserController)), ...(fetchMiddlewares(UserController.prototype.getUser)), async function UserController_getUser(request, response, next) {
954
+ // 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
955
+ let validatedArgs = [];
956
+ try {
957
+ validatedArgs = templateService.getValidatedArgs({ args: argsUserController_getUser, request, response });
958
+ const container = typeof iocContainer === 'function' ? iocContainer(request) : iocContainer;
959
+ const controller = await container.get(UserController);
960
+ if (typeof controller['setStatus'] === 'function') {
961
+ controller.setStatus(undefined);
962
+ }
963
+ await templateService.apiHandler({
964
+ methodName: 'getUser',
965
+ controller,
966
+ response,
967
+ next,
968
+ validatedArgs,
969
+ successStatus: undefined,
970
+ });
971
+ }
972
+ catch (err) {
973
+ return next(err);
974
+ }
975
+ });
976
+ // 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
903
977
  const argsSrController_getSrs = {
904
978
  req: { "in": "request", "name": "req", "required": true, "dataType": "object" },
905
979
  fields: { "in": "query", "name": "fields", "dataType": "string" },
@@ -0,0 +1,70 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
11
+ import { provide } from 'inversify-binding-decorators';
12
+ import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
13
+ import { partialUsers, user, userIds } from '../open-api/oa-examples/user.oa-example.mjs';
14
+ import { XoController } from '../abstract-classes/xo-controller.mjs';
15
+ let UserController = class UserController extends XoController {
16
+ // --- abstract methods
17
+ async getAllCollectionObjects() {
18
+ const users = await this.restApi.xoApp.getAllUsers();
19
+ return users.map(user => this.#sanitizeUser(user));
20
+ }
21
+ async getCollectionObject(id) {
22
+ const user = await this.restApi.xoApp.getUser(id);
23
+ return this.#sanitizeUser(user);
24
+ }
25
+ #sanitizeUser(user) {
26
+ const sanitizedUser = { ...user };
27
+ if (sanitizedUser.pw_hash !== undefined) {
28
+ sanitizedUser.pw_hash = '***obfuscated***';
29
+ }
30
+ return sanitizedUser;
31
+ }
32
+ /**
33
+ * @example fields "permission,name,id"
34
+ * @example filter "permission:none"
35
+ * @example limit 42
36
+ */
37
+ async getUsers(req, fields, filter, limit) {
38
+ const users = Object.values(await this.getObjects({ filter, limit }));
39
+ return this.sendObjects(users, req);
40
+ }
41
+ /**
42
+ * @example id "722d17b9-699b-49d2-8193-be1ac573d3de"
43
+ */
44
+ getUser(id) {
45
+ return this.getObject(id);
46
+ }
47
+ };
48
+ __decorate([
49
+ Example(userIds),
50
+ Example(partialUsers),
51
+ Get(''),
52
+ __param(0, Request()),
53
+ __param(1, Query()),
54
+ __param(2, Query()),
55
+ __param(3, Query())
56
+ ], UserController.prototype, "getUsers", null);
57
+ __decorate([
58
+ Example(user),
59
+ Get('{id}'),
60
+ Response(notFoundResp.status, notFoundResp.description),
61
+ __param(0, Path())
62
+ ], UserController.prototype, "getUser", null);
63
+ UserController = __decorate([
64
+ Route('users'),
65
+ Security('*'),
66
+ Response(unauthorizedResp.status, unauthorizedResp.description),
67
+ Tags('users'),
68
+ provide(UserController)
69
+ ], UserController);
70
+ export { UserController };
@@ -3978,6 +3978,96 @@
3978
3978
  ],
3979
3979
  "type": "object"
3980
3980
  },
3981
+ "Partial_Unbrand_XoUser__": {
3982
+ "properties": {
3983
+ "authProviders": {
3984
+ "$ref": "#/components/schemas/Record_string.string_"
3985
+ },
3986
+ "email": {
3987
+ "type": "string"
3988
+ },
3989
+ "groups": {
3990
+ "items": {
3991
+ "type": "string"
3992
+ },
3993
+ "type": "array"
3994
+ },
3995
+ "id": {
3996
+ "type": "string"
3997
+ },
3998
+ "name": {
3999
+ "type": "string"
4000
+ },
4001
+ "permission": {
4002
+ "type": "string"
4003
+ },
4004
+ "pw_hash": {
4005
+ "type": "string"
4006
+ },
4007
+ "preferences": {
4008
+ "$ref": "#/components/schemas/Record_string.string_"
4009
+ }
4010
+ },
4011
+ "type": "object",
4012
+ "description": "Make all properties in T optional"
4013
+ },
4014
+ "WithHref_Partial_Unbrand_XoUser___": {
4015
+ "allOf": [
4016
+ {
4017
+ "$ref": "#/components/schemas/Partial_Unbrand_XoUser__"
4018
+ },
4019
+ {
4020
+ "properties": {
4021
+ "href": {
4022
+ "type": "string"
4023
+ }
4024
+ },
4025
+ "required": [
4026
+ "href"
4027
+ ],
4028
+ "type": "object"
4029
+ }
4030
+ ]
4031
+ },
4032
+ "Unbrand_XoUser_": {
4033
+ "properties": {
4034
+ "authProviders": {
4035
+ "$ref": "#/components/schemas/Record_string.string_"
4036
+ },
4037
+ "email": {
4038
+ "type": "string"
4039
+ },
4040
+ "groups": {
4041
+ "items": {
4042
+ "type": "string"
4043
+ },
4044
+ "type": "array"
4045
+ },
4046
+ "id": {
4047
+ "type": "string"
4048
+ },
4049
+ "name": {
4050
+ "type": "string"
4051
+ },
4052
+ "permission": {
4053
+ "type": "string"
4054
+ },
4055
+ "pw_hash": {
4056
+ "type": "string"
4057
+ },
4058
+ "preferences": {
4059
+ "$ref": "#/components/schemas/Record_string.string_"
4060
+ }
4061
+ },
4062
+ "required": [
4063
+ "email",
4064
+ "groups",
4065
+ "id",
4066
+ "permission",
4067
+ "preferences"
4068
+ ],
4069
+ "type": "object"
4070
+ },
3981
4071
  "Record_string.STORAGE_OPERATIONS_": {
3982
4072
  "properties": {},
3983
4073
  "type": "object",
@@ -5870,7 +5960,7 @@
5870
5960
  },
5871
5961
  "info": {
5872
5962
  "title": "@xen-orchestra/rest-api",
5873
- "version": "0.4.0",
5963
+ "version": "0.5.0",
5874
5964
  "description": "REST API to manage your XOA",
5875
5965
  "license": {
5876
5966
  "name": "AGPL-3.0-or-later"
@@ -7636,7 +7726,7 @@
7636
7726
  "$VGPUs": [],
7637
7727
  "xenStoreData": {},
7638
7728
  "vga": "std",
7639
- "videoram": "8",
7729
+ "videoram": 8,
7640
7730
  "id": "b7569d99-30f8-178a-7d94-801de3e29b5b-f873abe0-b138-4995-8f6f-498b423d234d",
7641
7731
  "isDefaultTemplate": true,
7642
7732
  "template_info": {
@@ -8916,6 +9006,158 @@
8916
9006
  ]
8917
9007
  }
8918
9008
  },
9009
+ "/users": {
9010
+ "get": {
9011
+ "operationId": "GetUsers",
9012
+ "responses": {
9013
+ "200": {
9014
+ "description": "Ok",
9015
+ "content": {
9016
+ "application/json": {
9017
+ "schema": {
9018
+ "anyOf": [
9019
+ {
9020
+ "items": {
9021
+ "type": "string"
9022
+ },
9023
+ "type": "array"
9024
+ },
9025
+ {
9026
+ "items": {
9027
+ "$ref": "#/components/schemas/WithHref_Partial_Unbrand_XoUser___"
9028
+ },
9029
+ "type": "array"
9030
+ }
9031
+ ]
9032
+ },
9033
+ "examples": {
9034
+ "Example 1": {
9035
+ "value": [
9036
+ "/rest/v0/users/088124f3-41b6-4258-9653-6eedc7b46111",
9037
+ "/rest/v0/users/a8715f02-20e7-4881-8b02-28ce2260c39d"
9038
+ ]
9039
+ },
9040
+ "Example 2": {
9041
+ "value": [
9042
+ {
9043
+ "permission": "none",
9044
+ "name": "testName",
9045
+ "id": "088124f3-41b6-4258-9653-6eedc7b46111",
9046
+ "href": "/rest/v0/users/088124f3-41b6-4258-9653-6eedc7b46111"
9047
+ },
9048
+ {
9049
+ "permission": "none",
9050
+ "id": "a8715f02-20e7-4881-8b02-28ce2260c39d",
9051
+ "href": "/rest/v0/users/a8715f02-20e7-4881-8b02-28ce2260c39d"
9052
+ }
9053
+ ]
9054
+ }
9055
+ }
9056
+ }
9057
+ }
9058
+ },
9059
+ "401": {
9060
+ "description": "Authentication required"
9061
+ }
9062
+ },
9063
+ "tags": [
9064
+ "users"
9065
+ ],
9066
+ "security": [
9067
+ {
9068
+ "*": []
9069
+ }
9070
+ ],
9071
+ "parameters": [
9072
+ {
9073
+ "in": "query",
9074
+ "name": "fields",
9075
+ "required": false,
9076
+ "schema": {
9077
+ "type": "string"
9078
+ },
9079
+ "example": "permission,name,id"
9080
+ },
9081
+ {
9082
+ "in": "query",
9083
+ "name": "filter",
9084
+ "required": false,
9085
+ "schema": {
9086
+ "type": "string"
9087
+ },
9088
+ "example": "permission:none"
9089
+ },
9090
+ {
9091
+ "in": "query",
9092
+ "name": "limit",
9093
+ "required": false,
9094
+ "schema": {
9095
+ "format": "double",
9096
+ "type": "number"
9097
+ },
9098
+ "example": 42
9099
+ }
9100
+ ]
9101
+ }
9102
+ },
9103
+ "/users/{id}": {
9104
+ "get": {
9105
+ "operationId": "GetUser",
9106
+ "responses": {
9107
+ "200": {
9108
+ "description": "Ok",
9109
+ "content": {
9110
+ "application/json": {
9111
+ "schema": {
9112
+ "$ref": "#/components/schemas/Unbrand_XoUser_"
9113
+ },
9114
+ "examples": {
9115
+ "Example 1": {
9116
+ "value": {
9117
+ "email": "admin@admin.net",
9118
+ "permission": "admin",
9119
+ "pw_hash": "***obfuscated***",
9120
+ "groups": [
9121
+ "7d98fee4-3357-41a7-ac3f-9124212badb7",
9122
+ "7981ba62-c395-4546-bfa4-d1261653a77f"
9123
+ ],
9124
+ "name": "admin@admin.net",
9125
+ "preferences": {},
9126
+ "id": "722d17b9-699b-49d2-8193-be1ac573d3de"
9127
+ }
9128
+ }
9129
+ }
9130
+ }
9131
+ }
9132
+ },
9133
+ "401": {
9134
+ "description": "Authentication required"
9135
+ },
9136
+ "404": {
9137
+ "description": "Resource not found"
9138
+ }
9139
+ },
9140
+ "tags": [
9141
+ "users"
9142
+ ],
9143
+ "security": [
9144
+ {
9145
+ "*": []
9146
+ }
9147
+ ],
9148
+ "parameters": [
9149
+ {
9150
+ "in": "path",
9151
+ "name": "id",
9152
+ "required": true,
9153
+ "schema": {
9154
+ "type": "string"
9155
+ },
9156
+ "example": "722d17b9-699b-49d2-8193-be1ac573d3de"
9157
+ }
9158
+ ]
9159
+ }
9160
+ },
8919
9161
  "/srs": {
8920
9162
  "get": {
8921
9163
  "operationId": "GetSrs",
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.4.0",
9
+ "version": "0.5.0",
10
10
  "description": "REST API to manage your XOA",
11
11
  "license": "AGPL-3.0-or-later",
12
12
  "private": false,