mirror of
https://github.com/niusmallnan/steve.git
synced 2025-06-25 22:21:35 +00:00
Cleanup schema change reporting
This commit is contained in:
parent
bb76e4db56
commit
9f5d802708
@ -64,6 +64,10 @@ func (l *AccessStore) AccessFor(user user.Info) *AccessSet {
|
||||
}
|
||||
|
||||
func (l *AccessStore) CacheKey(user user.Info) string {
|
||||
cacheKey, ok := l.cache.Get(user.GetName())
|
||||
if ok {
|
||||
return cacheKey.(string)
|
||||
}
|
||||
d := sha256.New()
|
||||
|
||||
l.users.addRolesToHash(d, user.GetName())
|
||||
@ -77,5 +81,7 @@ func (l *AccessStore) CacheKey(user user.Info) string {
|
||||
l.groups.addRolesToHash(d, group)
|
||||
}
|
||||
|
||||
return hex.EncodeToString(d.Sum(nil))
|
||||
cacheKey = hex.EncodeToString(d.Sum(nil))
|
||||
l.cache.Add(user.GetName(), cacheKey, 2*time.Second)
|
||||
return cacheKey.(string)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rancher/apiserver/pkg/builtin"
|
||||
"k8s.io/apimachinery/pkg/api/equality"
|
||||
|
||||
schemastore "github.com/rancher/apiserver/pkg/store/schema"
|
||||
"github.com/rancher/apiserver/pkg/types"
|
||||
@ -96,12 +97,24 @@ func (s *Store) sendSchemas(result chan types.APIEvent, apiOp *types.APIRequest,
|
||||
|
||||
inNewSchemas := map[string]bool{}
|
||||
for _, apiObject := range schemastore.FilterSchemas(apiOp, schemas.Schemas).Objects {
|
||||
inNewSchemas[apiObject.ID] = true
|
||||
eventName := types.ChangeAPIEvent
|
||||
if oldSchema := oldSchemas.LookupSchema(apiObject.ID); oldSchema == nil {
|
||||
eventName = types.CreateAPIEvent
|
||||
} else {
|
||||
newSchemaCopy := apiObject.Object.(*types.APISchema).Schema.DeepCopy()
|
||||
oldSchemaCopy := oldSchema.Schema.DeepCopy()
|
||||
newSchemaCopy.Mapper = nil
|
||||
oldSchemaCopy.Mapper = nil
|
||||
if equality.Semantic.DeepEqual(newSchemaCopy, oldSchemaCopy) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
result <- types.APIEvent{
|
||||
Name: types.ChangeAPIEvent,
|
||||
Name: eventName,
|
||||
ResourceType: "schema",
|
||||
Object: apiObject,
|
||||
}
|
||||
inNewSchemas[apiObject.ID] = true
|
||||
}
|
||||
|
||||
for _, oldSchema := range schemastore.FilterSchemas(apiOp, oldSchemas.Schemas).Objects {
|
||||
|
@ -29,7 +29,7 @@ func (w *WatchRefresh) Watch(apiOp *types.APIRequest, schema *types.APISchema, w
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(30 * time.Second):
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
|
||||
newAs := w.asl.AccessFor(user)
|
||||
|
Loading…
Reference in New Issue
Block a user