mirror of
https://github.com/taigrr/wtf
synced 2026-03-31 20:48:44 -07:00
WTF-400 OpsGenie extracted to new config format
This commit is contained in:
55
modules/opsgenie/settings.go
Normal file
55
modules/opsgenie/settings.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package opsgenie
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
displayEmpty bool
|
||||
schedule []string
|
||||
scheduleIdentifierType string
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.opsgenie")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_OPS_GENIE_API_KEY")),
|
||||
displayEmpty: localConfig.UBool("displayEmpty", true),
|
||||
scheduleIdentifierType: localConfig.UString("scheduleIdentifierType", "id"),
|
||||
}
|
||||
|
||||
settings.schedule = settings.arrayifySchedules(localConfig)
|
||||
|
||||
return &settings
|
||||
}
|
||||
|
||||
// arrayifySchedules figures out if we're dealing with a single project or an array of projects
|
||||
func (settings *Settings) arrayifySchedules(localConfig *config.Config) []string {
|
||||
schedules := []string{}
|
||||
|
||||
// Single schedule
|
||||
schedule, err := localConfig.String("schedule")
|
||||
if err == nil {
|
||||
schedules = append(schedules, schedule)
|
||||
return schedules
|
||||
}
|
||||
|
||||
// Array of schedules
|
||||
scheduleList := localConfig.UList("schedule")
|
||||
for _, scheduleName := range scheduleList {
|
||||
if schedule, ok := scheduleName.(string); ok {
|
||||
schedules = append(schedules, schedule)
|
||||
}
|
||||
}
|
||||
|
||||
return schedules
|
||||
}
|
||||
Reference in New Issue
Block a user