github.com/wtfutil/wtf@v0.43.0/modules/pagerduty/settings.go (about)

     1  package pagerduty
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/olebedev/config"
     7  	"github.com/wtfutil/wtf/cfg"
     8  )
     9  
    10  const (
    11  	defaultFocusable = false
    12  	defaultTitle     = "PagerDuty"
    13  )
    14  
    15  // Settings defines the configuration properties for this module
    16  type Settings struct {
    17  	*cfg.Common
    18  
    19  	apiKey           string        `help:"Your PagerDuty API key."`
    20  	escalationFilter []interface{} `help:"An array of schedule names you want to filter the OnCalls on."`
    21  	myName           string        `help:"The name to highlight when on-call in PagerDuty."`
    22  	scheduleIDs      []interface{} `help:"An array of schedule IDs you want to restrict the OnCalls query to."`
    23  	showIncidents    bool          `help:"Whether or not to list incidents." optional:"true"`
    24  	showOnCallEnd    bool          `help:"Whether or not to display the date the oncall schedule ends." optional:"true"`
    25  	showSchedules    bool          `help:"Whether or not to show schedules." optional:"true"`
    26  	teamIDs          []interface{} `help:"An array of team IDs to restrict the incidents query to" optional:"true"`
    27  	userIDs          []interface{} `help:"An array of user IDs to restrict the incidents query to" optional:"true"`
    28  }
    29  
    30  // NewSettingsFromYAML creates a new settings instance from a YAML config block
    31  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    32  	settings := Settings{
    33  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    34  
    35  		apiKey:           ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_PAGERDUTY_API_KEY"))),
    36  		escalationFilter: ymlConfig.UList("escalationFilter"),
    37  		myName:           ymlConfig.UString("myName"),
    38  		scheduleIDs:      ymlConfig.UList("scheduleIDs", []interface{}{}),
    39  		showIncidents:    ymlConfig.UBool("showIncidents", true),
    40  		showOnCallEnd:    ymlConfig.UBool("showOnCallEnd", false),
    41  		showSchedules:    ymlConfig.UBool("showSchedules", true),
    42  		teamIDs:          ymlConfig.UList("teamIDs", []interface{}{}),
    43  		userIDs:          ymlConfig.UList("userIDs", []interface{}{}),
    44  	}
    45  
    46  	cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()
    47  
    48  	return &settings
    49  }