Add nil check for quota manager (#9379)

* Add nil check for quota manager

* Add missing nil checks
This commit is contained in:
Alexander Bezobchuk 2020-07-01 21:14:33 -04:00 committed by GitHub
parent cf94e19b03
commit f1534a0ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

View File

@ -339,9 +339,11 @@ func (c *Core) disableCredentialInternal(ctx context.Context, path string, updat
removePathCheckers(c, entry, viewPath) removePathCheckers(c, entry, viewPath)
if err := c.quotaManager.HandleBackendDisabling(ctx, ns.Path, path); err != nil { if c.quotaManager != nil {
c.logger.Error("failed to update quotas after disabling auth", "path", path, "error", err) if err := c.quotaManager.HandleBackendDisabling(ctx, ns.Path, path); err != nil {
return err c.logger.Error("failed to update quotas after disabling auth", "path", path, "error", err)
return err
}
} }
if c.logger.IsInfo() { if c.logger.IsInfo() {

View File

@ -1838,8 +1838,10 @@ func (c *Core) sealInternalWithOptions(grabStateLock, keepHALock, performCleanup
} }
} }
if err := c.quotaManager.Reset(); err != nil { if c.quotaManager != nil {
c.logger.Error("error resetting quota manager", "error", err) if err := c.quotaManager.Reset(); err != nil {
c.logger.Error("error resetting quota manager", "error", err)
}
} }
postSealInternal(c) postSealInternal(c)
@ -2526,11 +2528,19 @@ func (c *Core) setupQuotas(ctx context.Context, isPerfStandby bool) error {
// ApplyRateLimitQuota checks the request against all the applicable quota rules // ApplyRateLimitQuota checks the request against all the applicable quota rules
func (c *Core) ApplyRateLimitQuota(req *quotas.Request) (quotas.Response, error) { func (c *Core) ApplyRateLimitQuota(req *quotas.Request) (quotas.Response, error) {
req.Type = quotas.TypeRateLimit req.Type = quotas.TypeRateLimit
return c.quotaManager.ApplyQuota(req) if c.quotaManager != nil {
return c.quotaManager.ApplyQuota(req)
}
return quotas.Response{Allowed: true}, nil
} }
// RateLimitAuditLoggingEnabled returns if the quota configuration allows audit // RateLimitAuditLoggingEnabled returns if the quota configuration allows audit
// logging of request rejections due to rate limiting quota rule violations. // logging of request rejections due to rate limiting quota rule violations.
func (c *Core) RateLimitAuditLoggingEnabled() bool { func (c *Core) RateLimitAuditLoggingEnabled() bool {
return c.quotaManager.RateLimitAuditLoggingEnabled() if c.quotaManager != nil {
return c.quotaManager.RateLimitAuditLoggingEnabled()
}
return false
} }

View File

@ -664,9 +664,11 @@ func (c *Core) unmountInternal(ctx context.Context, path string, updateStorage b
removePathCheckers(c, entry, viewPath) removePathCheckers(c, entry, viewPath)
if err := c.quotaManager.HandleBackendDisabling(ctx, ns.Path, path); err != nil { if c.quotaManager != nil {
c.logger.Error("failed to update quotas after disabling mount", "path", path, "error", err) if err := c.quotaManager.HandleBackendDisabling(ctx, ns.Path, path); err != nil {
return err c.logger.Error("failed to update quotas after disabling mount", "path", path, "error", err)
return err
}
} }
if c.logger.IsInfo() { if c.logger.IsInfo() {