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"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OnCallResponse struct {
|
type OnCallResponse struct {
|
||||||
@ -28,16 +30,22 @@ type Parent struct {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func Fetch() (*OnCallResponse, error) {
|
func Fetch() (*OnCallResponse, error) {
|
||||||
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
|
|
||||||
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
|
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
|
||||||
|
|
||||||
response, err := opsGenieRequest(scheduleUrl, apiKey)
|
response, err := opsGenieRequest(scheduleUrl, apiKey())
|
||||||
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- 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) {
|
func opsGenieRequest(url string, apiKey string) (*OnCallResponse, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,7 +25,7 @@ func (widget *Widget) Refresh() {
|
|||||||
data, err := Fetch()
|
data, err := Fetch()
|
||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
widget.View.SetTitle(widget.Name)
|
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user