Skip to content

Commit

Permalink
add json config for notifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
harishkswami committed Jul 26, 2024
1 parent bfbc8fc commit de3b801
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 26 additions & 1 deletion cli/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cli

import (
"context"
"encoding/json"
"fmt"

"github.com/goto/guardian/pkg/log"
"github.com/mitchellh/mapstructure"

"github.com/MakeNowJust/heredoc"
"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -69,7 +71,30 @@ func runJobCmd() *cobra.Command {
logger := log.NewCtxLogger(config.LogLevel, []string{config.AuditLogTraceIDHeaderKey})
crypto := crypto.NewAES(config.EncryptionSecretKeyKey)
validator := validator.New()
notifier, err := notifiers.NewClient(&config.Notifier, logger)
var notifierMap map[string]interface{}
errr := json.Unmarshal([]byte(config.Notifiers), &notifierMap)
if errr != nil {
fmt.Println(errr)
}
var notifierConfigMap map[string]notifiers.Config
err = mapstructure.Decode(notifierMap, &notifierConfigMap)
if err != nil {
fmt.Println(err)

}
notifierConfig := []notifiers.Config{}
if config.Notifiers != "" {
for _, val := range notifierConfigMap {
notifierConfig = append(notifierConfig, val)

}
} else {
// map old to the new format
oldConfig := config.Notifier
oldConfig.Criteria = "true"
notifierConfig = append(notifierConfig, oldConfig)
}
notifier, err := notifiers.NewMultiClient(&notifierConfig, logger)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func RunServer(config *Config) error {
oldConfig.Criteria = "true"
notifierConfig = append(notifierConfig, oldConfig)
}
fmt.Println(notifierConfig)
notifier, err := notifiers.NewMultiClient(&notifierConfig, logger)
if err != nil {
return err
Expand Down

0 comments on commit de3b801

Please sign in to comment.