From 9bf19d6532fdedb983f83c51468ad052cc7c9b53 Mon Sep 17 00:00:00 2001 From: Amgad Ashraf <35847451+amgadramses@users.noreply.github.com> Date: Sun, 19 Dec 2021 14:23:09 +0200 Subject: [PATCH] :recycle: use providers with added configurations & update deploy files (#11) --- README.md | 1 - config.yaml | 3 --- deploy/config.yaml | 4 ++++ util/util.go | 20 +++++++++----------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index dfd093bf..3bb041cc 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.0.4/deploy/ | `providers.discord.text` | Customized text in discord message | No | | `providers.pagerduty.integrationKey` | PagerDuty integration key [more info](https://support.pagerduty.com/docs/services-and-integrations) | Yes | -Each provider can be enabled or disabled separately using the boolean property `enabled`. ### Cleanup diff --git a/config.yaml b/config.yaml index f96fea44..8e33d9f9 100644 --- a/config.yaml +++ b/config.yaml @@ -1,11 +1,8 @@ maxRecentLogLines: 0 providers: slack: - enabled: true webhook: "" pagerduty: - enabled: true integrationKey: "" discord: - enabled: true webhook: "" diff --git a/deploy/config.yaml b/deploy/config.yaml index 3295ab8c..0d0cf049 100644 --- a/deploy/config.yaml +++ b/deploy/config.yaml @@ -13,4 +13,8 @@ data: maxRecentLogLines: providers: slack: + webhook: + pagerduty: + integrationKey: + discord: webhook: \ No newline at end of file diff --git a/util/util.go b/util/util.go index 052af041..c81e477d 100644 --- a/util/util.go +++ b/util/util.go @@ -96,17 +96,15 @@ func GetProviders() []provider.Provider { var providers []provider.Provider for key, value := range viper.Get("providers").(map[string]interface{}) { - for e, b := range value.(map[string]interface{}) { - if e == "enabled" && b == true { - if key == "slack" { - providers = append(providers, provider.NewSlack(viper.GetString("providers.slack.webhook"))) - } - if key == "pagerduty" { - providers = append(providers, provider.NewPagerDuty(viper.GetString("providers.pagerduty.integrationKey"))) - } - if key == "discord" { - providers = append(providers, provider.NewDiscord(viper.GetString("providers.discord.webhook"))) - } + for c, v := range value.(map[string]interface{}) { + if key == "slack" && c == "webhook" && len(strings.TrimSpace(v.(string))) > 0 { + providers = append(providers, provider.NewSlack(viper.GetString("providers.slack.webhook"))) + } + if key == "pagerduty" && c == "integrationkey" && len(strings.TrimSpace(v.(string))) > 0 { + providers = append(providers, provider.NewPagerDuty(viper.GetString("providers.pagerduty.integrationKey"))) + } + if key == "discord" && c == "webhook" && len(strings.TrimSpace(v.(string))) > 0 { + providers = append(providers, provider.NewDiscord(viper.GetString("providers.discord.webhook"))) } } }