2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2019-10-24 18:38:09 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package authmethod
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type syncCache struct {
|
|
|
|
lock sync.RWMutex
|
|
|
|
cache authMethodCache
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCache() Cache {
|
|
|
|
c := &syncCache{}
|
|
|
|
c.cache.init()
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *syncCache) GetValidator(method *structs.ACLAuthMethod) (uint64, Validator, bool) {
|
|
|
|
c.lock.RLock()
|
|
|
|
defer c.lock.RUnlock()
|
|
|
|
return c.cache.GetValidator(method)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *syncCache) PutValidatorIfNewer(method *structs.ACLAuthMethod, validator Validator, idx uint64) Validator {
|
|
|
|
c.lock.Lock()
|
|
|
|
defer c.lock.Unlock()
|
|
|
|
return c.cache.PutValidatorIfNewer(method, validator, idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *syncCache) Purge() {
|
|
|
|
c.lock.Lock()
|
2020-05-01 22:35:28 +00:00
|
|
|
defer c.lock.Unlock()
|
2019-10-24 18:38:09 +00:00
|
|
|
c.cache.Purge()
|
|
|
|
}
|