Skip to content

Commit

Permalink
all: various cleanups and simplifications
Browse files Browse the repository at this point in the history
I had been stashing these bit by bit over the last couple of weeks,
since they were too small to submit separately.
  • Loading branch information
mvdan authored and buger committed Nov 3, 2017
1 parent bdae5a4 commit 92ac12c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,13 @@ func loadCustomMiddleware(spec *APISpec) ([]string, apidef.MiddlewareDefinition,
"prefix": "main",
}).Debug("Loading file middleware from ", path)

mwDef := apidef.MiddlewareDefinition{}
mwDef.Name = strings.Split(filepath.Base(path), ".")[0]
mwDef := apidef.MiddlewareDefinition{
Name: strings.Split(filepath.Base(path), ".")[0],
Path: path,
}
log.WithFields(logrus.Fields{
"prefix": "main",
}).Debug("-- Middleware name ", mwDef.Name)
mwDef.Path = path
mwDef.RequireSession = strings.HasSuffix(mwDef.Name, "_with_session")
if mwDef.RequireSession {
switch folder.name {
Expand Down
5 changes: 1 addition & 4 deletions mw_hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ func (hm *HMACMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request,
encodedSignature := generateEncodedSignature(signatureString, secret)

// Compare
matchPass := false
if encodedSignature == fieldValues.Signature {
matchPass = true
}
matchPass := encodedSignature == fieldValues.Signature

// Check for lower case encoding (.Net issues, again)
if !matchPass {
Expand Down
9 changes: 3 additions & 6 deletions oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,7 @@ func (r *RedisOsinStorageInterface) LoadAuthorize(code string) (*osin.AuthorizeD
return nil, err
}

authData := osin.AuthorizeData{}
authData.Client = new(OAuthClient)
authData := osin.AuthorizeData{Client: new(OAuthClient)}
if err := json.Unmarshal([]byte(authJSON), &authData); err != nil {
log.Error("Couldn't unmarshal OAuth auth data object (LoadAuthorize): ", err)
return nil, err
Expand Down Expand Up @@ -646,8 +645,7 @@ func (r *RedisOsinStorageInterface) LoadAccess(token string) (*osin.AccessData,
return nil, err
}

accessData := osin.AccessData{}
accessData.Client = new(OAuthClient)
accessData := osin.AccessData{Client: new(OAuthClient)}
if err := json.Unmarshal([]byte(accessJSON), &accessData); err != nil {
log.Error("Couldn't unmarshal OAuth auth data object (LoadAccess): ", err)
return nil, err
Expand Down Expand Up @@ -679,8 +677,7 @@ func (r *RedisOsinStorageInterface) LoadRefresh(token string) (*osin.AccessData,
}

// new interface means having to make this nested... ick.
accessData := osin.AccessData{}
accessData.Client = new(OAuthClient)
accessData := osin.AccessData{Client: new(OAuthClient)}
if err := json.Unmarshal([]byte(accessJSON), &accessData); err != nil {
log.Error("Couldn't unmarshal OAuth auth data object (LoadRefresh): ", err,
"; Decoding: ", accessJSON)
Expand Down
7 changes: 2 additions & 5 deletions reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ func urlFromService(spec *APISpec) (*apidef.HostList, error) {
doCacheRefresh := func() (*apidef.HostList, error) {
log.Debug("--> Refreshing")
spec.ServiceRefreshInProgress = true
defer func() { spec.ServiceRefreshInProgress = false }()
sd := ServiceDiscovery{}
sd.Init(&spec.Proxy.ServiceDiscovery)
data, err := sd.Target(spec.Proxy.ServiceDiscovery.QueryEndpoint)
if err != nil {
spec.ServiceRefreshInProgress = false
return nil, err
}
spec.HasRun = true
// Set the cached value
if data.Len() == 0 {
spec.HasRun = true
spec.ServiceRefreshInProgress = false
log.Warning("[PROXY][SD] Service Discovery returned empty host list! Returning last good set.")

if spec.LastGoodHostList == nil {
Expand All @@ -68,8 +67,6 @@ func urlFromService(spec *APISpec) (*apidef.HostList, error) {
ServiceCache.Set(spec.APIID, data, cache.DefaultExpiration)
// Stash it too
spec.LastGoodHostList = data
spec.HasRun = true
spec.ServiceRefreshInProgress = false
return data, nil
}

Expand Down
16 changes: 0 additions & 16 deletions service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,17 @@ const mesosphere = `{
func configureService(name string, sd *ServiceDiscovery) string {
switch name {
case "consul":
sd.isNested = false
sd.isTargetList = true
sd.endpointReturnsList = true
sd.portSeperate = true
sd.dataPath = "Address"
sd.parentPath = ""
sd.portPath = "ServicePort"
return consul
case "etcd":
sd.isNested = false
sd.isTargetList = false
sd.endpointReturnsList = false
sd.portSeperate = false
sd.dataPath = "node.value"
sd.parentPath = ""
sd.portPath = ""
return etcd
case "nested":
sd.isNested = true
sd.isTargetList = false
sd.endpointReturnsList = false
sd.portSeperate = true
sd.dataPath = "hostname"
sd.parentPath = "node.value"
Expand All @@ -189,7 +179,6 @@ func configureService(name string, sd *ServiceDiscovery) string {
case "nested_list":
sd.isNested = true
sd.isTargetList = true
sd.endpointReturnsList = false
sd.portSeperate = true
sd.dataPath = "hostname"
sd.parentPath = "node.value"
Expand All @@ -205,25 +194,20 @@ func configureService(name string, sd *ServiceDiscovery) string {
sd.portPath = "port"
return nested_consul
case "mesosphere":
sd.isNested = false
sd.isTargetList = true
sd.endpointReturnsList = false
sd.portSeperate = true
sd.dataPath = "host"
sd.parentPath = "tasks"
sd.portPath = "ports"
return mesosphere
case "eureka":
sd.isNested = false
sd.isTargetList = true
sd.endpointReturnsList = false
sd.portSeperate = true
sd.dataPath = "hostName"
sd.parentPath = "application.instance"
sd.portPath = "port.$"
return eureka_real
}

return ""
}

Expand Down

0 comments on commit 92ac12c

Please sign in to comment.