From c9525c83edd23545ba707c57529e0505082bceb0 Mon Sep 17 00:00:00 2001 From: xilabao Date: Thu, 8 Dec 2016 15:06:41 +0800 Subject: [PATCH] remove wrapUpdatedObjectInfo from rbac storage --- .../rbac/clusterrole/policybased/storage.go | 25 +------------------ .../clusterrolebinding/policybased/storage.go | 25 +------------------ pkg/registry/rbac/role/policybased/storage.go | 25 +------------------ .../rbac/rolebinding/policybased/storage.go | 25 +------------------ 4 files changed, 4 insertions(+), 96 deletions(-) diff --git a/pkg/registry/rbac/clusterrole/policybased/storage.go b/pkg/registry/rbac/clusterrole/policybased/storage.go index 17cc672269..178c5d5195 100644 --- a/pkg/registry/rbac/clusterrole/policybased/storage.go +++ b/pkg/registry/rbac/clusterrole/policybased/storage.go @@ -57,7 +57,7 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, obj) } - nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { + nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { clusterRole := obj.(*rbac.ClusterRole) rules := clusterRole.Rules @@ -69,26 +69,3 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) } - -// TODO(ericchiang): This logic is copied from #26240. Replace with once that PR is merged into master. -type wrappedUpdatedObjectInfo struct { - objInfo rest.UpdatedObjectInfo - - transformFunc rest.TransformFunc -} - -func wrapUpdatedObjectInfo(objInfo rest.UpdatedObjectInfo, transformFunc rest.TransformFunc) rest.UpdatedObjectInfo { - return &wrappedUpdatedObjectInfo{objInfo, transformFunc} -} - -func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions { - return i.objInfo.Preconditions() -} - -func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) { - obj, err := i.objInfo.UpdatedObject(ctx, oldObj) - if err != nil { - return obj, err - } - return i.transformFunc(ctx, obj, oldObj) -} diff --git a/pkg/registry/rbac/clusterrolebinding/policybased/storage.go b/pkg/registry/rbac/clusterrolebinding/policybased/storage.go index 0190a0baaf..5d79346a3d 100644 --- a/pkg/registry/rbac/clusterrolebinding/policybased/storage.go +++ b/pkg/registry/rbac/clusterrolebinding/policybased/storage.go @@ -60,7 +60,7 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, obj) } - nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { + nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { clusterRoleBinding := obj.(*rbac.ClusterRoleBinding) rules, err := s.ruleResolver.GetRoleReferenceRules(clusterRoleBinding.RoleRef, clusterRoleBinding.Namespace) @@ -75,26 +75,3 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) } - -// TODO(ericchiang): This logic is copied from #26240. Replace with once that PR is merged into master. -type wrappedUpdatedObjectInfo struct { - objInfo rest.UpdatedObjectInfo - - transformFunc rest.TransformFunc -} - -func wrapUpdatedObjectInfo(objInfo rest.UpdatedObjectInfo, transformFunc rest.TransformFunc) rest.UpdatedObjectInfo { - return &wrappedUpdatedObjectInfo{objInfo, transformFunc} -} - -func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions { - return i.objInfo.Preconditions() -} - -func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) { - obj, err := i.objInfo.UpdatedObject(ctx, oldObj) - if err != nil { - return obj, err - } - return i.transformFunc(ctx, obj, oldObj) -} diff --git a/pkg/registry/rbac/role/policybased/storage.go b/pkg/registry/rbac/role/policybased/storage.go index 23e1f8734b..c6bb36cb57 100644 --- a/pkg/registry/rbac/role/policybased/storage.go +++ b/pkg/registry/rbac/role/policybased/storage.go @@ -57,7 +57,7 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, obj) } - nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { + nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { role := obj.(*rbac.Role) rules := role.Rules @@ -69,26 +69,3 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) } - -// TODO(ericchiang): This logic is copied from #26240. Replace with once that PR is merged into master. -type wrappedUpdatedObjectInfo struct { - objInfo rest.UpdatedObjectInfo - - transformFunc rest.TransformFunc -} - -func wrapUpdatedObjectInfo(objInfo rest.UpdatedObjectInfo, transformFunc rest.TransformFunc) rest.UpdatedObjectInfo { - return &wrappedUpdatedObjectInfo{objInfo, transformFunc} -} - -func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions { - return i.objInfo.Preconditions() -} - -func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) { - obj, err := i.objInfo.UpdatedObject(ctx, oldObj) - if err != nil { - return obj, err - } - return i.transformFunc(ctx, obj, oldObj) -} diff --git a/pkg/registry/rbac/rolebinding/policybased/storage.go b/pkg/registry/rbac/rolebinding/policybased/storage.go index db9261fe74..4962d5a78b 100644 --- a/pkg/registry/rbac/rolebinding/policybased/storage.go +++ b/pkg/registry/rbac/rolebinding/policybased/storage.go @@ -60,7 +60,7 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, obj) } - nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { + nonEscalatingInfo := rest.WrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) { roleBinding := obj.(*rbac.RoleBinding) rules, err := s.ruleResolver.GetRoleReferenceRules(roleBinding.RoleRef, roleBinding.Namespace) @@ -75,26 +75,3 @@ func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInf return s.StandardStorage.Update(ctx, name, nonEscalatingInfo) } - -// TODO(ericchiang): This logic is copied from #26240. Replace with once that PR is merged into master. -type wrappedUpdatedObjectInfo struct { - objInfo rest.UpdatedObjectInfo - - transformFunc rest.TransformFunc -} - -func wrapUpdatedObjectInfo(objInfo rest.UpdatedObjectInfo, transformFunc rest.TransformFunc) rest.UpdatedObjectInfo { - return &wrappedUpdatedObjectInfo{objInfo, transformFunc} -} - -func (i *wrappedUpdatedObjectInfo) Preconditions() *api.Preconditions { - return i.objInfo.Preconditions() -} - -func (i *wrappedUpdatedObjectInfo) UpdatedObject(ctx api.Context, oldObj runtime.Object) (runtime.Object, error) { - obj, err := i.objInfo.UpdatedObject(ctx, oldObj) - if err != nil { - return obj, err - } - return i.transformFunc(ctx, obj, oldObj) -}