mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-08-03 01:50:34 +02:00
Do not allow unknown fields in JSON configuration file
This commit is contained in:
@@ -352,8 +352,9 @@ func NewIPMIReceiver(name string, config json.RawMessage) (Receiver, error) {
|
|||||||
|
|
||||||
// Read the IPMI receiver specific JSON config
|
// Read the IPMI receiver specific JSON config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &configJSON)
|
d := json.NewDecoder(bytes.NewReader(config))
|
||||||
if err != nil {
|
d.DisallowUnknownFields()
|
||||||
|
if err := d.Decode(&configJSON); err != nil {
|
||||||
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -353,10 +353,10 @@ func (r *RedfishReceiver) readProcessorMetrics(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to read JSON for processor metrics: %+w", err)
|
return fmt.Errorf("unable to read JSON for processor metrics: %+w", err)
|
||||||
}
|
}
|
||||||
err = json.NewDecoder(bytes.NewReader(body)).Decode(&processorMetrics)
|
err = json.Unmarshal(body, &processorMetrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"unable to decode JSON='%s' for processor metrics: %+w",
|
"unable to unmarshal JSON='%s' for processor metrics: %+w",
|
||||||
string(body),
|
string(body),
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
@@ -673,8 +673,9 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) {
|
|||||||
|
|
||||||
// Read the redfish receiver specific JSON config
|
// Read the redfish receiver specific JSON config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &configJSON)
|
d := json.NewDecoder(bytes.NewReader(config))
|
||||||
if err != nil {
|
d.DisallowUnknownFields()
|
||||||
|
if err := d.Decode(&configJSON); err != nil {
|
||||||
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user