Преглед изворни кода

work on sanitizing configs

jamesread пре 4 година
родитељ
комит
614c3b73fc
4 измењених фајлова са 48 додато и 18 уклоњено
  1. 1 3
      cmd/OliveTin/main.go
  2. 32 0
      internal/config/sanitize.go
  3. 0 15
      internal/grpcapi/grpcApi.go
  4. 15 0
      internal/grpcapi/grpcApiButtons.go

+ 1 - 3
cmd/OliveTin/main.go

@@ -62,9 +62,7 @@ func reloadConfig() {
 		os.Exit(1)
 	}
 
-	if logLevel, err := log.ParseLevel(cfg.LogLevel); err == nil {
-		log.SetLevel(logLevel)
-	}
+	config.Sanitize(cfg);
 }
 
 func main() {

+ 32 - 0
internal/config/sanitize.go

@@ -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"
+}

+ 0 - 15
internal/grpcapi/grpcApi.go

@@ -56,21 +56,6 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
 	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) {
 	ret := &pb.GetLogsResponse{}
 

+ 15 - 0
internal/grpcapi/grpcApiButtons.go

@@ -8,6 +8,21 @@ import (
 	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 {
 	btn := pb.ActionButton{
 		Id:      fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),