Pass ctx to Validate, ValidateUpdate
Pass ctx to Validate/ValidateUpdate. This is useful so strategies can access data such as the current user.
This commit is contained in:
@@ -40,7 +40,7 @@ type RESTCreateStrategy interface {
|
||||
PrepareForCreate(obj runtime.Object)
|
||||
// Validate is invoked after default fields in the object have been filled in before
|
||||
// the object is persisted.
|
||||
Validate(obj runtime.Object) fielderrors.ValidationErrorList
|
||||
Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList
|
||||
}
|
||||
|
||||
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
|
||||
@@ -63,7 +63,7 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
|
||||
api.FillObjectMetaSystemFields(ctx, objectMeta)
|
||||
api.GenerateName(strategy, objectMeta)
|
||||
|
||||
if errs := strategy.Validate(obj); len(errs) > 0 {
|
||||
if errs := strategy.Validate(ctx, obj); len(errs) > 0 {
|
||||
return errors.NewInvalid(kind, objectMeta.Name, errs)
|
||||
}
|
||||
return nil
|
||||
|
@@ -75,7 +75,7 @@ func (svcStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
}
|
||||
|
||||
// Validate validates a new service.
|
||||
func (svcStrategy) Validate(obj runtime.Object) fielderrors.ValidationErrorList {
|
||||
func (svcStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||||
service := obj.(*api.Service)
|
||||
return validation.ValidateService(service)
|
||||
}
|
||||
@@ -84,6 +84,6 @@ func (svcStrategy) AllowCreateOnUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (svcStrategy) ValidateUpdate(obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
func (svcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidateServiceUpdate(old.(*api.Service), obj.(*api.Service))
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ type RESTUpdateStrategy interface {
|
||||
PrepareForUpdate(obj, old runtime.Object)
|
||||
// ValidateUpdate is invoked after default fields in the object have been filled in before
|
||||
// the object is persisted.
|
||||
ValidateUpdate(obj, old runtime.Object) fielderrors.ValidationErrorList
|
||||
ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList
|
||||
}
|
||||
|
||||
// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns
|
||||
@@ -58,7 +58,7 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
|
||||
objectMeta.Namespace = api.NamespaceNone
|
||||
}
|
||||
strategy.PrepareForUpdate(obj, old)
|
||||
if errs := strategy.ValidateUpdate(obj, old); len(errs) > 0 {
|
||||
if errs := strategy.ValidateUpdate(ctx, obj, old); len(errs) > 0 {
|
||||
return errors.NewInvalid(kind, objectMeta.Name, errs)
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user