Skip to content

Commit

Permalink
Merge a10299f into 10e7ce8
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed Aug 1, 2018
2 parents 10e7ce8 + a10299f commit 4175e84
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
4 changes: 1 addition & 3 deletions api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ func (a APIDefinitionLoader) FromDashboardService(endpoint, secret string) ([]*A

newRequest.Header.Set("x-tyk-nonce", ServiceNonce)

c := &http.Client{
Timeout: 120 * time.Second,
}
c := initialiseClient(120 * time.Second)
resp, err := c.Do(newRequest)
if err != nil {
return nil, err
Expand Down
36 changes: 32 additions & 4 deletions dashboard_register.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -36,6 +37,34 @@ type HTTPDashboardHandler struct {
heartBeatStopSentinel bool
}

func initialiseClient(timeout time.Duration) *http.Client {
client := &http.Client{}
if config.Global().HttpServerOptions.UseSSL {
certs := make([]tls.Certificate, len(config.Global().HttpServerOptions.Certificates))
certNameMap := make(map[string]*tls.Certificate)
for i, certData := range config.Global().HttpServerOptions.Certificates {
cert, err := tls.LoadX509KeyPair(certData.CertFile, certData.KeyFile)
if err != nil {
log.Fatalf("Server error: loadkeys: %s", err)
}
certs[i] = cert
certNameMap[certData.Name] = &certs[i]
}
// Setup HTTPS client
tlsConfig := &tls.Config{
Certificates: certs,
InsecureSkipVerify: config.Global().HttpServerOptions.SSLInsecureSkipVerify,
NameToCertificate: certNameMap,
}
transport := &http.Transport{TLSClientConfig: tlsConfig}
client = &http.Client{Transport: transport}

} else {

client = &http.Client{Timeout: timeout}
}
return client
}
func reLogin() {
if !config.Global().UseDBAppConfigs {
return
Expand Down Expand Up @@ -84,8 +113,7 @@ func (h *HTTPDashboardHandler) Init() error {

func (h *HTTPDashboardHandler) Register() error {
req := h.newRequest(h.RegistrationEndpoint)

c := &http.Client{Timeout: 5 * time.Second}
c := initialiseClient(5 * time.Second)
resp, err := c.Do(req)

if err != nil {
Expand Down Expand Up @@ -156,8 +184,8 @@ func (h *HTTPDashboardHandler) sendHeartBeat() error {
req := h.newRequest(h.HeartBeatEndpoint)
req.Header.Set("x-tyk-nodeid", NodeID)
req.Header.Set("x-tyk-nonce", ServiceNonce)
c := initialiseClient(5 * time.Second)

c := &http.Client{Timeout: 5 * time.Second}
resp, err := c.Do(req)
if err != nil || resp.StatusCode != 200 {
return errors.New("dashboard is down? Heartbeat is failing")
Expand All @@ -182,7 +210,7 @@ func (h *HTTPDashboardHandler) DeRegister() error {
req.Header.Set("x-tyk-nodeid", NodeID)
req.Header.Set("x-tyk-nonce", ServiceNonce)

c := &http.Client{Timeout: 5 * time.Second}
c := initialiseClient(5 * time.Second)
resp, err := c.Do(req)

if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func LoadPoliciesFromDashboard(endpoint, secret string, allowExplicit bool) map[
log.WithFields(logrus.Fields{
"prefix": "policy",
}).Info("Mutex lock acquired... calling")
c := &http.Client{
Timeout: 10 * time.Second,
}
c := initialiseClient(10 * time.Second)

log.WithFields(logrus.Fields{
"prefix": "policy",
Expand Down

0 comments on commit 4175e84

Please sign in to comment.