-
Notifications
You must be signed in to change notification settings - Fork 396
Closed
Labels
3.2Target is 3.2 and all newer release/master branchesTarget is 3.2 and all newer release/master branchesconfigfeatureA new functionalityA new functionality
Description
For example, we have some logger module/service and its configuration contains a user-defined context without a strict structure. We want to acquire a particular value from it (if exists):
local schema = require('experimental.config.utils.schema')
local logger_config_schema = schema.new('logger_config', schema.record({
level = schema.enum({
'fatal',
'syserror',
'error',
'crit',
'warn',
'info',
'verbose',
'debug',
}, {
default = 'info',
}),
-- Initial context (MDC).
context = schema.map({
key = schema.scalar({type = 'string'}),
value = schema.scalar({type = 'any'}), -- !!
}),
}))
logger_config = logger_config_schema:apply_default({})
logger_config.context = {
hostname = box.info.hostname,
process = {
pid = box.info.pid,
},
}
-- It is OK.
local hostname = logger_config_schema:get(logger_config, 'context.hostname')
print('hostname', hostname)
-- It raises an error.
local pid = logger_config_schema:get(logger_config, 'context.process.pid')
-- error: [logger_config] context.process: Attempt to index a
-- scalar value of type any by field "pid"
print('pid', pid)It seems convenient to have an ability to access a field that is inside a schemaless part of the configuration (inside the any type).
Also, this ability would be helpful for config:get(), when values nested into app.cfg or roles_cfg are accessed.
See also #10204.
Metadata
Metadata
Assignees
Labels
3.2Target is 3.2 and all newer release/master branchesTarget is 3.2 and all newer release/master branchesconfigfeatureA new functionalityA new functionality