work on sanitizing configs
This commit is contained in:
parent
6267dd791a
commit
614c3b73fc
|
|
@ -62,9 +62,7 @@ func reloadConfig() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if logLevel, err := log.ParseLevel(cfg.LogLevel); err == nil {
|
config.Sanitize(cfg);
|
||||||
log.SetLevel(logLevel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Sanitize(cfg *Config) {
|
||||||
|
sanitizeLogLevel(cfg);
|
||||||
|
|
||||||
|
for _, action := range cfg.ActionButtons {
|
||||||
|
sanitizeAction(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeLogLevel(cfg *Config) {
|
||||||
|
if logLevel, err := log.ParseLevel(cfg.LogLevel); err == nil {
|
||||||
|
log.Info("lvl", logLevel)
|
||||||
|
log.SetLevel(logLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeAction(action ActionButton) {
|
||||||
|
for _, argument := range action.Arguments {
|
||||||
|
sanitizeActionArgument(argument)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeActionArgument(arg ActionArgument) {
|
||||||
|
log.Info("Sanitize AA")
|
||||||
|
arg.Label = "foo"
|
||||||
|
arg.Name = "blat"
|
||||||
|
}
|
||||||
|
|
@ -56,21 +56,6 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func actionButtonsCfgToPb(cfgActionButtons []config.ActionButton, user *acl.User) (*pb.GetButtonsResponse) {
|
|
||||||
res := &pb.GetButtonsResponse{}
|
|
||||||
|
|
||||||
for _, action := range cfgActionButtons {
|
|
||||||
if !acl.IsAllowedView(cfg, user, &action) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
btn := buildButton(action, user)
|
|
||||||
res.Actions = append(res.Actions, btn)
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *pb.GetLogsRequest) (*pb.GetLogsResponse, error) {
|
func (api *oliveTinAPI) GetLogs(ctx ctx.Context, req *pb.GetLogsRequest) (*pb.GetLogsResponse, error) {
|
||||||
ret := &pb.GetLogsResponse{}
|
ret := &pb.GetLogsResponse{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,21 @@ import (
|
||||||
config "github.com/jamesread/OliveTin/internal/config"
|
config "github.com/jamesread/OliveTin/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func actionButtonsCfgToPb(cfgActionButtons []config.ActionButton, user *acl.User) (*pb.GetButtonsResponse) {
|
||||||
|
res := &pb.GetButtonsResponse{}
|
||||||
|
|
||||||
|
for _, action := range cfgActionButtons {
|
||||||
|
if !acl.IsAllowedView(cfg, user, &action) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
btn := buildButton(action, user)
|
||||||
|
res.Actions = append(res.Actions, btn)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func buildButton(action config.ActionButton, user *acl.User) *pb.ActionButton {
|
func buildButton(action config.ActionButton, user *acl.User) *pb.ActionButton {
|
||||||
btn := pb.ActionButton{
|
btn := pb.ActionButton{
|
||||||
Id: fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),
|
Id: fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue