patch

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package patch provides SCIM PATCH operation handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applier

type Applier struct {
	// CaseSensitive controls whether attribute names are matched case-sensitively.
	CaseSensitive bool
}

Applier applies PATCH operations to resources.

func NewApplier

func NewApplier() *Applier

NewApplier creates a new patch applier.

func (*Applier) Apply

func (a *Applier) Apply(resource any, operations []Operation) error

Apply applies a list of PATCH operations to a resource. The resource must be a pointer to a struct.

type Operation

type Operation struct {
	Op    OperationType `json:"op"`
	Path  string        `json:"path,omitempty"`
	Value any           `json:"value,omitempty"`
}

Operation represents a single SCIM PATCH operation.

func (Operation) MarshalJSON

func (op Operation) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Operation.

func (*Operation) UnmarshalJSON

func (op *Operation) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Operation.

func (*Operation) Validate

func (op *Operation) Validate() error

Validate validates a PATCH operation.

type OperationType

type OperationType string

OperationType represents the type of a PATCH operation.

const (
	OpAdd     OperationType = "add"
	OpRemove  OperationType = "remove"
	OpReplace OperationType = "replace"
)

func ParseOperationType

func ParseOperationType(s string) (OperationType, error)

ParseOperationType parses an operation type string.

type Path

type Path struct {
	// Attribute is the main attribute name.
	Attribute string

	// SubAttribute is the optional sub-attribute name.
	SubAttribute string

	// Filter is the optional filter for multi-valued attributes (e.g., "type eq 'work'").
	Filter string

	// URIPrefix is the optional schema URI prefix.
	URIPrefix string
}

Path represents a parsed PATCH path.

func ParsePath

func ParsePath(path string) (*Path, error)

ParsePath parses a SCIM PATCH path string. Supported formats:

  • "attribute"
  • "attribute.subAttribute"
  • "attribute[filter]"
  • "attribute[filter].subAttribute"
  • "urn:schema:attribute"
  • "urn:schema:attribute.subAttribute"

func (*Path) IsMultiValued

func (p *Path) IsMultiValued() bool

IsMultiValued returns true if the path has a filter for multi-valued attributes.

func (*Path) String

func (p *Path) String() string

String returns the string representation of the path.

type Request

type Request struct {
	Schemas    []string    `json:"schemas"`
	Operations []Operation `json:"Operations"`
}

Request represents a SCIM PATCH request.

type TargetSelector

type TargetSelector struct {
	// All indicates all values should be affected.
	All bool

	// Index is a specific index in the array (0-based, -1 if not specified).
	Index int

	// FilterAttr is the attribute to match.
	FilterAttr string

	// FilterOp is the filter operator.
	FilterOp string

	// FilterValue is the value to match.
	FilterValue any
}

TargetSelector represents a selector for multi-valued attribute targets.

func ParseFilter

func ParseFilter(filter string) (*TargetSelector, error)

ParseFilter parses a filter expression from a path. Supported formats:

  • "type eq 'work'"
  • "value eq 'xxx'"
  • "primary eq true"

func (*TargetSelector) Matches

func (s *TargetSelector) Matches(value map[string]any) bool

Matches returns true if the selector matches the given value.

Jump to

Keyboard shortcuts

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