mirror of
https://github.com/niusmallnan/steve.git
synced 2025-06-26 14:41: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 {
|
func (l *AccessStore) CacheKey(user user.Info) string {
|
||||||
|
cacheKey, ok := l.cache.Get(user.GetName())
|
||||||
|
if ok {
|
||||||
|
return cacheKey.(string)
|
||||||
|
}
|
||||||
d := sha256.New()
|
d := sha256.New()
|
||||||
|
|
||||||
l.users.addRolesToHash(d, user.GetName())
|
l.users.addRolesToHash(d, user.GetName())
|
||||||
@ -77,5 +81,7 @@ func (l *AccessStore) CacheKey(user user.Info) string {
|
|||||||
l.groups.addRolesToHash(d, group)
|
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"
|
"time"
|
||||||
|
|
||||||
"github.com/rancher/apiserver/pkg/builtin"
|
"github.com/rancher/apiserver/pkg/builtin"
|
||||||
|
"k8s.io/apimachinery/pkg/api/equality"
|
||||||
|
|
||||||
schemastore "github.com/rancher/apiserver/pkg/store/schema"
|
schemastore "github.com/rancher/apiserver/pkg/store/schema"
|
||||||
"github.com/rancher/apiserver/pkg/types"
|
"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{}
|
inNewSchemas := map[string]bool{}
|
||||||
for _, apiObject := range schemastore.FilterSchemas(apiOp, schemas.Schemas).Objects {
|
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{
|
result <- types.APIEvent{
|
||||||
Name: types.ChangeAPIEvent,
|
Name: eventName,
|
||||||
ResourceType: "schema",
|
ResourceType: "schema",
|
||||||
Object: apiObject,
|
Object: apiObject,
|
||||||
}
|
}
|
||||||
inNewSchemas[apiObject.ID] = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, oldSchema := range schemastore.FilterSchemas(apiOp, oldSchemas.Schemas).Objects {
|
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 {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-time.After(30 * time.Second):
|
case <-time.After(2 * time.Second):
|
||||||
}
|
}
|
||||||
|
|
||||||
newAs := w.asl.AccessFor(user)
|
newAs := w.asl.AccessFor(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user