crud

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

This package implements modification and evaluation of Resource

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(resource *prop.Resource, path string, value interface{}) error

Add value to SCIM resource at the given SCIM path. If SCIM path is empty, value will be added to the root of the resource. The supplied value must be compatible with the target property attribute, otherwise error will be returned.

func Delete

func Delete(resource *prop.Resource, path string) error

Delete value from the SCIM resource at the specified SCIM path. The path cannot be empty.

func Evaluate

func Evaluate(resource *prop.Resource, filter string) (bool, error)

Evaluate the resource with the given SCIM filter and return the boolean result or an error.

func EvaluateExpressionOnProperty added in v2.2.0

func EvaluateExpressionOnProperty(prop prop.Property, expr *expr.Expression) (bool, error)

func Register

func Register(resourceType *spec.ResourceType)

Register calls expr.RegisterURN for the main schema ids and all schema extension ids in the resource type.

func Replace

func Replace(resource *prop.Resource, path string, value interface{}) error

Replace value in SCIM resource at the given SCIM path. If SCIM path is empty, the root of the resource will be replaced. The supplied value must be compatible with the target property attribute, otherwise error will be returned.

func SeekSortTarget

func SeekSortTarget(resource *prop.Resource, by *expr.Expression) (prop.Property, error)

Find the actual sort target inferred by the sortBy parameter. 'resource' points to the Resource whose value is being sorted. 'by' is the compiled sortBy path. Depending on the sortBy parameter, the actual sort target varies in several cases.

First, if the sortBy parameter refers to a simple type inside a singular complex type, it will be the sort target. For instance,

sortBy=name.familyName

Given the following resource snippet:

{
	"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
	"id": "FA33AA7E-99DB-4446-A2CD-050133B442DA",
	"userName": "imulab",
	"name": {
		"familyName": "Qiu",
		"givenName": "David"
	}
}

The value "Qiu" will be used to sort the resource. This also applies to any top level singular simple types, as this project treats top-level container as a virtual complex property as well.

Second, if the sortBy parameter refers to a simple type inside a multiValued complex type, the sort target will be the value whose accompanying primary attribute was set to 'true', or the first value. For instance,

sortBy=emails.value

Given the following resource snippet:

{
	"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
	"id": "FA33AA7E-99DB-4446-A2CD-050133B442DA",
	"userName": "imulab",
	"emails": [
		{
			"value": "foo@bar.com"
		},
		{
			"value": "bar@foo.com",
			"primary": true
		}
	]
}

The value "bar@foo.com" will be used to sort the resource, because its accompany primary attribute is true.

However, if none of the primary attribute was set to true, like:

{
	"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
	"id": "FA33AA7E-99DB-4446-A2CD-050133B442DA",
	"userName": "imulab",
	"emails": [
		{
			"value": "foo@bar.com"
		},
		{
			"value": "bar@foo.com"
		}
	]
}

In this case, "foo@bar.com" will be used to sort the resource, because it is the first value.

Third, if the sortBy parameter refers to multiValued simple type, the sort target will be its first element. For instance,

sortBy=schemas

Given the following resource snippet:

	{
		"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"],
		"id": "FA33AA7E-99DB-4446-A2CD-050133B442DA",
		"userName": "imulab",
		"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
 			"employeeNumber": "11250"
		}
	}

The value "urn:ietf:params:scim:schemas:core:2.0:User" will be used to sort the resource because it is the first element.

Other sortBy parameters that does not fall into the above three categories are considered to be invalid.

Types

type Pagination

type Pagination struct {
	StartIndex int // 1-based start index
	Count      int
}

Option to paginate.

type Projection

type Projection struct {
	Attributes         []string
	ExcludedAttributes []string
}

Option to include or exclude attributes in the return. At most one can be specified.

type Sort

type Sort struct {
	By    string
	Order SortOrder
}

Option to sort

func (Sort) Sort

func (s Sort) Sort(resources []*prop.Resource) error

Sort the given list of resources according to the sort options.

type SortOrder

type SortOrder string

Order for sorting

const (
	SortDefault SortOrder = ""
	SortAsc     SortOrder = "ascending"
	SortDesc    SortOrder = "descending"
)

Sort order defined in specification

Directories

Path Synopsis
This package implements compilers for SCIM path and SCIM filters, and defines the basic data structure for their representation in memory.
This package implements compilers for SCIM path and SCIM filters, and defines the basic data structure for their representation in memory.

Jump to

Keyboard shortcuts

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