forked from RedHatInsights/curiosity-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatformSchemas.js
More file actions
106 lines (97 loc) · 2.6 KB
/
Copy pathplatformSchemas.js
File metadata and controls
106 lines (97 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import JoiBase from 'joi';
import JoiDate from '@joi/date';
import { schemaResponse } from '../common/helpers';
import platformConstants from './platformConstants';
/**
* @memberof Platform
* @module PlatformSchemas
*/
/**
* Extend Joi with date.
*
* @type {*}
*/
const Joi = JoiBase.extend(JoiDate);
/**
* Export response source item.
*
* @type {*} Joi schema
*/
const exportsItem = Joi.object({
application: Joi.string(),
resource: Joi.string(),
filters: Joi.object().optional().allow(null),
id: Joi.string().guid(),
status: Joi.string().valid(...Object.values(platformConstants.PLATFORM_API_EXPORT_STATUS_TYPES))
})
.unknown(true)
.default();
/**
* Export response.
*
* @type {*} Joi schema
*/
const exportsResponseSchema = Joi.object()
.keys({
id: Joi.string().guid(),
name: Joi.string(),
created_at: Joi.date().utc(),
completed_at: Joi.date().utc().optional().allow(null),
expires_at: Joi.date().utc().optional().allow(null),
format: Joi.string().valid(...Object.values(platformConstants.PLATFORM_API_EXPORT_CONTENT_TYPES)),
status: Joi.string().valid(...Object.values(platformConstants.PLATFORM_API_EXPORT_STATUS_TYPES)),
sources: Joi.array().items(exportsItem).default([])
})
.unknown(true)
.default({});
/**
* User response item.
*
* @type {*} Joi schema
*/
const userResponseSchema = Joi.object()
.keys({
identity: Joi.object({
user: Joi.object({
is_org_admin: Joi.boolean().default(false)
})
.unknown(true)
.default({})
})
.unknown(true)
.default({}),
entitlements: Joi.object({
[process.env.REACT_APP_UI_NAME]: Joi.object({
is_entitled: Joi.boolean().default(false)
})
.unknown(true)
.default({})
})
.unknown(true)
.default({})
})
.unknown(true)
.default({});
/**
* Permissions response item.
*
* @type {*} Joi schema
*/
const permissionsItem = Joi.object({
permission: Joi.string().optional().allow(null),
resourceDefinitions: Joi.array().optional().default([])
})
.unknown(true)
.default();
/**
* Authorize response.
*
* @type {*} Joi schema
*/
const permissionsResponseSchema = Joi.array().items(permissionsItem).default([]);
const platformSchemas = {
exports: response => schemaResponse({ response, schema: exportsResponseSchema, id: 'Export status' }),
user: response => schemaResponse({ response, schema: userResponseSchema, id: 'User auth' }),
permissions: response => schemaResponse({ response, schema: permissionsResponseSchema, id: 'Permissions auth' })
};
export { platformSchemas as default, platformSchemas };