Skip to content

Commit

Permalink
Merge pull request #5 from ivixvi/to-private
Browse files Browse the repository at this point in the history
fix: various improvement
  • Loading branch information
ivixvi authored Jul 7, 2024
2 parents 5239b70 + df79540 commit e253e37
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README-ja.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# scim-patch
SCIM2.0 Patch 操作のGo言語実装です

現在は構想があるのみで、順次実装を進めていこうと考えています。

> [!CAUTION]
> 一通りの実装が済んでおらず、利用できる状態にありません。

# 概要

SCIM2.0のPatch操作の仕様の幅が広く、また、IdP毎の差異を吸収するのも大変です。
そこで、本ライブラリが「Patchによるスキーマの操作」を一通り吸収します。

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# scim-patch
Go implementation of SCIM 2.0 Patch operations.

Currently, we only have a concept, but we plan to implement it gradually.
> [!CAUTION]
> It has not been fully implemented and is not ready for use.
# Overview

The specification of SCIM 2.0 Patch operations is broad, and absorbing the differences for each IdP is also challenging.
Therefore, this library aims to comprehensively handle "schema manipulation via Patch".

Expand Down
32 changes: 21 additions & 11 deletions scimpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,43 @@ type Patcher struct {
SchemaExtensions []scim.SchemaExtension
}

// Apply is returns a argument.
// Apply は RFC7644 3.5.2. Modifying with PATCH の実装です。
// data に op が適用された ResourceAttributes を返却します。
// see. https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2
func (p Patcher) Apply(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
switch strings.ToLower(op.Op) {
case scim.PatchOperationAdd:
return p.Add(op, data)
return p.add(op, data)
case scim.PatchOperationReplace:
return p.Replace(op, data)
return p.replace(op, data)
case scim.PatchOperationRemove:
return p.Remove(op, data)
return p.remove(op, data)
}
return data, nil
}

// Add is returns a argument.
func (p Patcher) Add(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
// add は RFC7644 3.5.2.1. Add Operation の実装です。
// data に op が適用された ResourceAttributes を返却します。
// see. https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.1
// 基本は Validated な op を想定しているため、エラーハンドリングは属性を確認するうえで対応することになる最小限のチェックとなっています。
func (p Patcher) add(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
return data, nil
}

// Replace is returns a argument.
func (p Patcher) Replace(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
// replace は RFC7644 3.5.2.3. Replace Operation の実装です。
// data に op が適用された ResourceAttributes を返却します。
// see. https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.3
// 基本は Validated な op を想定しているため、エラーハンドリングは属性を確認するうえで対応することになる最小限のチェックとなっています。
func (p Patcher) replace(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
return data, nil
}

// Remove is returns a argument.
func (p Patcher) Remove(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
// remove は RFC7644 3.5.2.2. Remove Operation の実装です。
// data に op が適用された ResourceAttributes を返却します。
// see. https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.2
// 基本は Validated な op を想定しているため、エラーハンドリングは属性を確認するうえで対応することになる最小限のチェックとなっています。
func (p Patcher) remove(op scim.PatchOperation, data scim.ResourceAttributes) (scim.ResourceAttributes, error) {
if op.Path == nil {
// 3.5.2.2. Remove Operation
// If "path" is unspecified, the operation fails with HTTP status code 400 and a "scimType" error code of "noTarget".
return scim.ResourceAttributes{}, errors.ScimErrorNoTarget
}
Expand Down
4 changes: 4 additions & 0 deletions scimpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
filter "github.com/scim2/filter-parser/v2"
)

// path は *filter.Path を取得しやすくするためのテストユーティリティです。
// APIのリクエストボディ Operations[].path にはいってくる想定の値を引数に与えて利用します。
func path(s string) *filter.Path {
p, err := filter.ParsePath([]byte(s))
if err != nil {
Expand All @@ -18,6 +20,7 @@ func path(s string) *filter.Path {
return &p
}

// TestPatcher_Apply は Pacher.Apply の正常系をテストします
func TestPatcher_Apply(t *testing.T) {
// Define the test cases
testCases := []struct {
Expand Down Expand Up @@ -89,6 +92,7 @@ func TestPatcher_Apply(t *testing.T) {
}
}

// TestPatcher_ApplyError は Pacher.Apply の異常系をテストします
func TestPatcher_ApplyError(t *testing.T) {
// Define the test cases
testCases := []struct {
Expand Down

0 comments on commit e253e37

Please sign in to comment.