mirror of
https://github.com/niusmallnan/steve.git
synced 2025-07-25 19:33:14 +00:00
test access control cache
This commit is contained in:
parent
2c645b3680
commit
18ce669a80
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1"
|
v1 "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"k8s.io/apimachinery/pkg/util/cache"
|
"k8s.io/apimachinery/pkg/util/cache"
|
||||||
"k8s.io/apiserver/pkg/authentication/user"
|
"k8s.io/apiserver/pkg/authentication/user"
|
||||||
)
|
)
|
||||||
@ -40,16 +41,21 @@ func NewAccessStore(ctx context.Context, cacheResults bool, rbac v1.Interface) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *AccessStore) AccessFor(user user.Info) *AccessSet {
|
func (l *AccessStore) AccessFor(user user.Info) *AccessSet {
|
||||||
|
logrus.Infof("******* AccessFor user: %+v", user)
|
||||||
var cacheKey string
|
var cacheKey string
|
||||||
if l.cache != nil {
|
if l.cache != nil {
|
||||||
|
logrus.Infof("******* AccessFor cache size: %d", len(l.cache.Keys()))
|
||||||
cacheKey = l.CacheKey(user)
|
cacheKey = l.CacheKey(user)
|
||||||
|
logrus.Infof("******* AccessFor try cache via key: %s", cacheKey)
|
||||||
val, ok := l.cache.Get(cacheKey)
|
val, ok := l.cache.Get(cacheKey)
|
||||||
if ok {
|
if ok {
|
||||||
|
logrus.Infof("******* AccessFor got cache via key: %s", cacheKey)
|
||||||
as, _ := val.(*AccessSet)
|
as, _ := val.(*AccessSet)
|
||||||
return as
|
return as
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Info("******* AccessFor generate results")
|
||||||
result := l.users.get(user.GetName())
|
result := l.users.get(user.GetName())
|
||||||
for _, group := range user.GetGroups() {
|
for _, group := range user.GetGroups() {
|
||||||
result.Merge(l.groups.get(group))
|
result.Merge(l.groups.get(group))
|
||||||
@ -58,6 +64,7 @@ func (l *AccessStore) AccessFor(user user.Info) *AccessSet {
|
|||||||
if l.cache != nil {
|
if l.cache != nil {
|
||||||
result.ID = cacheKey
|
result.ID = cacheKey
|
||||||
l.cache.Add(cacheKey, result, 24*time.Hour)
|
l.cache.Add(cacheKey, result, 24*time.Hour)
|
||||||
|
logrus.Infof("******* AccessFor add cache to key: %s", cacheKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user