Issue UI: redact private data like (user, locations, ...) (#25039)
This commit is contained in:
parent
f8dcd4dd78
commit
a65a1ce2d7
23 changed files with 277 additions and 109 deletions
|
|
@ -23,11 +23,11 @@ import (
|
|||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
func devicesConfig[T any](class templates.Class, h config.Handler[T]) ([]map[string]any, error) {
|
||||
func devicesConfig[T any](class templates.Class, h config.Handler[T], hidePrivate bool) ([]map[string]any, error) {
|
||||
var res []map[string]any
|
||||
|
||||
for _, dev := range h.Devices() {
|
||||
dc, err := deviceConfigMap(class, dev)
|
||||
dc, err := deviceConfigMap(class, dev, hidePrivate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -54,20 +54,23 @@ func devicesConfigHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check if private data should be hidden (default: true, showing private data)
|
||||
hidePrivate := r.URL.Query().Get("private") == "false"
|
||||
|
||||
var res []map[string]any
|
||||
|
||||
switch class {
|
||||
case templates.Meter:
|
||||
res, err = devicesConfig(class, config.Meters())
|
||||
res, err = devicesConfig(class, config.Meters(), hidePrivate)
|
||||
|
||||
case templates.Charger:
|
||||
res, err = devicesConfig(class, config.Chargers())
|
||||
res, err = devicesConfig(class, config.Chargers(), hidePrivate)
|
||||
|
||||
case templates.Vehicle:
|
||||
res, err = devicesConfig(class, config.Vehicles())
|
||||
res, err = devicesConfig(class, config.Vehicles(), hidePrivate)
|
||||
|
||||
case templates.Circuit:
|
||||
res, err = devicesConfig(class, config.Circuits())
|
||||
res, err = devicesConfig(class, config.Circuits(), hidePrivate)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -78,7 +81,7 @@ func devicesConfigHandler(w http.ResponseWriter, r *http.Request) {
|
|||
jsonWrite(w, res)
|
||||
}
|
||||
|
||||
func deviceConfigMap[T any](class templates.Class, dev config.Device[T]) (map[string]any, error) {
|
||||
func deviceConfigMap[T any](class templates.Class, dev config.Device[T], hidePrivate bool) (map[string]any, error) {
|
||||
conf := dev.Config()
|
||||
|
||||
dc := map[string]any{
|
||||
|
|
@ -102,7 +105,7 @@ func deviceConfigMap[T any](class templates.Class, dev config.Device[T]) (map[st
|
|||
}
|
||||
|
||||
if conf.Type == typeTemplate {
|
||||
params, err := sanitizeMasked(class, conf.Other)
|
||||
params, err := sanitizeMasked(class, conf.Other, hidePrivate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -146,13 +149,13 @@ func deviceConfigMap[T any](class templates.Class, dev config.Device[T]) (map[st
|
|||
return dc, nil
|
||||
}
|
||||
|
||||
func deviceConfig[T any](class templates.Class, id int, h config.Handler[T]) (map[string]any, error) {
|
||||
func deviceConfig[T any](class templates.Class, id int, h config.Handler[T], hidePrivate bool) (map[string]any, error) {
|
||||
dev, err := h.ByName(config.NameForID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deviceConfigMap(class, dev)
|
||||
return deviceConfigMap(class, dev, hidePrivate)
|
||||
}
|
||||
|
||||
// deviceConfigHandler returns a device configuration by class
|
||||
|
|
@ -171,20 +174,23 @@ func deviceConfigHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check if private data should be hidden (default: true, showing private data)
|
||||
hidePrivate := r.URL.Query().Get("private") == "false"
|
||||
|
||||
var res map[string]any
|
||||
|
||||
switch class {
|
||||
case templates.Meter:
|
||||
res, err = deviceConfig(class, id, config.Meters())
|
||||
res, err = deviceConfig(class, id, config.Meters(), hidePrivate)
|
||||
|
||||
case templates.Charger:
|
||||
res, err = deviceConfig(class, id, config.Chargers())
|
||||
res, err = deviceConfig(class, id, config.Chargers(), hidePrivate)
|
||||
|
||||
case templates.Vehicle:
|
||||
res, err = deviceConfig(class, id, config.Vehicles())
|
||||
res, err = deviceConfig(class, id, config.Vehicles(), hidePrivate)
|
||||
|
||||
case templates.Circuit:
|
||||
res, err = deviceConfig(class, id, config.Circuits())
|
||||
res, err = deviceConfig(class, id, config.Circuits(), hidePrivate)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue