attr

package
v0.0.0-...-47ace37 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRequired

func CheckRequired(res *resource.Resource) (err error)

CheckRequired returns an error if at least one required attribute of res was not asserted by the client

func GetUniqueAttributes

func GetUniqueAttributes() ([][]string, error)

GetUniqueAttributes is ... (todo) > add support to multi key indexes

Types

type Context

type Context struct {
	Schema       *core.Schema
	Attribute    *core.Attribute
	SubAttribute *core.Attribute
}

A Context represents a set of definitions related to a Path

func Contexts

func Contexts(rt *core.ResourceType, fx func(attribute *core.Attribute) bool) ([]Context, error)

Contexts returns a slice of Context given a resource type rt.

It flattens the attributes of rt's schemas returning their Context representations. When a fx is provided it returns all the attributes statisfying fx(attribute).

func (*Context) Delete

func (ctx *Context) Delete(valuer resource.Valuer)

Delete a value from valuer at destination path of this context

func (*Context) Get

func (ctx *Context) Get(valuer resource.Valuer) interface{}

Get a value from valuer at destination path of this context and return it

func (*Context) Path

func (ctx *Context) Path() *Path

Path returns a Path built from a given Context

func (*Context) Set

func (ctx *Context) Set(value interface{}, valuer resource.Valuer)

Set value to valuer at destination path of this context

Value should be datatype.DataTyper or []datatype.DataTyper or nil. Furthermore attribute's characteristics are not enforced nor checked according to DataTypes rules when used within maps.

However, when context is pointing to a sub-attribute and parent attribute is missing, parent's value will be created with respect of attribute definition in order to accomodate the nested sub-attribute's value.

Value will be not set if it's not possibile to accomodate the sub-attribute's value in any way (eg. trying to set a sub-attribute's value in a map that's not respecting the parent attribute's definition).

Usage example: Parse("emails.type").Context(res.ResourceType()).Set(datatype.String("home"), res) for each complex value within "emails" (it's a multi value), the value of "type" sub-attribute will be set to "home".

type Path

type Path struct {
	URI  string
	Name string
	Sub  string
}

A Path represents a parsed SCIM attribute path as per https://tools.ietf.org/html/rfc7644#section-3.10

func Parse

func Parse(s string) *Path

Parse parses a SCIM attribute notation into a Path structure.

func Paths

func Paths(rt *core.ResourceType, fx func(attribute *core.Attribute) bool) ([]*Path, error)

Paths returns a slice of Path given a resource type rt.

It flattens the attributes of rt's schemas returning their contextualized Path representations. When a fx is provided it returns only the attribute paths statisfying fx(attribute).

func Projection

func Projection(ctx *core.ResourceType, included []*Path, excluded []*Path) ([]*Path, error)

Projection computes a set of attribute paths

The logic it enables is the one described within the RFC at sections:

- https://tools.ietf.org/html/rfc7644#section-3.4.2.5

- https://tools.ietf.org/html/rfc7644#section-3.4.3

- https://tools.ietf.org/html/rfc7644#section-3.9

In short the logic is (D - E - N) ∪ A where:

I: { i | i explicitly included by the user }

E: { e | e explicitly excluded by the user }

N: { n | n.Returned == "never" }

A: { a | a.Returned == "always" }

D: I if I != ∅ || { d | d.Returned == "default" }

Furthermore, attributes with Mutability == "writeOnly" cannot be returned too. So, pragmatically, they are treated as Returned == "never", as per: - https://tools.ietf.org/html/rfc7643#section-7

func (Path) Context

func (p Path) Context(rt *core.ResourceType) (ctx *Context)

Context fetches from rt a suitable Context for p, if any.

Nil when p is an unknown path attribute.

func (Path) IsSubAttribute

func (p Path) IsSubAttribute() bool

IsSubAttribute returns true if the path refers to an attribute with a parent

While p.Name refers to the name of the parent, p.Sub refers to the name of its children.

func (Path) String

func (p Path) String() string

func (Path) Transform

func (p Path) Transform(f func(facet string) string) *Path

Transform applies f(facet) to p's facets (URN, attribute, and sub-attribute name) and returns a new transformed Path

func (Path) Undefined

func (p Path) Undefined() bool

Undefined returns true if p does not satisfy the minimal path attribute definition. An Path is defined when its minimal component (ie., Name) exists, that's not implay validity (syntactically validation is a Parse responsibility).

type Relation

type Relation struct {
	RWAttribute    Path
	ROAttribute    Path
	ROResourceType core.ResourceType
}

Relation is ...

func GetRelationships

func GetRelationships(key, resourceTypeID string) ([]Relation, error)

GetRelationships is ...

Jump to

Keyboard shortcuts

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