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:
parent
a1c528e4d5
commit
f880c0ef19
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user