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:
Andy Goldstein
2015-03-30 13:51:33 -04:00
parent d5ce931f0b
commit d7c5f427cb
10 changed files with 25 additions and 25 deletions

View File

@@ -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

View File

@@ -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))
}

View File

@@ -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