Load default configuration values for modules
Filters, monitors and routers can now declare parameters and those parameters will always be present. Currently, this removes the need to parse simple values like booleans and integers. Some of the more common parameter types could be added in the future e.g. paths to files.
This commit is contained in:
parent
241dbb464a
commit
f7c6accaa0
@ -2599,6 +2599,33 @@ static int validate_ssl_parameters(CONFIG_CONTEXT* obj, char *ssl_cert, char *ss
|
||||
return error_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add default parameters for a module to the configuration context
|
||||
*
|
||||
* Only parameters that aren't defined are added to the configuration context.
|
||||
* This allows users to override the default values.
|
||||
*
|
||||
* @param ctx Configuration context where the default parameters are added
|
||||
* @param module Name of the module
|
||||
*/
|
||||
static void config_add_defaults(CONFIG_CONTEXT *ctx, const char *module)
|
||||
{
|
||||
const MXS_MODULE *mod = get_module(module);
|
||||
|
||||
if (mod)
|
||||
{
|
||||
for (int i = 0; mod->parameters[i].name; i++)
|
||||
{
|
||||
ss_dassert(config_param_is_valid(module, mod->parameters[i].name,
|
||||
mod->parameters[i].default_value));
|
||||
|
||||
bool rv = config_add_param(ctx, mod->parameters[i].name,
|
||||
mod->parameters[i].default_value);
|
||||
MXS_ABORT_IF_FALSE(rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new router for a service
|
||||
* @param obj Service configuration context
|
||||
@ -2795,6 +2822,11 @@ int create_new_service(CONFIG_CONTEXT *obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Store the configuration parameters for the service */
|
||||
config_add_defaults(obj, router);
|
||||
service_add_parameters(obj->element, obj->parameters);
|
||||
|
||||
return error_count;
|
||||
}
|
||||
|
||||
@ -3023,6 +3055,7 @@ int create_new_monitor(CONFIG_CONTEXT *context, CONFIG_CONTEXT *obj, HASHTABLE*
|
||||
|
||||
if (error_count == 0)
|
||||
{
|
||||
config_add_defaults(obj, module);
|
||||
monitorAddParameters(obj->element, obj->parameters);
|
||||
|
||||
char *interval_str = config_get_value(obj->parameters, "monitor_interval");
|
||||
@ -3235,7 +3268,9 @@ int create_new_filter(CONFIG_CONTEXT *obj)
|
||||
}
|
||||
}
|
||||
|
||||
config_add_defaults(obj, module);
|
||||
CONFIG_PARAMETER *params = obj->parameters;
|
||||
|
||||
while (params)
|
||||
{
|
||||
if (strcmp(params->name, "module") && strcmp(params->name, "options"))
|
||||
|
@ -121,6 +121,16 @@ void service_update(SERVICE *service, char *router, char *user, char *auth);
|
||||
bool service_set_param_value(SERVICE* service, CONFIG_PARAMETER* param, char* valstr,
|
||||
count_spec_t count_spec, config_param_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Add parameters to a service
|
||||
*
|
||||
* A copy of @c param is added to @c service.
|
||||
*
|
||||
* @param service Service where the parameters are added
|
||||
* @param param Parameters to add
|
||||
*/
|
||||
void service_add_parameters(SERVICE *service, const CONFIG_PARAMETER *param);
|
||||
|
||||
/**
|
||||
* Internal debugging diagnostics
|
||||
*/
|
||||
|
@ -1658,6 +1658,17 @@ int service_refresh_users(SERVICE *service)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void service_add_parameters(SERVICE *service, const CONFIG_PARAMETER *param)
|
||||
{
|
||||
while (param)
|
||||
{
|
||||
CONFIG_PARAMETER *new_param = config_clone_param(param);
|
||||
new_param->next = service->svc_config_param;
|
||||
service->svc_config_param = new_param;
|
||||
param = param->next;
|
||||
}
|
||||
}
|
||||
|
||||
bool service_set_param_value(SERVICE* service,
|
||||
CONFIG_PARAMETER* param,
|
||||
char* valstr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user