1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Clean up the OpsGenie module's API credentials loading

This commit is contained in:
Chris Cummer 2018-07-31 14:21:02 -07:00
parent a1c528e4d5
commit f880c0ef19
2 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,8 @@ import (
"fmt"
"net/http"
"os"
"github.com/senorprogrammer/wtf/wtf"
)
type OnCallResponse struct {
@ -28,16 +30,22 @@ type Parent struct {
/* -------------------- Exported Functions -------------------- */
func Fetch() (*OnCallResponse, error) {
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
response, err := opsGenieRequest(scheduleUrl, apiKey)
response, err := opsGenieRequest(scheduleUrl, apiKey())
return response, err
}
/* -------------------- Unexported Functions -------------------- */
func apiKey() string {
return wtf.Config.UString(
"wtf.mods.opsgenie.apiKey",
os.Getenv("WTF_OPS_GENIE_API_KEY"),
)
}
func opsGenieRequest(url string, apiKey string) (*OnCallResponse, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {

View File

@ -25,7 +25,7 @@ func (widget *Widget) Refresh() {
data, err := Fetch()
widget.UpdateRefreshedAt()
widget.View.SetTitle(widget.Name)
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
var content string
if err != nil {