Skip to content

Commit

Permalink
config: change Sanitized to return snake-cased keys, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn committed Oct 7, 2019
1 parent 95ab4e0 commit da85f38
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 142 deletions.
122 changes: 61 additions & 61 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func parseTelemetry(result *Config, list *ast.ObjectList) error {
}

// Sanitized returns a copy of the config with all values that are considered
// sensitive stripped. It also strips all raw values that are mainly
// sensitive stripped. It also strips all `*Raw` values that are mainly
// used for parsing.
//
// Specifically, the fields that this method strips are:
Expand All @@ -917,115 +917,115 @@ func parseTelemetry(result *Config, list *ast.ObjectList) error {
// - Telemetry.CirconusAPIToken
func (c *Config) Sanitized() map[string]interface{} {
result := map[string]interface{}{
"CacheSize": c.CacheSize,
"DisableCache": c.DisableCache,
"DisableMlock": c.DisableMlock,
"DisablePrintableCheck": c.DisablePrintableCheck,
"cache_size": c.CacheSize,
"disable_cache": c.DisableCache,
"disable_mlock": c.DisableMlock,
"disable_printable_check": c.DisablePrintableCheck,

"EnableUI": c.EnableUI,
"enable_ui": c.EnableUI,

"MaxLeaseTTL": c.MaxLeaseTTL,
"DefaultLeaseTTL": c.DefaultLeaseTTL,
"max_lease_ttl": c.MaxLeaseTTL,
"default_lease_ttl": c.DefaultLeaseTTL,

"DefaultMaxRequestDuration": c.DefaultMaxRequestDuration,
"default_max_request_duration": c.DefaultMaxRequestDuration,

"ClusterName": c.ClusterName,
"ClusterCipherSuites": c.ClusterCipherSuites,
"cluster_name": c.ClusterName,
"cluster_cipher_suites": c.ClusterCipherSuites,

"PluginDirectory": c.PluginDirectory,
"plugin_directory": c.PluginDirectory,

"LogLevel": c.LogLevel,
"LogFormat": c.LogFormat,
"log_level": c.LogLevel,
"log_format": c.LogFormat,

"PidFile": c.PidFile,
"EnableRawEndpoint": c.EnableRawEndpoint,
"pid_file": c.PidFile,
"raw_storage_endpoint": c.EnableRawEndpoint,

"APIAddr": c.APIAddr,
"ClusterAddr": c.ClusterAddr,
"DisableClustering": c.DisableClustering,
"api_addr": c.APIAddr,
"cluster_addr": c.ClusterAddr,
"disable_clustering": c.DisableClustering,

"DisablePerformanceStandby": c.DisablePerformanceStandby,
"disable_performance_standby": c.DisablePerformanceStandby,

"DisableSealWrap": c.DisableSealWrap,
"disable_sealwrap": c.DisableSealWrap,

"DisableIndexing": c.DisableIndexing,
"disable_indexing": c.DisableIndexing,
}

// Sanitize listeners
if len(c.Listeners) != 0 {
var sanitizedListeners []interface{}
for _, ln := range c.Listeners {
cleanLn := map[string]interface{}{
"Type": ln.Type,
"Config": ln.Config,
"type": ln.Type,
"config": ln.Config,
}
sanitizedListeners = append(sanitizedListeners, cleanLn)
}
result["Listeners"] = sanitizedListeners
result["listeners"] = sanitizedListeners
}

// Sanitize storage stanza
if c.Storage != nil {
sanitizedStorage := map[string]interface{}{
"Type": c.Storage.Type,
"RedirectAddr": c.Storage.RedirectAddr,
"ClusterAddr": c.Storage.ClusterAddr,
"DisableClustering": c.Storage.DisableClustering,
"type": c.Storage.Type,
"redirect_addr": c.Storage.RedirectAddr,
"cluster_addr": c.Storage.ClusterAddr,
"disable_clustering": c.Storage.DisableClustering,
}
result["Storage"] = sanitizedStorage
result["storage"] = sanitizedStorage
}

// Sanitize HA storage stanza
if c.HAStorage != nil {
sanitizedHAStorage := map[string]interface{}{
"Type": c.HAStorage.Type,
"RedirectAddr": c.HAStorage.RedirectAddr,
"ClusterAddr": c.HAStorage.ClusterAddr,
"DisableClustering": c.HAStorage.DisableClustering,
"type": c.HAStorage.Type,
"redirect_addr": c.HAStorage.RedirectAddr,
"cluster_addr": c.HAStorage.ClusterAddr,
"disable_clustering": c.HAStorage.DisableClustering,
}
result["HAStorage"] = sanitizedHAStorage
result["ha_storage"] = sanitizedHAStorage
}

// Sanitize seals stanza
if len(c.Seals) != 0 {
var sanitizedSeals []interface{}
for _, s := range c.Seals {
cleanSeal := map[string]interface{}{
"Type": s.Type,
"Disabled": s.Disabled,
"type": s.Type,
"disabled": s.Disabled,
}
sanitizedSeals = append(sanitizedSeals, cleanSeal)
}
result["Seals"] = sanitizedSeals
result["seals"] = sanitizedSeals
}

// Sanitize telemetry stanza
if c.Telemetry != nil {
sanitizedTelemetry := map[string]interface{}{
"StatsiteAddr": c.Telemetry.StatsiteAddr,
"StatsdAddr": c.Telemetry.StatsdAddr,
"DisableHostname": c.Telemetry.DisableHostname,
"CirconusAPIToken": "",
"CirconusAPIApp": c.Telemetry.CirconusAPIApp,
"CirconusAPIURL": c.Telemetry.CirconusAPIURL,
"CirconusSubmissionInterval": c.Telemetry.CirconusSubmissionInterval,
"CirconusCheckSubmissionURL": c.Telemetry.CirconusCheckSubmissionURL,
"CirconusCheckID": c.Telemetry.CirconusCheckID,
"CirconusCheckForceMetricActivation": c.Telemetry.CirconusCheckForceMetricActivation,
"CirconusCheckInstanceID": c.Telemetry.CirconusCheckInstanceID,
"CirconusCheckSearchTag": c.Telemetry.CirconusCheckSearchTag,
"CirconusCheckTags": c.Telemetry.CirconusCheckTags,
"CirconusCheckDisplayName": c.Telemetry.CirconusCheckDisplayName,
"CirconusBrokerID": c.Telemetry.CirconusBrokerID,
"CirconusBrokerSelectTag": c.Telemetry.CirconusBrokerSelectTag,
"DogStatsDAddr": c.Telemetry.DogStatsDAddr,
"DogStatsDTags": c.Telemetry.DogStatsDTags,
"PrometheusRetentionTime": c.Telemetry.PrometheusRetentionTime,
"StackdriverProjectID": c.Telemetry.StackdriverProjectID,
"StackdriverLocation": c.Telemetry.StackdriverLocation,
"StackdriverNamespace": c.Telemetry.StackdriverNamespace,
"statsite_address": c.Telemetry.StatsiteAddr,
"statsd_address": c.Telemetry.StatsdAddr,
"disable_hostname": c.Telemetry.DisableHostname,
"circonus_api_token": "",
"circonus_api_app": c.Telemetry.CirconusAPIApp,
"circonus_api_url": c.Telemetry.CirconusAPIURL,
"circonus_submission_interval": c.Telemetry.CirconusSubmissionInterval,
"circonus_submission_url": c.Telemetry.CirconusCheckSubmissionURL,
"circonus_check_id": c.Telemetry.CirconusCheckID,
"circonus_check_force_metric_activation": c.Telemetry.CirconusCheckForceMetricActivation,
"circonus_check_instance_id": c.Telemetry.CirconusCheckInstanceID,
"circonus_check_search_tag": c.Telemetry.CirconusCheckSearchTag,
"circonus_check_tags": c.Telemetry.CirconusCheckTags,
"circonus_check_display_name": c.Telemetry.CirconusCheckDisplayName,
"circonus_broker_id": c.Telemetry.CirconusBrokerID,
"circonus_broker_select_tag": c.Telemetry.CirconusBrokerSelectTag,
"dogstatsd_addr": c.Telemetry.DogStatsDAddr,
"dogstatsd_tags": c.Telemetry.DogStatsDTags,
"prometheus_retention_time": c.Telemetry.PrometheusRetentionTime,
"stackdriver_project_id": c.Telemetry.StackdriverProjectID,
"stackdriver_location": c.Telemetry.StackdriverLocation,
"stackdriver_namespace": c.Telemetry.StackdriverNamespace,
}
result["Telemetry"] = sanitizedTelemetry
result["telemetry"] = sanitizedTelemetry
}

return result
Expand Down
120 changes: 60 additions & 60 deletions command/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,75 +358,75 @@ func TestConfig_Sanitized(t *testing.T) {
sanitizedConfig := config.Sanitized()

expected := map[string]interface{}{
"APIAddr": "top_level_api_addr",
"CacheSize": 0,
"ClusterAddr": "top_level_cluster_addr",
"ClusterCipherSuites": "",
"ClusterName": "testcluster",
"DefaultLeaseTTL": 10 * time.Hour,
"DefaultMaxRequestDuration": 0 * time.Second,
"DisableCache": true,
"DisableClustering": false,
"DisableIndexing": false,
"DisableMlock": true,
"DisablePerformanceStandby": false,
"DisablePrintableCheck": false,
"DisableSealWrap": true,
"EnableRawEndpoint": true,
"EnableUI": true,
"HAStorage": map[string]interface{}{
"ClusterAddr": "top_level_cluster_addr",
"DisableClustering": true,
"RedirectAddr": "top_level_api_addr",
"Type": "consul"},
"Listeners": []interface{}{
"api_addr": "top_level_api_addr",
"cache_size": 0,
"cluster_addr": "top_level_cluster_addr",
"cluster_cipher_suites": "",
"cluster_name": "testcluster",
"default_lease_ttl": 10 * time.Hour,
"default_max_request_duration": 0 * time.Second,
"disable_cache": true,
"disable_clustering": false,
"disable_indexing": false,
"disable_mlock": true,
"disable_performance_standby": false,
"disable_printable_check": false,
"disable_sealwrap": true,
"raw_storage_endpoint": true,
"enable_ui": true,
"ha_storage": map[string]interface{}{
"cluster_addr": "top_level_cluster_addr",
"disable_clustering": true,
"redirect_addr": "top_level_api_addr",
"type": "consul"},
"listeners": []interface{}{
map[string]interface{}{
"Config": map[string]interface{}{
"config": map[string]interface{}{
"address": "127.0.0.1:443",
},
"Type": "tcp",
"type": "tcp",
},
},
"LogFormat": "",
"LogLevel": "",
"MaxLeaseTTL": 10 * time.Hour,
"PidFile": "./pidfile",
"PluginDirectory": "",
"Seals": []interface{}{
"log_format": "",
"log_level": "",
"max_lease_ttl": 10 * time.Hour,
"pid_file": "./pidfile",
"plugin_directory": "",
"seals": []interface{}{
map[string]interface{}{
"Disabled": false,
"Type": "awskms",
"disabled": false,
"type": "awskms",
},
},
"Storage": map[string]interface{}{
"ClusterAddr": "top_level_cluster_addr",
"DisableClustering": false,
"RedirectAddr": "top_level_api_addr",
"Type": "consul",
"storage": map[string]interface{}{
"cluster_addr": "top_level_cluster_addr",
"disable_clustering": false,
"redirect_addr": "top_level_api_addr",
"type": "consul",
},
"Telemetry": map[string]interface{}{
"CirconusAPIApp": "",
"CirconusAPIToken": "",
"CirconusAPIURL": "",
"CirconusBrokerID": "",
"CirconusBrokerSelectTag": "",
"CirconusCheckDisplayName": "",
"CirconusCheckForceMetricActivation": "",
"CirconusCheckID": "",
"CirconusCheckInstanceID": "",
"CirconusCheckSearchTag": "",
"CirconusCheckSubmissionURL": "",
"CirconusCheckTags": "",
"CirconusSubmissionInterval": "",
"DisableHostname": false,
"DogStatsDAddr": "",
"DogStatsDTags": []string(nil),
"PrometheusRetentionTime": 24 * time.Hour,
"StackdriverLocation": "",
"StackdriverNamespace": "",
"StackdriverProjectID": "",
"StatsdAddr": "bar",
"StatsiteAddr": ""},
"telemetry": map[string]interface{}{
"circonus_api_app": "",
"circonus_api_token": "",
"circonus_api_url": "",
"circonus_broker_id": "",
"circonus_broker_select_tag": "",
"circonus_check_display_name": "",
"circonus_check_force_metric_activation": "",
"circonus_check_id": "",
"circonus_check_instance_id": "",
"circonus_check_search_tag": "",
"circonus_submission_url": "",
"circonus_check_tags": "",
"circonus_submission_interval": "",
"disable_hostname": false,
"dogstatsd_addr": "",
"dogstatsd_tags": []string(nil),
"prometheus_retention_time": 24 * time.Hour,
"stackdriver_location": "",
"stackdriver_namespace": "",
"stackdriver_project_id": "",
"statsd_address": "bar",
"statsite_address": ""},
}

if diff := deep.Equal(sanitizedConfig, expected); len(diff) > 0 {
Expand Down
42 changes: 21 additions & 21 deletions http/sys_config_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ func TestSysConfigState_Sanitized(t *testing.T) {
var expected map[string]interface{}

configResp := map[string]interface{}{
"APIAddr": "",
"CacheSize": json.Number("0"),
"ClusterAddr": "",
"ClusterCipherSuites": "",
"ClusterName": "",
"DefaultLeaseTTL": json.Number("0"),
"DefaultMaxRequestDuration": json.Number("0"),
"DisableCache": false,
"DisableClustering": false,
"DisableIndexing": false,
"DisableMlock": false,
"DisablePerformanceStandby": false,
"DisablePrintableCheck": false,
"DisableSealWrap": false,
"EnableRawEndpoint": false,
"EnableUI": false,
"LogFormat": "",
"LogLevel": "",
"MaxLeaseTTL": json.Number("0"),
"PidFile": "",
"PluginDirectory": "",
"api_addr": "",
"cache_size": json.Number("0"),
"cluster_addr": "",
"cluster_cipher_suites": "",
"cluster_name": "",
"default_lease_ttl": json.Number("0"),
"default_max_request_duration": json.Number("0"),
"disable_cache": false,
"disable_clustering": false,
"disable_indexing": false,
"disable_mlock": false,
"disable_performance_standby": false,
"disable_printable_check": false,
"disable_sealwrap": false,
"raw_storage_endpoint": false,
"enable_ui": false,
"log_format": "",
"log_level": "",
"max_lease_ttl": json.Number("0"),
"pid_file": "",
"plugin_directory": "",
}

expected = map[string]interface{}{
Expand Down

0 comments on commit da85f38

Please sign in to comment.