1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/opsgenie/settings.go
2019-04-15 21:16:18 -07:00

56 lines
1.3 KiB
Go

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
}