Skip to content

Commit 2ea7c4f

Browse files
committed
add config validations
1 parent 1947768 commit 2ea7c4f

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/appdynamics_ngx_module.c

+34-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ appd_ngx_create_main_config(ngx_conf_t *cf) {
1212
if (ngx_array_init(&amcf->backend_names, cf->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
1313
return NULL;
1414
}
15-
1615
amcf->enabled = NGX_CONF_UNSET;
1716
amcf->controller_use_ssl = NGX_CONF_UNSET;
1817
amcf->controller_port = NGX_CONF_UNSET;
@@ -23,8 +22,34 @@ static char *
2322
appd_ngx_init_main_config(ngx_conf_t *cf, void *conf) {
2423
appd_ngx_main_conf_t *amcf = conf;
2524

25+
ngx_conf_init_value(amcf->enabled, 0);
2626
if (amcf->enabled) {
27-
// TODO validate configuration
27+
if (amcf->controller_hostname.len == 0) {
28+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_controller_hostname");
29+
return NGX_CONF_ERROR;
30+
}
31+
if (amcf->controller_account.len == 0) {
32+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_controller_account");
33+
return NGX_CONF_ERROR;
34+
}
35+
if(amcf->controller_access_key.len == 0) {
36+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_controller_access_key");
37+
return NGX_CONF_ERROR;
38+
}
39+
if (amcf->agent_app_name.len == 0) {
40+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_agent_app_name");
41+
return NGX_CONF_ERROR;
42+
}
43+
if (amcf->agent_tier_name.len == 0) {
44+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_agent_tier_name");
45+
return NGX_CONF_ERROR;
46+
}
47+
if (amcf->agent_node_name.len == 0) {
48+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "missing appdynamics_agent_nod_name");
49+
return NGX_CONF_ERROR;
50+
}
51+
// NOTE make sure to read AppDynamics' this-or-that defaulting of certain props!
52+
2853
}
2954

3055
return NGX_CONF_OK;
@@ -69,7 +94,7 @@ appd_ngx_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) {
6994

7095
ngx_conf_merge_str_value(conf->bt_name, prev->bt_name, "");
7196
ngx_conf_merge_uint_value(conf->bt_name_max_segments, prev->bt_name_max_segments, 3);
72-
ngx_conf_merge_value(conf->error_on_4xx, prev->error_on_4xx, 1);
97+
ngx_conf_merge_value(conf->error_on_4xx, prev->error_on_4xx, 0);
7398

7499
pcc = prev->collectors.elts;
75100
for (i = 0; i < prev->collectors.nelts; i++) {
@@ -187,10 +212,14 @@ appd_ngx_sdk_init(ngx_cycle_t *cycle, appd_ngx_main_conf_t *amcf) {
187212

188213
struct appd_config* cfg = appd_config_init();
189214
appd_config_set_controller_host(cfg, (const char*)amcf->controller_hostname.data);
190-
appd_config_set_controller_port(cfg, amcf->controller_port);
215+
if (amcf->controller_port != NGX_CONF_UNSET) {
216+
appd_config_set_controller_port(cfg, amcf->controller_port);
217+
}
191218
appd_config_set_controller_account(cfg, (const char*)amcf->controller_account.data);
192219
appd_config_set_controller_access_key(cfg, (const char*)amcf->controller_access_key.data);
193-
appd_config_set_controller_use_ssl(cfg, amcf->controller_use_ssl);
220+
if (amcf->controller_use_ssl != NGX_CONF_UNSET) {
221+
appd_config_set_controller_use_ssl(cfg, amcf->controller_use_ssl);
222+
}
194223
if (amcf->controller_certificate_file.len > 0) {
195224
appd_config_set_controller_certificate_file(cfg, (const char*)amcf->controller_certificate_file.data);
196225
}

0 commit comments

Comments
 (0)