mirror of
https://github.com/vee1e/runtimeclass-debugger.git
synced 2026-09-01 18:27:58 +00:00
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Package config reads edge node configuration files.
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// ErrConfigNotFound is returned when the edgecore config file does not
|
|
// exist.
|
|
var ErrConfigNotFound = errors.New("edgecore config not found")
|
|
|
|
// ReportEvent reads edged.reportEvent from the edgecore.yaml at the given
|
|
// path. It returns the value, whether the key was present, and an error.
|
|
func ReportEvent(path string) (bool, bool, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return false, false, fmt.Errorf("%w: %s", ErrConfigNotFound, path)
|
|
}
|
|
return false, false, err
|
|
}
|
|
var tree map[string]interface{}
|
|
if err := yaml.Unmarshal(data, &tree); err != nil {
|
|
return false, false, fmt.Errorf("parse %s: %w", path, err)
|
|
}
|
|
edged, ok := tree["edged"].(map[string]interface{})
|
|
if !ok {
|
|
return false, false, nil
|
|
}
|
|
value, ok := edged["reportEvent"]
|
|
if !ok {
|
|
return false, false, nil
|
|
}
|
|
report, ok := value.(bool)
|
|
if !ok {
|
|
return false, true, fmt.Errorf("edged.reportEvent is not a boolean in %s: %v", path, value)
|
|
}
|
|
return report, true, nil
|
|
}
|