· 4 years ago · Dec 04, 2020, 01:18 AM
1// All providers support these extended options as well
2const Common = {
3 bufferSize: {
4 type: ['string', 'number']
5 },
6 maxIoSize: {
7 type: ['string', 'number']
8 },
9 segmentSize: {
10 type: ['string', 'number']
11 }
12}
13
14// Generic field validator indicating what options are allowed and what aren't
15// for each service (engine provider) supports
16const Fields = {
17 datadir: {
18 type: 'object',
19 properties: {
20 phyDir: { type: ['string', 'number'] }
21 },
22 dependentSchemas: Common,
23 required: ['phyDir']
24 },
25 backblaze: {
26 type: 'object',
27 properties: {
28 keyId: {
29 type: 'string'
30 },
31 bucketName: {
32 type: 'string'
33 },
34 appKey: {
35 type: 'string'
36 }
37 },
38 dependentSchemas: Common,
39 required: ['keyId', 'bucketName', 'appKey']
40 },
41 objstore: {
42 type: 'object',
43 properties: {
44 region: {
45 type: 'string'
46 },
47 accessKey: {
48 type: 'string'
49 },
50 secretKey: {
51 type: 'string'
52 },
53 containerName: {
54 type: 'string'
55 },
56 url: {
57 type: 'string'
58 }
59 },
60 dependentSchemas: Common,
61 required: ['region', 'accessKey', 'secretKey', 'containerName']
62 },
63 azure: {
64 type: 'object',
65 properties: {
66 accountName: {
67 type: 'string'
68 },
69 accountKey: {
70 type: 'string'
71 },
72 containerName: {
73 type: 'string'
74 },
75 endpoint: {
76 type: 'string'
77 }
78 },
79 dependentSchemas: Common,
80 required: ['accountName', 'accountKey', 'containerName', 'endpoint']
81 }
82};
83
84function registerSchemas() {
85 for (const type of Object.keys(Fields))
86 Server.validator.addObjectSchema(type, Fields[type]);
87}