From a1c528e4d5e2a9339cb3564dbafd2819602c46b3 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 31 Jul 2018 14:17:30 -0700 Subject: [PATCH] Clean up the NewRelic module's API credentials loading --- newrelic/client.go | 11 +++++++++-- newrelic/widget.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/newrelic/client.go b/newrelic/client.go index f88d4e3e..e3937338 100644 --- a/newrelic/client.go +++ b/newrelic/client.go @@ -8,7 +8,7 @@ import ( ) func Application() (*nr.Application, error) { - client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) + client := nr.NewClient(apiKey()) application, err := client.GetApplication(wtf.Config.UInt("wtf.mods.newrelic.applicationId")) if err != nil { @@ -19,7 +19,7 @@ func Application() (*nr.Application, error) { } func Deployments() ([]nr.ApplicationDeployment, error) { - client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) + client := nr.NewClient(apiKey()) opts := &nr.ApplicationDeploymentOptions{Page: 1} deployments, err := client.GetApplicationDeployments(wtf.Config.UInt("wtf.mods.newrelic.applicationId"), opts) @@ -29,3 +29,10 @@ func Deployments() ([]nr.ApplicationDeployment, error) { return deployments, nil } + +func apiKey() string { + return wtf.Config.UString( + "wtf.mods.newrelic.apiKey", + os.Getenv("WTF_NEW_RELIC_API_KEY"), + ) +} diff --git a/newrelic/widget.go b/newrelic/widget.go index 8c4fd8b7..84bdb6bf 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -31,7 +31,7 @@ func (widget *Widget) Refresh() { } widget.UpdateRefreshedAt() - widget.View.SetTitle(fmt.Sprintf("%s- [green]%s[white]", widget.Name, appName)) + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.Name, appName))) widget.View.Clear() var content string