mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Rewrote way how to define region
Now region is defined with `region` variable and could be only `us` or `eu`
This commit is contained in:
parent
7422cc3822
commit
4b629db0d9
@ -25,28 +25,28 @@ type Parent struct {
|
||||
}
|
||||
|
||||
var opsGenieAPIUrl = map[string]string{
|
||||
"default": "https://api.opsgenie.com",
|
||||
"europe": "https://api.eu.opsgenie.com",
|
||||
"us": "https://api.opsgenie.com",
|
||||
"eu": "https://api.eu.opsgenie.com",
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Fetch(scheduleIdentifierType string, schedules []string) ([]*OnCallResponse, error) {
|
||||
agregatedResponses := []*OnCallResponse{}
|
||||
region := "default"
|
||||
|
||||
for _, sched := range schedules {
|
||||
if widget.settings.isEurope {
|
||||
region = "europe"
|
||||
}
|
||||
scheduleUrl := fmt.Sprintf("%s/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", opsGenieAPIUrl[region], sched, scheduleIdentifierType)
|
||||
response, err := opsGenieRequest(scheduleUrl, widget.settings.apiKey)
|
||||
agregatedResponses = append(agregatedResponses, response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if regionUrl, regionErr := opsGenieAPIUrl[widget.settings.region]; regionErr {
|
||||
for _, sched := range schedules {
|
||||
scheduleUrl := fmt.Sprintf("%s/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", regionUrl, sched, scheduleIdentifierType)
|
||||
response, err := opsGenieRequest(scheduleUrl, widget.settings.apiKey)
|
||||
agregatedResponses = append(agregatedResponses, response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return agregatedResponses, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("You specified wrong region. Possible options are only 'us' and 'eu'.")
|
||||
}
|
||||
return agregatedResponses, nil
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
@ -13,7 +13,7 @@ type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string `help:"Your OpsGenie API token."`
|
||||
isEurope bool `help:"Defines if European servers should be used." optional:"true"`
|
||||
region string `help:"Defines region to use. Possible options: us (by default), eu." optional:"true"`
|
||||
displayEmpty bool `help:"Whether schedules with no assigned person on-call should be displayed." optional:"true"`
|
||||
schedule []string `help:"A list of names of the schedule(s) to retrieve."`
|
||||
scheduleIdentifierType string `help:"Type of the schedule identifier." values:"id or name" optional:"true"`
|
||||
@ -25,7 +25,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_OPS_GENIE_API_KEY")),
|
||||
isEurope: ymlConfig.UBool("isEurope", false),
|
||||
region: ymlConfig.UString("region", "us"),
|
||||
displayEmpty: ymlConfig.UBool("displayEmpty", true),
|
||||
scheduleIdentifierType: ymlConfig.UString("scheduleIdentifierType", "id"),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user