Add a REST hook for post-validation canonicalize

This is a simple hook that only Endpoints uses for now.
This commit is contained in:
Tim Hockin
2015-11-12 21:13:16 -08:00
parent 927f30b0a5
commit 35ab5c6234
25 changed files with 113 additions and 11 deletions

View File

@@ -37,11 +37,15 @@ type RESTCreateStrategy interface {
NamespaceScoped() bool
// PrepareForCreate is invoked on create before validation to normalize
// the object. For example: remove fields that are not to be persisted,
// sort order-insensitive list fields, etc.
// sort order-insensitive list fields, etc. This should not remove fields
// whose presence would be considered a validation error.
PrepareForCreate(obj runtime.Object)
// Validate is invoked after default fields in the object have been filled in before
// the object is persisted.
// the object is persisted. This method should not mutate the object.
Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList
// Canonicalize is invoked after validation has succeeded but before the
// object has been persisted. This method may mutate the object.
Canonicalize(obj runtime.Object)
}
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
@@ -77,6 +81,8 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
return errors.NewInvalid(kind, objectMeta.Name, errs)
}
strategy.Canonicalize(obj)
return nil
}