Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
google auth for /metrics endpoint should depend on config values, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf committed Apr 11, 2019
1 parent 6d989c8 commit 860d76b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,34 +467,36 @@ func runTradeCmd(options inputs) {
}

func startMonitoringServer(l logger.Logger, botConfig trader.BotConfig) error {
serverConfig := &networking.Config{
GoogleClientID: botConfig.GoogleClientID,
GoogleClientSecret: botConfig.GoogleClientSecret,
PermittedEmails: map[string]bool{},
}
// Load acceptable Google emails into the map
for _, email := range strings.Split(botConfig.AcceptableEmails, ",") {
serverConfig.PermittedEmails[email] = true
}

healthMetrics, e := monitoring.MakeMetricsRecorder(map[string]interface{}{"success": true})
if e != nil {
return fmt.Errorf("unable to make metrics recorder for the health endpoint: %s", e)
return fmt.Errorf("unable to make metrics recorder for the /health endpoint: %s", e)
}

healthEndpoint, e := monitoring.MakeMetricsEndpoint("/health", healthMetrics, networking.NoAuth)
if e != nil {
return fmt.Errorf("unable to make /health endpoint: %s", e)
}

kelpMetrics, e := monitoring.MakeMetricsRecorder(nil)
if e != nil {
return fmt.Errorf("unable to make metrics recorder for the /metrics endpoint: %s", e)
}

metricsEndpoint, e := monitoring.MakeMetricsEndpoint("/metrics", kelpMetrics, networking.GoogleAuth)
metricsAuth := networking.NoAuth
if botConfig.GoogleClientID != "" || botConfig.GoogleClientSecret != "" {
metricsAuth = networking.GoogleAuth
}
metricsEndpoint, e := monitoring.MakeMetricsEndpoint("/metrics", kelpMetrics, metricsAuth)
if e != nil {
return fmt.Errorf("unable to make /metrics endpoint: %s", e)
}

serverConfig := &networking.Config{
GoogleClientID: botConfig.GoogleClientID,
GoogleClientSecret: botConfig.GoogleClientSecret,
PermittedEmails: map[string]bool{},
}
for _, email := range strings.Split(botConfig.AcceptableEmails, ",") {
serverConfig.PermittedEmails[email] = true
}
server, e := networking.MakeServer(serverConfig, []networking.Endpoint{healthEndpoint, metricsEndpoint})
if e != nil {
return fmt.Errorf("unable to initialize the metrics server: %s", e)
Expand Down

0 comments on commit 860d76b

Please sign in to comment.