Skip to content

Commit

Permalink
all: rename publicHash to hashKey
Browse files Browse the repository at this point in the history
And replace a copy-pasted version of it with a call.
  • Loading branch information
mvdan authored and buger committed Sep 19, 2017
1 parent 18feef7 commit 9ee791f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *RedisAnalyticsHandler) RecordHit(record AnalyticsRecord) error {

r.AnalyticsPool.SendWork(func() {
// If we are obfuscating API Keys, store the hashed representation (config check handled in hashing function)
record.APIKey = publicHash(record.APIKey)
record.APIKey = hashKey(record.APIKey)

if config.Global.SlaveOptions.UseRPC {
// Extend tag list to include this data so wecan segment by node if necessary
Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func handleOrgAddOrUpdate(keyName string, r *http.Request) (interface{}, int) {
if r.URL.Query().Get("reset_quota") == "1" {
sessionManager.ResetQuota(keyName, newSession)
newSession.QuotaRenews = time.Now().Unix() + newSession.QuotaRenewalRate
rawKey := QuotaKeyPrefix + publicHash(keyName)
rawKey := QuotaKeyPrefix + hashKey(keyName)

// manage quotas separately
DefaultQuotaStore.RemoveSession(rawKey)
Expand Down
4 changes: 2 additions & 2 deletions auth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func (b *DefaultSessionManager) Store() StorageHandler {

func (b *DefaultSessionManager) ResetQuota(keyName string, session *SessionState) {

rawKey := QuotaKeyPrefix + publicHash(keyName)
rawKey := QuotaKeyPrefix + hashKey(keyName)
log.WithFields(logrus.Fields{
"prefix": "auth-mgr",
"inbound-key": ObfuscateKeyString(keyName),
"key": rawKey,
}).Info("Reset quota for key.")

rateLimiterSentinelKey := RateLimitKeyPrefix + publicHash(keyName) + ".BLOCKED"
rateLimiterSentinelKey := RateLimitKeyPrefix + hashKey(keyName) + ".BLOCKED"
// Clear the rate limiter
go b.store.DeleteRawKey(rateLimiterSentinelKey)
// Fix the raw key
Expand Down
9 changes: 1 addition & 8 deletions oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

/*
Sample Oaut Flow:
-----------------
Expand All @@ -34,7 +33,6 @@ Effort required by Resource Owner:
1. Create a login & approve/deny page
2. Send an API request to Tyk to generate an auth_code
3. Create endpoint to accept key change notifications
*/

// OAuthClient is a representation within an APISpec of a client
Expand Down Expand Up @@ -249,12 +247,7 @@ func (o *OAuthManager) HandleAccess(r *http.Request) *osin.Response {
if ar.Type == osin.PASSWORD {
username = r.Form.Get("username")
password := r.Form.Get("password")
keyName := o.API.OrgID + username
if config.Global.HashKeys {
// HASHING? FIX THE KEY
keyName = doHash(keyName)
}
searchKey := "apikey-" + keyName
searchKey := "apikey-" + hashKey(o.API.OrgID+username)
log.Debug("Getting: ", searchKey)

var err error
Expand Down
6 changes: 3 additions & 3 deletions session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const (
// Key values to manage rate are Rate and Per, e.g. Rate of 10 messages
// Per 10 seconds
func (l *SessionLimiter) ForwardMessage(currentSession *SessionState, key string, store StorageHandler, enableRL, enableQ bool) sessionFailReason {
rateLimiterKey := RateLimitKeyPrefix + publicHash(key)
rateLimiterSentinelKey := RateLimitKeyPrefix + publicHash(key) + ".BLOCKED"
rateLimiterKey := RateLimitKeyPrefix + hashKey(key)
rateLimiterSentinelKey := RateLimitKeyPrefix + hashKey(key) + ".BLOCKED"

if enableRL {
if config.Global.EnableSentinelRateLImiter {
Expand Down Expand Up @@ -150,7 +150,7 @@ func (l *SessionLimiter) IsRedisQuotaExceeded(currentSession *SessionState, key

// Create the key
log.Debug("[QUOTA] Inbound raw key is: ", key)
rawKey := QuotaKeyPrefix + publicHash(key)
rawKey := QuotaKeyPrefix + hashKey(key)
log.Debug("[QUOTA] Quota limiter key is: ", rawKey)
log.Debug("Renewing with TTL: ", currentSession.QuotaRenewalRate)
// INCR the key (If it equals 1 - set EXPIRE)
Expand Down
2 changes: 1 addition & 1 deletion storage_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func doHash(in string) string {
}

//Public function for use in classes that bypass elements of the storage manager
func publicHash(in string) string {
func hashKey(in string) string {
if !config.Global.HashKeys {
// Not hashing? Return the raw key
return in
Expand Down

0 comments on commit 9ee791f

Please sign in to comment.