scimpatch

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 7 Imported by: 0

README

scim-patch

Go Reference

Go implementation of SCIM2.0 Patch operation

[!CAUTION] This library is not stable and not ready for production use.

Overview

The SCIM2.0 Patch operation specification is broad, and absorbing differences between IdPs is challenging. This library aims to handle "schema operations via Patch" comprehensively.

Since it does not directly manipulate application data, the overall processing and data storage may become redundant. However, it helps reduce tight coupling by only requiring you to consider the mapping between the SCIM schema and the schema used in your application.

Additionally, this library depends on the following SCIM-related implementations for handling Schema and filter:

Expected Use Cases

The concept is close to the issue described here: https://github.com/elimity-com/scim/issues/171

For usage examples in the current implementation, please refer to example.

Logger

Logging of internal processing in the Patcher can be achieved by passing a logger via context. You can use a logger that implements the PatcherLogger interface.

For specific usage examples, please refer to example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLogger

func AddLogger(ctx context.Context, logger PatcherLogger) context.Context

AddLogger adds a logger to the context. If the context already has a logger, AddLogger will overwrite it. If the logger is nil, AddLogger will add a no-op logger. The logger used by the Patcher.

Types

type Operator

type Operator interface {
	Direct(ctx context.Context, scopedMap map[string]interface{}, scopedAttr string, value interface{}) bool
	ByValueExpressionForItem(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, value interface{}) ([]map[string]interface{}, bool)
	ByValueExpressionForAttribute(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, subAttr string, value interface{}) ([]map[string]interface{}, bool)
}

Operator は Patch Operation の各操作のドメインとなるインターフェースです。 Direct は map とその map 内で更新対象となる属性と更新後の値を受け取って更新後のmapと変更有無を返却します この関数のみ、pathが未指定の場合でも利用されます ByValueExpressionForItem は 対象の属性が、MultiValuedComplexAttribute で path にて valFilter が指定されているときにそれを受けとって更新後のスライスと変更有無を返却します。 ByValueExpressionForAttribute は 対象の属性が、MultiValuedComplexAttribute で path にて valFilter と subAttr が指定されているときにそれを受けとって更新後のスライスと変更有無を返却します。

type Patcher

type Patcher struct {
	// contains filtered or unexported fields
}

func NewPatcher

func NewPatcher(
	s schema.Schema,
	extensions []schema.Schema,
	opts *PatcherOpts,
) *Patcher

NewPatcher は Patcher の実態を取得します。

func (*Patcher) Apply

func (p *Patcher) Apply(ctx context.Context, op scim.PatchOperation, data map[string]interface{}) (map[string]interface{}, bool, error)

Apply は RFC7644 3.5.2. Modifying with PATCH の実装です。 data に op が適用された ResourceAttributes と実際に適用されたかどうかの真偽値を返却します。 see. https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2

type PatcherLogger

type PatcherLogger interface {
	Error(args ...interface{})
	Debug(args ...interface{})
}

type PatcherOpts

type PatcherOpts struct {
	Adder    *Operator
	Replacer *Operator
	Remover  *Operator
}

PatcherOpts を利用することで Patcherが利用する各操作の Operator を上書きすることができます。 指定しない場合はパッケージデフォルトで実装されている Operator が利用されます。

Jump to

Keyboard shortcuts

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