From 5cf35b3617affabb3fc1d3580a4a09cc28328419 Mon Sep 17 00:00:00 2001 From: dencoded <33698537+dencoded@users.noreply.github.com> Date: Tue, 27 Feb 2018 00:18:10 -0500 Subject: [PATCH] added more logging when applying policies to a key --- middleware.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/middleware.go b/middleware.go index 0a472bd899e..3acd8e531c8 100644 --- a/middleware.go +++ b/middleware.go @@ -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 @@ -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 @@ -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