@xen-orchestra/rest-api 0.6.0 → 0.8.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/README.md CHANGED
@@ -48,6 +48,7 @@ class Foo extends Controller {
48
48
  @Example(['foo', 'bar'])
49
49
  @Get('{id}')
50
50
  @Security('*')
51
+ @Middlewares(json())
51
52
  @SuccessResponse(202)
52
53
  @Response(404)
53
54
  getFoo(@Path() id: string) {
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from '@xen-orchestra/log';
2
- import { featureUnauthorized, forbiddenOperation, invalidCredentials, invalidParameters, noSuchObject, notImplemented, unauthorized, } from 'xo-common/api-errors.js';
2
+ import { featureUnauthorized, forbiddenOperation, incorrectState, invalidCredentials, invalidParameters, noSuchObject, notImplemented, objectAlreadyExists, unauthorized, } from 'xo-common/api-errors.js';
3
3
  const log = createLogger('xo:rest-api:error-handler');
4
4
  // must have 4 parameters to be recognized as an error middleware by express
5
5
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -19,12 +19,19 @@ export default function genericErrorHandler(error, req, res, _next) {
19
19
  else if (invalidCredentials.is(error)) {
20
20
  res.status(401);
21
21
  }
22
+ else if (objectAlreadyExists.is(error)) {
23
+ res.status(409);
24
+ }
22
25
  else if (invalidParameters.is(error)) {
23
26
  res.status(422);
24
27
  }
25
28
  else if (notImplemented.is(error)) {
26
29
  res.status(501);
27
30
  }
31
+ else if (incorrectState.is(error)) {
32
+ res.status(409);
33
+ responseError.data = error.data;
34
+ }
28
35
  else {
29
36
  if (error.name === 'XapiError') {
30
37
  responseError.info = 'This is a XenServer/XCP-ng error, not an XO error';
@@ -10,10 +10,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Example, Get, Path, Query, Response, Request, Route, Security, Tags } from 'tsoa';
11
11
  import { inject } from 'inversify';
12
12
  import { provide } from 'inversify-binding-decorators';
13
- import { network, networkIds, partialNetworks } from '../oa-examples/network.oa-example.mjs';
14
- import { notFoundResp, unauthorizedResp } from '../common/response.common.mjs';
15
- import { RestApi } from '../../rest-api/rest-api.mjs';
16
- import { XapiXoController } from '../../abstract-classes/xapi-xo-controller.mjs';
13
+ import { network, networkIds, partialNetworks } from '../open-api/oa-examples/network.oa-example.mjs';
14
+ import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
15
+ import { RestApi } from '../rest-api/rest-api.mjs';
16
+ import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
17
17
  let NetworkController = class NetworkController extends XapiXoController {
18
18
  constructor(restApi) {
19
19
  super('network', restApi);
@@ -1,3 +1,7 @@
1
+ export const createdResp = {
2
+ status: 201,
3
+ description: 'Resource created',
4
+ };
1
5
  export const actionAsyncroneResp = {
2
6
  status: 202,
3
7
  description: 'Action executed asynchronously',
@@ -23,3 +27,11 @@ export const internalServerErrorResp = {
23
27
  status: 500,
24
28
  description: 'Internal server error, XenServer/XCP-ng error',
25
29
  };
30
+ export const resourceAlreadyExists = {
31
+ status: 409,
32
+ description: 'Resource already exists',
33
+ };
34
+ export const invalidParameters = {
35
+ status: 422,
36
+ description: 'Invalid parameters',
37
+ };
@@ -0,0 +1,51 @@
1
+ export const pifIds = [
2
+ '/rest/v0/pifs/d9e42451-3794-089f-de81-4ee0e6137bee',
3
+ '/rest/v0/pifs/3f258258-ffd9-7bf2-2b47-74a0af2ea3b3',
4
+ ];
5
+ export const partialPifs = [
6
+ {
7
+ attached: true,
8
+ device: 'eth0',
9
+ deviceName: 'MT27520 Family [ConnectX-3 Pro]',
10
+ id: 'd9e42451-3794-089f-de81-4ee0e6137bee',
11
+ href: '/rest/v0/pifs/d9e42451-3794-089f-de81-4ee0e6137bee',
12
+ },
13
+ {
14
+ attached: true,
15
+ device: 'eth1',
16
+ deviceName: 'MT27520 Family [ConnectX-3 Pro]',
17
+ id: '3f258258-ffd9-7bf2-2b47-74a0af2ea3b3',
18
+ href: '/rest/v0/pifs/3f258258-ffd9-7bf2-2b47-74a0af2ea3b3',
19
+ },
20
+ ];
21
+ export const pif = {
22
+ type: 'PIF',
23
+ attached: true,
24
+ isBondMaster: false,
25
+ isBondSlave: false,
26
+ device: 'eth0',
27
+ deviceName: 'MT27520 Family [ConnectX-3 Pro]',
28
+ dns: '',
29
+ disallowUnplug: false,
30
+ gateway: '',
31
+ ip: '',
32
+ ipv6: [],
33
+ mac: 'ec:eb:b8:8e:d1:12',
34
+ management: false,
35
+ carrier: true,
36
+ mode: 'None',
37
+ ipv6Mode: 'None',
38
+ mtu: 1500,
39
+ netmask: '',
40
+ physical: true,
41
+ primaryAddressType: 'IPv4',
42
+ vlan: -1,
43
+ speed: 10000,
44
+ $host: 'b61a5c92-700e-4966-a13b-00633f03eea8',
45
+ $network: 'ac9b098e-df7f-50d3-b013-95d4cd550c61',
46
+ id: 'd9e42451-3794-089f-de81-4ee0e6137bee',
47
+ uuid: 'd9e42451-3794-089f-de81-4ee0e6137bee',
48
+ $pool: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
49
+ $poolId: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
50
+ _xapiRef: 'OpaqueRef:d94c0e13-ce19-c545-bcf2-c4cbbd3d43b8',
51
+ };
@@ -1,3 +1,4 @@
1
+ export const serverId = { id: '38068475-3a1d-4a64-95df-8782cdea02ac' };
1
2
  export const serverIds = [
2
3
  '/rest/v0/servers/f07ab729-c0e8-721c-45ec-f11276377030',
3
4
  '/rest/v0/servers/d5d1c4a3-4c5e-ca7b-6be8-33c824f87571',