Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Buhr committed Aug 7, 2014
1 parent 82695eb commit 874b1cd
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 38 deletions.
6 changes: 3 additions & 3 deletions api_definition_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"net/http"
"net/url"
"path/filepath"
"regexp"
"strings"
"time"
"net/url"
)

// APIDefinition represents the configuration for a single proxied API and it's versions.
Expand All @@ -34,7 +34,7 @@ type APIDefinition struct {
Key string `bson:"key" json:"key"`
} `bson:"definition" json:"definition"`
EnableSignatureChecking bool `bson:"enable_signature_checking" json:"enable_signature_checking"`
VersionData struct {
VersionData struct {
NotVersioned bool `bson:"not_versioned" json:"not_versioned"`
Versions map[string]VersionInfo `bson:"versions" json:"versions"`
} `bson:"version_data" json:"version_data"`
Expand Down Expand Up @@ -102,7 +102,7 @@ type APISpec struct {
APIDefinition
RxPaths map[string][]URLSpec
WhiteListEnabled map[string]bool
target *url.URL
target *url.URL
}

// APIDefinitionLoader will load an Api definition from a storage system. It has two methods LoadDefinitionsFromMongo()
Expand Down
5 changes: 2 additions & 3 deletions auth_manager.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"encoding/base64"
"encoding/json"
"time"
"github.com/nu7hatch/gouuid"
"strings"
"encoding/base64"
"time"
)

// AuthorisationHandler is used to validate a session key,
Expand Down Expand Up @@ -99,6 +99,5 @@ func (b AuthorisationManager) GenerateHMACSecret() string {
cleanSting := strings.Replace(u5.String(), "-", "", -1)
newSecret := base64.StdEncoding.EncodeToString([]byte(cleanSting))


return newSecret
}
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Config struct {
Secret string `json:"secret"`
TemplatePath string `json:"template_path"`
UseDBAppConfigs bool `json:"use_db_app_configs"`
AppPath string `json:"app_path"`
AppPath string `json:"app_path"`
Storage struct {
Type string `json:"type"`
Host string `json:"host"`
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ func init() {
log.Debug("Enabling debug-level output")
}


}

func main() {
Expand Down
14 changes: 7 additions & 7 deletions middleware_access_rights.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func (a AccessRightsCheck) New() func(http.Handler) http.Handler {
versionList, apiExists := thisSessionState.AccessRights[a.Spec.APIID]
if !apiExists {
log.WithFields(logrus.Fields{
"path": r.URL.Path,
"origin": r.RemoteAddr,
"key": authHeaderValue,
"path": r.URL.Path,
"origin": r.RemoteAddr,
"key": authHeaderValue,
"api_found": false,
}).Info("Attempted access to unauthorised API.")
handler := ErrorHandler{a.TykMiddleware}
Expand All @@ -56,10 +56,10 @@ func (a AccessRightsCheck) New() func(http.Handler) http.Handler {
if !found {
// Not found? Bounce
log.WithFields(logrus.Fields{
"path": r.URL.Path,
"origin": r.RemoteAddr,
"key": authHeaderValue,
"api_found": true,
"path": r.URL.Path,
"origin": r.RemoteAddr,
"key": authHeaderValue,
"api_found": true,
"version_found": false,
}).Info("Attempted access to unauthorised API version.")
handler := ErrorHandler{a.TykMiddleware}
Expand Down
18 changes: 9 additions & 9 deletions middleware_check_HMAC_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package main
import "net/http"

import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"github.com/Sirupsen/logrus"
"github.com/gorilla/context"
"strings"
"math"
"net/url"
"sort"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"strings"
"time"
"math"
)

// Test key: 53ac07777cbb8c2d530000021a42331a43bd45555d5c923bdb36fc8a
Expand Down Expand Up @@ -100,7 +100,7 @@ func (hm HMACMiddleware) New() func(http.Handler) http.Handler {
keyId := ""
algorithm := ""
signature := ""
for _, v := range(splitValues) {
for _, v := range splitValues {
splitKeyValuePair := strings.Split(v, "=")
if len(splitKeyValuePair) != 2 {
hm.authorizationError(w, r)
Expand Down Expand Up @@ -194,12 +194,12 @@ func (hm HMACMiddleware) parseFormParams(values url.Values) string {

log.Debug("Parsing header values")

for k, v := range(values) {
for k, v := range values {
log.Debug("Form parser - processing key: ", k)
log.Debug("Form parser - processing value: ", v)
encodedKey := url.QueryEscape(k)
encodedVals := []string{}
for _, raw_value := range(v) {
for _, raw_value := range v {
encodedVals = append(encodedVals, url.QueryEscape(raw_value))
}
joined_vals := strings.Join(encodedVals, "|")
Expand All @@ -213,7 +213,7 @@ func (hm HMACMiddleware) parseFormParams(values url.Values) string {
sortedKvs := []string{}

// Put the prepared key value params in order according to above sort
for _, sk := range(keys) {
for _, sk := range keys {
sortedKvs = append(sortedKvs, kvValues[sk])
}

Expand Down
14 changes: 5 additions & 9 deletions oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ const (
// NewOAuthNotification is a notification sent to a
// webhook when an access request or a refresh request comes in.
type NewOAuthNotification struct {
AuthCode string
NewOAuthToken string
RefreshToken string
OldRefreshToken string
NotificationType OAuthNotificationType
AuthCode string `json:"auth_code"`
NewOAuthToken string `json:"new_oauth_token"`
RefreshToken string `json:"refresh_token"`
OldRefreshToken string `json:"old_refresh_token"`
NotificationType OAuthNotificationType `json:"notification_type"`
}

// OAuthHandlers are the HTTP Handlers that manage the Tyk OAuth flow
Expand Down Expand Up @@ -385,7 +385,6 @@ func (r RedisOsinStorageInterface) SaveAuthorize(authData *osin.AuthorizeData) e

}


}

// LoadAuthorize loads auth data from redis
Expand Down Expand Up @@ -446,8 +445,6 @@ func (r RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) error

authManager.UpdateSession(accessData.AccessToken, newSession)



// Store the refresh token too
if accessData.RefreshToken != "" {
if accessDataJSON, marshalErr := json.Marshal(&accessData); marshalErr != nil {
Expand All @@ -459,7 +456,6 @@ func (r RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) error
return nil
}


}

return nil
Expand Down
4 changes: 2 additions & 2 deletions session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type SessionState struct {
BasicAuthData struct {
Password string `json:"password"`
} `json:"basic_auth_data"`
HMACEnabled bool `json:"hmac_enabled"`
HmacSecret string `json:"hmac_string"`
HMACEnabled bool `json:"hmac_enabled"`
HmacSecret string `json:"hmac_string"`
}

// SessionLimiter is the rate limiter for the API, use ForwardMessage() to
Expand Down
4 changes: 1 addition & 3 deletions tykReverseProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ package main

import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
"net/http/httputil"
)


// Copied form the original stdlib for ReverseProxy
func singleJoiningSlash(a, b string) string {
aslash := strings.HasSuffix(a, "/")
Expand Down Expand Up @@ -48,4 +47,3 @@ func TykNewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
}
return &httputil.ReverseProxy{Director: director}
}

0 comments on commit 874b1cd

Please sign in to comment.