diff --git a/core/config/config.go b/core/config/config.go index f679a88f..83cf2a5c 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -80,14 +80,14 @@ import ( // ssh_key = "/home/fristonio/.beast/secrets/key.priv" // ``` type BeastConfig struct { - AuthorizedKeysFile string `toml:"authorized_keys_file"` - BeastScriptsDir string `toml:"scripts_dir"` - AllowedBaseImages []string `toml:"allowed_base_images"` - AvailableSidecars []string `toml:"available_sidecars"` - GitRemote GitRemote `toml:"remote"` - JWTSecret string `toml:"jwt_secret"` - Webhooks []Webhook `toml:webhook` - TickerFrequency int `toml:"ticker_frequency"` + AuthorizedKeysFile string `toml:"authorized_keys_file"` + BeastScriptsDir string `toml:"scripts_dir"` + AllowedBaseImages []string `toml:"allowed_base_images"` + AvailableSidecars []string `toml:"available_sidecars"` + GitRemote GitRemote `toml:"remote"` + JWTSecret string `toml:"jwt_secret"` + NotificationWebhooks []NotificationWebhook `toml:webhook` + TickerFrequency int `toml:"ticker_frequency"` RemoteSyncPeriod time.Duration `toml:"-"` Rsp string `toml:"remote_sync_period"` @@ -215,10 +215,10 @@ func (config *GitRemote) ValidateGitConfig() error { return nil } -type Webhook struct { +type NotificationWebhook struct { URL string `toml:"url"` ServiceName string `toml:"service_name"` - Status bool `toml:"status"` + Active bool `toml:"status"` } // From the path of the config file provided as an arguement this function diff --git a/core/manager/challenge.go b/core/manager/challenge.go index 88ec1031..b832d899 100644 --- a/core/manager/challenge.go +++ b/core/manager/challenge.go @@ -530,7 +530,7 @@ func StartUndeployChallenge(challengeName string, purge bool) error { notify.SendNotification(notify.Success, msg) } - log.Infof("Notification for the event sent.") + log.Info("Notification for the event sent.") return err } diff --git a/pkg/notify/notification_constants.go b/pkg/notify/constants.go similarity index 100% rename from pkg/notify/notification_constants.go rename to pkg/notify/constants.go diff --git a/pkg/notify/main.go b/pkg/notify/main.go index 2f381f24..385c767e 100644 --- a/pkg/notify/main.go +++ b/pkg/notify/main.go @@ -2,6 +2,7 @@ package notify import ( "fmt" + "net/url" "github.com/sdslabs/beastv4/core/config" log "github.com/sirupsen/logrus" @@ -56,17 +57,21 @@ const ( //In the Discord notification provider it was using the same payload which was used for slack. //By writing "/slack" in the discord WebHookURL, it execute Slack-Compatible Webhook func NewNotifier(URL string, ProviderType ProviderTypeEnum) Notifier { + url, err := url.ParseRequestURI(URL) + if url == nil || err != nil { + fmt.Errorf("Invalid notification webhook URL") + } switch ProviderType { case SlackProvider: return &SlackNotificationProvider{ Request{ - WebHookURL: URL, + WebHookURL: url.String(), }, } case DiscordProvider: return &DiscordNotificationProvider{ Request{ - WebHookURL: URL + "/slack", + WebHookURL: url.String() + "/slack", }, } } @@ -83,8 +88,8 @@ func (req *Request) FillReqParams() error { } func SendNotification(nType NotificationType, message string) error { - for _, webhook := range config.Cfg.Webhooks { - if webhook.ServiceName != "" || webhook.Status == true { + for _, webhook := range config.Cfg.NotificationWebhooks { + if webhook.ServiceName != "" || webhook.Active == true { var Provider ProviderTypeEnum if webhook.ServiceName == "slack" { Provider = SlackProvider