filter

package
v0.0.0-...-986c4a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2020 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ForProperty

type ForProperty interface {
	// Returns true if this filter supports the supplied attribute. The Filter method
	// will only be called when this method returns true. This method is expected to be
	// called at setup time.
	Supports(attribute *spec.Attribute) bool
	// Filter the given property with reference to the resource that contains this property.
	// Any error returned shall cause the caller to abort subsequent operations.
	Filter(ctx context.Context, resource *prop.Resource, property prop.Property) error
	// Filter the given property with reference to the resource that contains this property, another reference resource which
	// potentially holds a reference property. The reference resource and property may serve as a guidance for the expected
	// state of the property. The reference resource shall never be nil, whereas the reference property may be nil.
	// Any error returned shall cause the caller to abort subsequent operations.
	FieldRef(ctx context.Context, resource *prop.Resource, property prop.Property, refResource *prop.Resource, refProperty prop.Property) error
}

Responsible of filtering on the level of a single property field. It provides more granular control than a resource filter.

type ForResource

type ForResource interface {
	// Filter the resource and return any error. If the error returned is not nil,
	// the caller should immediately abort the operation and avoid executing the
	// following filters.
	Filter(ctx context.Context, resource *prop.Resource) error
	// Filter the resource with reference to a reference resource and return any error.
	// The reference resource may serve as a guidance for the expected state of the resource.
	// If the error returned is not nil, the caller should immediately abort the operation
	// and avoid executing the following filters.
	FilterRef(ctx context.Context, resource *prop.Resource, ref *prop.Resource) error
}

Responsible of filtering a resource, like carrying out operations on a resource such as validation, modification, etc.

func ClearReadOnly

func ClearReadOnly() ForResource

Create a ForResource filter that deletes the values in readOnly properties from a resource.

func CopyReadOnly

func CopyReadOnly() ForResource

Create a ForResource filter that copies value from the reference property to the resource property when the mutability is readOnly and the attribute is marked with annotation '@CopyReadOnly'. It is suggested that: - for simple singular attribute, mark on the attribute itself - for complex singular attribute, mark on the sub attributes instead - for multiValued attribute, mark on the attribute itself.

func FromForProperty

func FromForProperty(filters ...ForProperty) ForResource

Create a ForResource filter using a list of ForProperty filters. The filtering resource will be traversed by a special prop.Visitor implementation which invokes each ForProperty filter in sequence on every visited property.

func ID

func ID() ForResource

Create a new resource filter that generates a new uuid on the id field.

func Meta

func Meta() ForResource

Create a new meta resource filter. The filter assigns metadata to the meta field on Filter. On FilterWithRef, the filter updates lastModified time and version only if resource hash has changed from ref hash.

func Password

func Password(bcryptCost int) ForResource

Return a filter that hashes the password field using BCrypt algorithm. It only performs the hashing when the value is not yet bcrypted.

func Validation

func Validation(database db.DB) ForResource

Create a ForResource filter that performs resource validation. Attributes checks such as required, canonicalValues, uniqueness and mutability is performed, where applicable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL