Skip to content

Commit

Permalink
added more logging when applying policies to a key
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded authored and buger committed Feb 28, 2018
1 parent 62a7a91 commit 5cf35b3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,25 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er
policy, ok := policiesByID[polID]
policiesMu.RUnlock()
if !ok {
return fmt.Errorf("policy not found: %q", polID)
err := fmt.Errorf("policy not found: %q", polID)
log.Error(err)
return err
}
// Check ownership, policy org owner must be the same as API,
// otherwise youcould overwrite a session key with a policy from a different org!
if policy.OrgID != t.Spec.OrgID {
return fmt.Errorf("attempting to apply policy from different organisation to key, skipping")
err := fmt.Errorf("attempting to apply policy from different organisation to key, skipping")
log.Error(err)
return err
}

if policy.Partitions.Quota || policy.Partitions.RateLimit || policy.Partitions.Acl {
// This is a partitioned policy, only apply what is active
if policy.Partitions.Quota {
if didQuota {
return fmt.Errorf("cannot apply multiple quota policies")
err := fmt.Errorf("cannot apply multiple quota policies")
log.Error(err)
return err
}
didQuota = true
// Quotas
Expand All @@ -196,7 +202,9 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er

if policy.Partitions.RateLimit {
if didRateLimit {
return fmt.Errorf("cannot apply multiple rate limit policies")
err := fmt.Errorf("cannot apply multiple rate limit policies")
log.Error(err)
return err
}
didRateLimit = true
// Rate limting
Expand All @@ -223,7 +231,9 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er

} else {
if len(policies) > 1 {
return fmt.Errorf("cannot apply multiple policies if any are non-partitioned")
err := fmt.Errorf("cannot apply multiple policies if any are non-partitioned")
log.Error(err)
return err
}
// This is not a partitioned policy, apply everything
// Quotas
Expand Down

0 comments on commit 5cf35b3

Please sign in to comment.