@@ -38,12 +38,6 @@ local function check_replica_master(master, ctx)
38
38
end
39
39
end
40
40
41
- local function check_replicaset_master (master )
42
- if master ~= ' auto' then
43
- error (' Only "auto" master is supported' )
44
- end
45
- end
46
-
47
41
local function is_number (v )
48
42
return type (v ) == ' number' and v == v
49
43
end
70
64
71
65
local type_descriptors = {
72
66
-- check(self, template, value)
73
- -- tostring(self)
67
+ -- tostring(self, template )
74
68
75
69
[' string' ] = {
76
70
check = function (self , _ , v ) return type (v ) == ' string' end ,
@@ -108,6 +102,27 @@ local type_descriptors = {
108
102
check = function (self , _ , v ) return type (v ) == ' table' end ,
109
103
tostring = type_tostring_trivial ,
110
104
},
105
+ [' enum' ] = {
106
+ check = function (self , tv , v )
107
+ for _ , vi in pairs (tv .enum ) do
108
+ if vi == v then
109
+ return true
110
+ end
111
+ end
112
+ return false
113
+ end ,
114
+ tostring = function (self , tv )
115
+ local values = {}
116
+ for _ , v in pairs (tv .enum ) do
117
+ assert (type (v ) == ' string' )
118
+ table.insert (values , (" '%s'" ):format (v ))
119
+ end
120
+ if tv .is_optional then
121
+ table.insert (values , ' nil' )
122
+ end
123
+ return (' enum {%s}' ):format (table.concat (values , ' , ' ))
124
+ end ,
125
+ },
111
126
}
112
127
for name , td in pairs (type_descriptors ) do
113
128
td .name = name
@@ -138,7 +153,7 @@ local function validate_config(config, template, check_arg)
138
153
if type (expected_type ) == ' string' then
139
154
local td = type_descriptors [expected_type ]
140
155
if not td :check (tv , value ) then
141
- error (string.format (' %s must be %s' , name , td :tostring ()))
156
+ error (string.format (' %s must be %s' , name , td :tostring (tv )))
142
157
end
143
158
local max = tv .max
144
159
if max and value > max then
@@ -156,7 +171,7 @@ local function validate_config(config, template, check_arg)
156
171
if not is_valid_type_found then
157
172
local types = {}
158
173
for _ , t in pairs (expected_type ) do
159
- table.insert (types , type_descriptors [t ]:tostring ())
174
+ table.insert (types , type_descriptors [t ]:tostring (tv ))
160
175
end
161
176
types = table.concat (types , ' , ' )
162
177
error (string.format (' %s must be one of the following ' ..
@@ -205,8 +220,8 @@ local replicaset_template = {
205
220
},
206
221
lock = {type = ' boolean' , name = ' Lock' , is_optional = true },
207
222
master = {
208
- type = ' string ' , name = ' Master search mode' , is_optional = true ,
209
- check = check_replicaset_master
223
+ type = ' enum ' , name = ' Master search mode' , is_optional = true ,
224
+ enum = { ' auto ' },
210
225
},
211
226
}
212
227
@@ -239,12 +254,6 @@ local function cfg_check_weights(weights)
239
254
end
240
255
end
241
256
242
- local function check_discovery_mode (value )
243
- if value ~= ' on' and value ~= ' off' and value ~= ' once' then
244
- error (" Expected 'on', 'off', or 'once' for discovery_mode" )
245
- end
246
- end
247
-
248
257
local function check_sharding (sharding )
249
258
local uuids = {}
250
259
local uris = {}
@@ -356,8 +365,8 @@ local cfg_template = {
356
365
is_optional = true , default = consts .DEFAULT_FAILOVER_PING_TIMEOUT
357
366
},
358
367
discovery_mode = {
359
- type = ' string ' , name = ' Discovery mode: on, off, once ' ,
360
- is_optional = true , default = ' on' , check = check_discovery_mode
368
+ type = ' enum ' , name = ' Discovery mode' ,
369
+ is_optional = true , default = ' on' , enum = { ' on ' , ' off ' , ' once ' },
361
370
},
362
371
sched_ref_quota = {
363
372
name = ' Scheduler storage ref quota' , type = ' non-negative number' ,
0 commit comments