scim2-models 0.3.5__py3-none-any.whl → 0.3.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scim2_models/__init__.py +11 -11
- scim2_models/annotations.py +104 -0
- scim2_models/attributes.py +57 -0
- scim2_models/base.py +68 -525
- scim2_models/constants.py +3 -3
- scim2_models/context.py +168 -0
- scim2_models/reference.py +82 -0
- scim2_models/rfc7643/enterprise_user.py +4 -4
- scim2_models/rfc7643/group.py +5 -5
- scim2_models/rfc7643/resource.py +202 -94
- scim2_models/rfc7643/resource_type.py +13 -10
- scim2_models/rfc7643/schema.py +44 -38
- scim2_models/rfc7643/service_provider_config.py +7 -7
- scim2_models/rfc7643/user.py +9 -9
- scim2_models/rfc7644/bulk.py +2 -2
- scim2_models/rfc7644/error.py +11 -11
- scim2_models/rfc7644/list_response.py +5 -65
- scim2_models/rfc7644/message.py +103 -3
- scim2_models/rfc7644/patch_op.py +20 -6
- scim2_models/rfc7644/search_request.py +4 -4
- scim2_models/scim_object.py +143 -0
- scim2_models/utils.py +1 -1
- {scim2_models-0.3.5.dist-info → scim2_models-0.3.7.dist-info}/METADATA +1 -1
- scim2_models-0.3.7.dist-info/RECORD +29 -0
- scim2_models-0.3.5.dist-info/RECORD +0 -24
- {scim2_models-0.3.5.dist-info → scim2_models-0.3.7.dist-info}/WHEEL +0 -0
- {scim2_models-0.3.5.dist-info → scim2_models-0.3.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,13 +4,13 @@ from typing import Optional
|
|
|
4
4
|
|
|
5
5
|
from pydantic import Field
|
|
6
6
|
|
|
7
|
-
from ..
|
|
8
|
-
from ..
|
|
9
|
-
from ..
|
|
10
|
-
from ..
|
|
11
|
-
from ..
|
|
12
|
-
from ..
|
|
13
|
-
from ..
|
|
7
|
+
from ..annotations import Mutability
|
|
8
|
+
from ..annotations import Required
|
|
9
|
+
from ..annotations import Returned
|
|
10
|
+
from ..annotations import Uniqueness
|
|
11
|
+
from ..attributes import ComplexAttribute
|
|
12
|
+
from ..reference import ExternalReference
|
|
13
|
+
from ..reference import Reference
|
|
14
14
|
from .resource import Resource
|
|
15
15
|
|
|
16
16
|
|
scim2_models/rfc7643/user.py
CHANGED
|
@@ -8,15 +8,15 @@ from typing import Union
|
|
|
8
8
|
from pydantic import EmailStr
|
|
9
9
|
from pydantic import Field
|
|
10
10
|
|
|
11
|
-
from ..
|
|
12
|
-
from ..
|
|
13
|
-
from ..
|
|
14
|
-
from ..
|
|
15
|
-
from ..
|
|
16
|
-
from ..
|
|
17
|
-
from ..
|
|
18
|
-
from ..
|
|
19
|
-
from ..
|
|
11
|
+
from ..annotations import CaseExact
|
|
12
|
+
from ..annotations import Mutability
|
|
13
|
+
from ..annotations import Required
|
|
14
|
+
from ..annotations import Returned
|
|
15
|
+
from ..annotations import Uniqueness
|
|
16
|
+
from ..attributes import ComplexAttribute
|
|
17
|
+
from ..attributes import MultiValuedComplexAttribute
|
|
18
|
+
from ..reference import ExternalReference
|
|
19
|
+
from ..reference import Reference
|
|
20
20
|
from ..utils import Base64Bytes
|
|
21
21
|
from .resource import AnyExtension
|
|
22
22
|
from .resource import Resource
|
scim2_models/rfc7644/bulk.py
CHANGED
|
@@ -6,8 +6,8 @@ from typing import Optional
|
|
|
6
6
|
from pydantic import Field
|
|
7
7
|
from pydantic import PlainSerializer
|
|
8
8
|
|
|
9
|
-
from ..
|
|
10
|
-
from ..
|
|
9
|
+
from ..annotations import Required
|
|
10
|
+
from ..attributes import ComplexAttribute
|
|
11
11
|
from ..utils import int_to_str
|
|
12
12
|
from .message import Message
|
|
13
13
|
|
scim2_models/rfc7644/error.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import Optional
|
|
|
3
3
|
|
|
4
4
|
from pydantic import PlainSerializer
|
|
5
5
|
|
|
6
|
-
from ..
|
|
6
|
+
from ..annotations import Required
|
|
7
7
|
from ..utils import int_to_str
|
|
8
8
|
from .message import Message
|
|
9
9
|
|
|
@@ -26,7 +26,7 @@ class Error(Message):
|
|
|
26
26
|
"""A detailed human-readable message."""
|
|
27
27
|
|
|
28
28
|
@classmethod
|
|
29
|
-
def make_invalid_filter_error(cls):
|
|
29
|
+
def make_invalid_filter_error(cls) -> "Error":
|
|
30
30
|
"""Pre-defined error intended to be raised when the specified filter syntax was invalid (does not comply with :rfc:`Figure 1 of RFC7644 <7644#section-3.4.2.2>`), or the specified attribute and filter comparison combination is not supported."""
|
|
31
31
|
return Error(
|
|
32
32
|
status=400,
|
|
@@ -35,7 +35,7 @@ class Error(Message):
|
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
@classmethod
|
|
38
|
-
def make_too_many_error(cls):
|
|
38
|
+
def make_too_many_error(cls) -> "Error":
|
|
39
39
|
"""Pre-defined error intended to be raised when the specified filter yields many more results than the server is willing to calculate or process. For example, a filter such as ``(userName pr)`` by itself would return all entries with a ``userName`` and MAY not be acceptable to the service provider."""
|
|
40
40
|
return Error(
|
|
41
41
|
status=400,
|
|
@@ -44,7 +44,7 @@ class Error(Message):
|
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
@classmethod
|
|
47
|
-
def make_uniqueness_error(cls):
|
|
47
|
+
def make_uniqueness_error(cls) -> "Error":
|
|
48
48
|
"""Pre-defined error intended to be raised when One or more of the attribute values are already in use or are reserved."""
|
|
49
49
|
return Error(
|
|
50
50
|
status=409,
|
|
@@ -53,7 +53,7 @@ class Error(Message):
|
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
@classmethod
|
|
56
|
-
def make_mutability_error(cls):
|
|
56
|
+
def make_mutability_error(cls) -> "Error":
|
|
57
57
|
"""Pre-defined error intended to be raised when the attempted modification is not compatible with the target attribute's mutability or current state (e.g., modification of an "immutable" attribute with an existing value)."""
|
|
58
58
|
return Error(
|
|
59
59
|
status=400,
|
|
@@ -62,7 +62,7 @@ class Error(Message):
|
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
@classmethod
|
|
65
|
-
def make_invalid_syntax_error(cls):
|
|
65
|
+
def make_invalid_syntax_error(cls) -> "Error":
|
|
66
66
|
"""Pre-defined error intended to be raised when the request body message structure was invalid or did not conform to the request schema."""
|
|
67
67
|
return Error(
|
|
68
68
|
status=400,
|
|
@@ -71,7 +71,7 @@ class Error(Message):
|
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
@classmethod
|
|
74
|
-
def make_invalid_path_error(cls):
|
|
74
|
+
def make_invalid_path_error(cls) -> "Error":
|
|
75
75
|
"""Pre-defined error intended to be raised when the "path" attribute was invalid or malformed (see :rfc:`Figure 7 of RFC7644 <7644#section-3.5.2>`)."""
|
|
76
76
|
return Error(
|
|
77
77
|
status=400,
|
|
@@ -80,7 +80,7 @@ class Error(Message):
|
|
|
80
80
|
)
|
|
81
81
|
|
|
82
82
|
@classmethod
|
|
83
|
-
def make_no_target_error(cls):
|
|
83
|
+
def make_no_target_error(cls) -> "Error":
|
|
84
84
|
"""Pre-defined error intended to be raised when the specified "path" did not yield an attribute or attribute value that could be operated on. This occurs when the specified "path" value contains a filter that yields no match."""
|
|
85
85
|
return Error(
|
|
86
86
|
status=400,
|
|
@@ -89,7 +89,7 @@ class Error(Message):
|
|
|
89
89
|
)
|
|
90
90
|
|
|
91
91
|
@classmethod
|
|
92
|
-
def make_invalid_value_error(cls):
|
|
92
|
+
def make_invalid_value_error(cls) -> "Error":
|
|
93
93
|
"""Pre-defined error intended to be raised when a required value was missing, or the value specified was not compatible with the operation or attribute type (see :rfc:`Section 2.2 of RFC7643 <7643#section-2.2>`), or resource schema (see :rfc:`Section 4 of RFC7643 <7643#section-4>`)."""
|
|
94
94
|
return Error(
|
|
95
95
|
status=400,
|
|
@@ -98,7 +98,7 @@ class Error(Message):
|
|
|
98
98
|
)
|
|
99
99
|
|
|
100
100
|
@classmethod
|
|
101
|
-
def make_invalid_version_error(cls):
|
|
101
|
+
def make_invalid_version_error(cls) -> "Error":
|
|
102
102
|
"""Pre-defined error intended to be raised when the specified SCIM protocol version is not supported (see :rfc:`Section 3.13 of RFC7644 <7644#section-3.13>`)."""
|
|
103
103
|
return Error(
|
|
104
104
|
status=400,
|
|
@@ -107,7 +107,7 @@ class Error(Message):
|
|
|
107
107
|
)
|
|
108
108
|
|
|
109
109
|
@classmethod
|
|
110
|
-
def make_sensitive_error(cls):
|
|
110
|
+
def make_sensitive_error(cls) -> "Error":
|
|
111
111
|
"""Pre-defined error intended to be raised when the specified request cannot be completed, due to the passing of sensitive (e.g., personal) information in a request URI. For example, personal information SHALL NOT be transmitted over request URIs. See :rfc:`Section 7.5.2 of RFC7644 <7644#section-7.5.2>`."""
|
|
112
112
|
return Error(
|
|
113
113
|
status=400,
|
|
@@ -2,83 +2,22 @@ from typing import Annotated
|
|
|
2
2
|
from typing import Any
|
|
3
3
|
from typing import Generic
|
|
4
4
|
from typing import Optional
|
|
5
|
-
from typing import Union
|
|
6
|
-
from typing import get_args
|
|
7
|
-
from typing import get_origin
|
|
8
5
|
|
|
9
|
-
from pydantic import Discriminator
|
|
10
6
|
from pydantic import Field
|
|
11
|
-
from pydantic import Tag
|
|
12
7
|
from pydantic import ValidationInfo
|
|
13
8
|
from pydantic import ValidatorFunctionWrapHandler
|
|
14
9
|
from pydantic import model_validator
|
|
15
10
|
from pydantic_core import PydanticCustomError
|
|
16
11
|
from typing_extensions import Self
|
|
17
12
|
|
|
18
|
-
from ..
|
|
19
|
-
from ..
|
|
20
|
-
from ..base import Context
|
|
21
|
-
from ..base import Required
|
|
13
|
+
from ..annotations import Required
|
|
14
|
+
from ..context import Context
|
|
22
15
|
from ..rfc7643.resource import AnyResource
|
|
16
|
+
from .message import GenericMessageMetaclass
|
|
23
17
|
from .message import Message
|
|
24
18
|
|
|
25
19
|
|
|
26
|
-
class
|
|
27
|
-
def tagged_resource_union(resource_union):
|
|
28
|
-
"""Build Discriminated Unions, so pydantic can guess which class are needed to instantiate by inspecting a payload.
|
|
29
|
-
|
|
30
|
-
https://docs.pydantic.dev/latest/concepts/unions/#discriminated-unions
|
|
31
|
-
"""
|
|
32
|
-
if not get_origin(resource_union) == Union:
|
|
33
|
-
return resource_union
|
|
34
|
-
|
|
35
|
-
resource_types = get_args(resource_union)
|
|
36
|
-
|
|
37
|
-
def get_schema_from_payload(payload: Any) -> Optional[str]:
|
|
38
|
-
if not payload:
|
|
39
|
-
return None
|
|
40
|
-
|
|
41
|
-
payload_schemas = (
|
|
42
|
-
payload.get("schemas", [])
|
|
43
|
-
if isinstance(payload, dict)
|
|
44
|
-
else payload.schemas
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
resource_types_schemas = [
|
|
48
|
-
resource_type.model_fields["schemas"].default[0]
|
|
49
|
-
for resource_type in resource_types
|
|
50
|
-
]
|
|
51
|
-
common_schemas = [
|
|
52
|
-
schema for schema in payload_schemas if schema in resource_types_schemas
|
|
53
|
-
]
|
|
54
|
-
return common_schemas[0] if common_schemas else None
|
|
55
|
-
|
|
56
|
-
discriminator = Discriminator(get_schema_from_payload)
|
|
57
|
-
|
|
58
|
-
def get_tag(resource_type: type[BaseModel]) -> Tag:
|
|
59
|
-
return Tag(resource_type.model_fields["schemas"].default[0])
|
|
60
|
-
|
|
61
|
-
tagged_resources = [
|
|
62
|
-
Annotated[resource_type, get_tag(resource_type)]
|
|
63
|
-
for resource_type in resource_types
|
|
64
|
-
]
|
|
65
|
-
union = Union[tuple(tagged_resources)]
|
|
66
|
-
return Annotated[union, discriminator]
|
|
67
|
-
|
|
68
|
-
def __new__(cls, name, bases, attrs, **kwargs):
|
|
69
|
-
if kwargs.get("__pydantic_generic_metadata__") and kwargs[
|
|
70
|
-
"__pydantic_generic_metadata__"
|
|
71
|
-
].get("args"):
|
|
72
|
-
tagged_union = cls.tagged_resource_union(
|
|
73
|
-
kwargs["__pydantic_generic_metadata__"]["args"][0]
|
|
74
|
-
)
|
|
75
|
-
kwargs["__pydantic_generic_metadata__"]["args"] = (tagged_union,)
|
|
76
|
-
|
|
77
|
-
klass = super().__new__(cls, name, bases, attrs, **kwargs)
|
|
78
|
-
return klass
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class ListResponse(Message, Generic[AnyResource], metaclass=ListResponseMetaclass):
|
|
20
|
+
class ListResponse(Message, Generic[AnyResource], metaclass=GenericMessageMetaclass):
|
|
82
21
|
schemas: Annotated[list[str], Required.true] = [
|
|
83
22
|
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
|
|
84
23
|
]
|
|
@@ -112,6 +51,7 @@ class ListResponse(Message, Generic[AnyResource], metaclass=ListResponseMetaclas
|
|
|
112
51
|
- 'resources' must be set if 'totalResults' is non-zero.
|
|
113
52
|
"""
|
|
114
53
|
obj = handler(value)
|
|
54
|
+
assert isinstance(obj, cls)
|
|
115
55
|
|
|
116
56
|
if (
|
|
117
57
|
not info.context
|
scim2_models/rfc7644/message.py
CHANGED
|
@@ -1,10 +1,110 @@
|
|
|
1
1
|
from typing import Annotated
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing import Callable
|
|
4
|
+
from typing import Optional
|
|
5
|
+
from typing import Union
|
|
6
|
+
from typing import get_args
|
|
7
|
+
from typing import get_origin
|
|
8
|
+
|
|
9
|
+
from pydantic import Discriminator
|
|
10
|
+
from pydantic import Tag
|
|
11
|
+
from pydantic._internal._model_construction import ModelMetaclass
|
|
2
12
|
|
|
3
13
|
from ..base import BaseModel
|
|
4
|
-
from ..
|
|
14
|
+
from ..scim_object import ScimObject
|
|
15
|
+
from ..utils import UNION_TYPES
|
|
5
16
|
|
|
6
17
|
|
|
7
|
-
class Message(
|
|
18
|
+
class Message(ScimObject):
|
|
8
19
|
"""SCIM protocol messages as defined by :rfc:`RFC7644 §3.1 <7644#section-3.1>`."""
|
|
9
20
|
|
|
10
|
-
|
|
21
|
+
|
|
22
|
+
def create_schema_discriminator(
|
|
23
|
+
resource_types_schemas: list[str],
|
|
24
|
+
) -> Callable[[Any], Optional[str]]:
|
|
25
|
+
"""Create a schema discriminator function for the given resource schemas.
|
|
26
|
+
|
|
27
|
+
:param resource_types_schemas: List of valid resource schemas
|
|
28
|
+
:return: Discriminator function for Pydantic
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def get_schema_from_payload(payload: Any) -> Optional[str]:
|
|
32
|
+
"""Extract schema from SCIM payload for discrimination.
|
|
33
|
+
|
|
34
|
+
:param payload: SCIM payload dict or object
|
|
35
|
+
:return: First matching schema or None
|
|
36
|
+
"""
|
|
37
|
+
if not payload:
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
payload_schemas = (
|
|
41
|
+
payload.get("schemas", []) if isinstance(payload, dict) else payload.schemas
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
common_schemas = [
|
|
45
|
+
schema for schema in payload_schemas if schema in resource_types_schemas
|
|
46
|
+
]
|
|
47
|
+
return common_schemas[0] if common_schemas else None
|
|
48
|
+
|
|
49
|
+
return get_schema_from_payload
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_tag(resource_type: type[BaseModel]) -> Tag:
|
|
53
|
+
"""Create Pydantic tag from resource type schema.
|
|
54
|
+
|
|
55
|
+
:param resource_type: SCIM resource type
|
|
56
|
+
:return: Pydantic Tag for discrimination
|
|
57
|
+
"""
|
|
58
|
+
return Tag(resource_type.model_fields["schemas"].default[0])
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def create_tagged_resource_union(resource_union: Any) -> Any:
|
|
62
|
+
"""Build Discriminated Unions for SCIM resources.
|
|
63
|
+
|
|
64
|
+
Creates discriminated unions so Pydantic can determine which class to instantiate
|
|
65
|
+
by inspecting the payload's schemas field.
|
|
66
|
+
|
|
67
|
+
:param resource_union: Union type of SCIM resources
|
|
68
|
+
:return: Annotated discriminated union or original type
|
|
69
|
+
"""
|
|
70
|
+
if get_origin(resource_union) not in UNION_TYPES:
|
|
71
|
+
return resource_union
|
|
72
|
+
|
|
73
|
+
resource_types = get_args(resource_union)
|
|
74
|
+
|
|
75
|
+
# Set up schemas for the discriminator function
|
|
76
|
+
resource_types_schemas = [
|
|
77
|
+
resource_type.model_fields["schemas"].default[0]
|
|
78
|
+
for resource_type in resource_types
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
# Create discriminator function with schemas captured in closure
|
|
82
|
+
schema_discriminator = create_schema_discriminator(resource_types_schemas)
|
|
83
|
+
discriminator = Discriminator(schema_discriminator)
|
|
84
|
+
|
|
85
|
+
tagged_resources = [
|
|
86
|
+
Annotated[resource_type, get_tag(resource_type)]
|
|
87
|
+
for resource_type in resource_types
|
|
88
|
+
]
|
|
89
|
+
# Dynamic union construction from tuple - MyPy can't validate this at compile time
|
|
90
|
+
union = Union[tuple(tagged_resources)] # type: ignore
|
|
91
|
+
return Annotated[union, discriminator]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class GenericMessageMetaclass(ModelMetaclass):
|
|
95
|
+
"""Metaclass for SCIM generic types with discriminated unions."""
|
|
96
|
+
|
|
97
|
+
def __new__(
|
|
98
|
+
cls, name: str, bases: tuple[type, ...], attrs: dict[str, Any], **kwargs: Any
|
|
99
|
+
) -> type:
|
|
100
|
+
"""Create class with tagged resource unions for generic parameters."""
|
|
101
|
+
if kwargs.get("__pydantic_generic_metadata__") and kwargs[
|
|
102
|
+
"__pydantic_generic_metadata__"
|
|
103
|
+
].get("args"):
|
|
104
|
+
tagged_union = create_tagged_resource_union(
|
|
105
|
+
kwargs["__pydantic_generic_metadata__"]["args"][0]
|
|
106
|
+
)
|
|
107
|
+
kwargs["__pydantic_generic_metadata__"]["args"] = (tagged_union,)
|
|
108
|
+
|
|
109
|
+
klass = super().__new__(cls, name, bases, attrs, **kwargs)
|
|
110
|
+
return klass
|
scim2_models/rfc7644/patch_op.py
CHANGED
|
@@ -5,9 +5,11 @@ from typing import Optional
|
|
|
5
5
|
|
|
6
6
|
from pydantic import Field
|
|
7
7
|
from pydantic import field_validator
|
|
8
|
+
from pydantic import model_validator
|
|
9
|
+
from typing_extensions import Self
|
|
8
10
|
|
|
9
|
-
from ..
|
|
10
|
-
from ..
|
|
11
|
+
from ..annotations import Required
|
|
12
|
+
from ..attributes import ComplexAttribute
|
|
11
13
|
from .message import Message
|
|
12
14
|
|
|
13
15
|
|
|
@@ -17,7 +19,7 @@ class PatchOperation(ComplexAttribute):
|
|
|
17
19
|
remove = "remove"
|
|
18
20
|
add = "add"
|
|
19
21
|
|
|
20
|
-
op:
|
|
22
|
+
op: Op
|
|
21
23
|
"""Each PATCH operation object MUST have exactly one "op" member, whose
|
|
22
24
|
value indicates the operation to perform and MAY be one of "add", "remove",
|
|
23
25
|
or "replace".
|
|
@@ -32,11 +34,23 @@ class PatchOperation(ComplexAttribute):
|
|
|
32
34
|
"""The "path" attribute value is a String containing an attribute path
|
|
33
35
|
describing the target of the operation."""
|
|
34
36
|
|
|
37
|
+
@model_validator(mode="after")
|
|
38
|
+
def validate_path(self) -> Self:
|
|
39
|
+
# The "path" attribute value is a String containing an attribute path
|
|
40
|
+
# describing the target of the operation. The "path" attribute is
|
|
41
|
+
# OPTIONAL for "add" and "replace" and is REQUIRED for "remove"
|
|
42
|
+
# operations. See relevant operation sections below for details.
|
|
43
|
+
|
|
44
|
+
if self.path is None and self.op == PatchOperation.Op.remove:
|
|
45
|
+
raise ValueError("Op.path is required for remove operations")
|
|
46
|
+
|
|
47
|
+
return self
|
|
48
|
+
|
|
35
49
|
value: Optional[Any] = None
|
|
36
50
|
|
|
37
51
|
@field_validator("op", mode="before")
|
|
38
52
|
@classmethod
|
|
39
|
-
def normalize_op(cls, v):
|
|
53
|
+
def normalize_op(cls, v: Any) -> Any:
|
|
40
54
|
"""Ignorecase for op.
|
|
41
55
|
|
|
42
56
|
This brings
|
|
@@ -63,8 +77,8 @@ class PatchOp(Message):
|
|
|
63
77
|
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
|
|
64
78
|
]
|
|
65
79
|
|
|
66
|
-
operations: Optional[list[PatchOperation]] = Field(
|
|
67
|
-
None, serialization_alias="Operations"
|
|
80
|
+
operations: Annotated[Optional[list[PatchOperation]], Required.true] = Field(
|
|
81
|
+
None, serialization_alias="Operations", min_length=1
|
|
68
82
|
)
|
|
69
83
|
"""The body of an HTTP PATCH request MUST contain the attribute
|
|
70
84
|
"Operations", whose value is an array of one or more PATCH operations."""
|
|
@@ -5,7 +5,7 @@ from typing import Optional
|
|
|
5
5
|
from pydantic import field_validator
|
|
6
6
|
from pydantic import model_validator
|
|
7
7
|
|
|
8
|
-
from ..
|
|
8
|
+
from ..annotations import Required
|
|
9
9
|
from .message import Message
|
|
10
10
|
|
|
11
11
|
|
|
@@ -69,7 +69,7 @@ class SearchRequest(Message):
|
|
|
69
69
|
return None if value is None else max(0, value)
|
|
70
70
|
|
|
71
71
|
@model_validator(mode="after")
|
|
72
|
-
def attributes_validator(self):
|
|
72
|
+
def attributes_validator(self) -> "SearchRequest":
|
|
73
73
|
if self.attributes and self.excluded_attributes:
|
|
74
74
|
raise ValueError(
|
|
75
75
|
"'attributes' and 'excluded_attributes' are mutually exclusive"
|
|
@@ -78,12 +78,12 @@ class SearchRequest(Message):
|
|
|
78
78
|
return self
|
|
79
79
|
|
|
80
80
|
@property
|
|
81
|
-
def start_index_0(self):
|
|
81
|
+
def start_index_0(self) -> Optional[int]:
|
|
82
82
|
"""The 0 indexed start index."""
|
|
83
83
|
return self.start_index - 1 if self.start_index is not None else None
|
|
84
84
|
|
|
85
85
|
@property
|
|
86
|
-
def stop_index_0(self):
|
|
86
|
+
def stop_index_0(self) -> Optional[int]:
|
|
87
87
|
"""The 0 indexed stop index."""
|
|
88
88
|
return (
|
|
89
89
|
self.start_index_0 + self.count
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Base SCIM object classes with schema identification."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
from typing import Any
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from .annotations import Required
|
|
9
|
+
from .base import BaseModel
|
|
10
|
+
from .context import Context
|
|
11
|
+
from .utils import normalize_attribute_name
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from .rfc7643.resource import Resource
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def validate_model_attribute(model: type["BaseModel"], attribute_base: str) -> None:
|
|
18
|
+
"""Validate that an attribute name or a sub-attribute path exist for a given model."""
|
|
19
|
+
attribute_name, *sub_attribute_blocks = attribute_base.split(".")
|
|
20
|
+
sub_attribute_base = ".".join(sub_attribute_blocks)
|
|
21
|
+
|
|
22
|
+
aliases = {field.validation_alias for field in model.model_fields.values()}
|
|
23
|
+
|
|
24
|
+
if normalize_attribute_name(attribute_name) not in aliases:
|
|
25
|
+
raise ValueError(
|
|
26
|
+
f"Model '{model.__name__}' has no attribute named '{attribute_name}'"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if sub_attribute_base:
|
|
30
|
+
attribute_type = model.get_field_root_type(attribute_name)
|
|
31
|
+
|
|
32
|
+
if not attribute_type or not issubclass(attribute_type, BaseModel):
|
|
33
|
+
raise ValueError(
|
|
34
|
+
f"Attribute '{attribute_name}' is not a complex attribute, and cannot have a '{sub_attribute_base}' sub-attribute"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
validate_model_attribute(attribute_type, sub_attribute_base)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def extract_schema_and_attribute_base(attribute_urn: str) -> tuple[str, str]:
|
|
41
|
+
"""Extract the schema urn part and the attribute name part from attribute name.
|
|
42
|
+
|
|
43
|
+
As defined in :rfc:`RFC7644 §3.10 <7644#section-3.10>`.
|
|
44
|
+
"""
|
|
45
|
+
*urn_blocks, attribute_base = attribute_urn.split(":")
|
|
46
|
+
schema = ":".join(urn_blocks)
|
|
47
|
+
return schema, attribute_base
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def validate_attribute_urn(
|
|
51
|
+
attribute_name: str,
|
|
52
|
+
default_resource: Optional[type["Resource"]] = None,
|
|
53
|
+
resource_types: Optional[list[type["Resource"]]] = None,
|
|
54
|
+
) -> str:
|
|
55
|
+
"""Validate that an attribute urn is valid or not.
|
|
56
|
+
|
|
57
|
+
:param attribute_name: The attribute urn to check.
|
|
58
|
+
:default_resource: The default resource if `attribute_name` is not an absolute urn.
|
|
59
|
+
:resource_types: The available resources in which to look for the attribute.
|
|
60
|
+
:return: The normalized attribute URN.
|
|
61
|
+
"""
|
|
62
|
+
from .rfc7643.resource import Resource
|
|
63
|
+
|
|
64
|
+
if not resource_types:
|
|
65
|
+
resource_types = []
|
|
66
|
+
|
|
67
|
+
if default_resource and default_resource not in resource_types:
|
|
68
|
+
resource_types.append(default_resource)
|
|
69
|
+
|
|
70
|
+
default_schema = (
|
|
71
|
+
default_resource.model_fields["schemas"].default[0]
|
|
72
|
+
if default_resource
|
|
73
|
+
else None
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
schema: Optional[Any]
|
|
77
|
+
schema, attribute_base = extract_schema_and_attribute_base(attribute_name)
|
|
78
|
+
if not schema:
|
|
79
|
+
schema = default_schema
|
|
80
|
+
|
|
81
|
+
if not schema:
|
|
82
|
+
raise ValueError("No default schema and relative URN")
|
|
83
|
+
|
|
84
|
+
resource = Resource.get_by_schema(resource_types, schema)
|
|
85
|
+
if not resource:
|
|
86
|
+
raise ValueError(f"No resource matching schema '{schema}'")
|
|
87
|
+
|
|
88
|
+
validate_model_attribute(resource, attribute_base)
|
|
89
|
+
|
|
90
|
+
return f"{schema}:{attribute_base}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class ScimObject(BaseModel):
|
|
94
|
+
schemas: Annotated[list[str], Required.true]
|
|
95
|
+
"""The "schemas" attribute is a REQUIRED attribute and is an array of
|
|
96
|
+
Strings containing URIs that are used to indicate the namespaces of the
|
|
97
|
+
SCIM schemas that define the attributes present in the current JSON
|
|
98
|
+
structure."""
|
|
99
|
+
|
|
100
|
+
def _prepare_model_dump(
|
|
101
|
+
self,
|
|
102
|
+
scim_ctx: Optional[Context] = Context.DEFAULT,
|
|
103
|
+
**kwargs: Any,
|
|
104
|
+
) -> dict[str, Any]:
|
|
105
|
+
kwargs.setdefault("context", {}).setdefault("scim", scim_ctx)
|
|
106
|
+
|
|
107
|
+
if scim_ctx:
|
|
108
|
+
kwargs.setdefault("exclude_none", True)
|
|
109
|
+
kwargs.setdefault("by_alias", True)
|
|
110
|
+
|
|
111
|
+
return kwargs
|
|
112
|
+
|
|
113
|
+
def model_dump(
|
|
114
|
+
self,
|
|
115
|
+
*args: Any,
|
|
116
|
+
scim_ctx: Optional[Context] = Context.DEFAULT,
|
|
117
|
+
**kwargs: Any,
|
|
118
|
+
) -> dict[str, Any]:
|
|
119
|
+
"""Create a model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump`.
|
|
120
|
+
|
|
121
|
+
:param scim_ctx: If a SCIM context is passed, some default values of
|
|
122
|
+
Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
|
|
123
|
+
messages. Pass :data:`None` to get the default Pydantic behavior.
|
|
124
|
+
"""
|
|
125
|
+
dump_kwargs = self._prepare_model_dump(scim_ctx, **kwargs)
|
|
126
|
+
if scim_ctx:
|
|
127
|
+
dump_kwargs.setdefault("mode", "json")
|
|
128
|
+
return super(BaseModel, self).model_dump(*args, **dump_kwargs)
|
|
129
|
+
|
|
130
|
+
def model_dump_json(
|
|
131
|
+
self,
|
|
132
|
+
*args: Any,
|
|
133
|
+
scim_ctx: Optional[Context] = Context.DEFAULT,
|
|
134
|
+
**kwargs: Any,
|
|
135
|
+
) -> str:
|
|
136
|
+
"""Create a JSON model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump_json`.
|
|
137
|
+
|
|
138
|
+
:param scim_ctx: If a SCIM context is passed, some default values of
|
|
139
|
+
Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
|
|
140
|
+
messages. Pass :data:`None` to get the default Pydantic behavior.
|
|
141
|
+
"""
|
|
142
|
+
dump_kwargs = self._prepare_model_dump(scim_ctx, **kwargs)
|
|
143
|
+
return super(BaseModel, self).model_dump_json(*args, **dump_kwargs)
|
scim2_models/utils.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scim2-models
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
4
4
|
Summary: SCIM2 models serialization and validation with pydantic
|
|
5
5
|
Project-URL: documentation, https://scim2-models.readthedocs.io
|
|
6
6
|
Project-URL: repository, https://github.com/python-scim/scim2-models
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
scim2_models/__init__.py,sha256=yqYNm1B18OD-c8Y3QC3VWWv6Yoxw4PAvpC9eABhxef0,3128
|
|
2
|
+
scim2_models/annotations.py,sha256=oRjlKL1fqrYfa9UtaMdxF5fOT8CUUN3m-rdzvf7aiSA,3304
|
|
3
|
+
scim2_models/attributes.py,sha256=VloM7txtM2oexPrHO4phVY6nDzORMr3Vqf6EFAEZzyk,1804
|
|
4
|
+
scim2_models/base.py,sha256=BcAjsbwaHhO8AnGJJF05MqfL636UBlM2njFuCvFL_SY,16795
|
|
5
|
+
scim2_models/constants.py,sha256=9egq8JW0dFAqPng85CiHoH5T6pRtYL87-gC0C-IMGsk,573
|
|
6
|
+
scim2_models/context.py,sha256=oV8BCBSl9NvXuue11q4EYnoSze1yqtja9U_HEdrR-88,9125
|
|
7
|
+
scim2_models/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
scim2_models/reference.py,sha256=EQM8bbSr_kxbFMNlWYf_4sAJlSsOS5wUrn-9_eF0Ykc,2483
|
|
9
|
+
scim2_models/scim_object.py,sha256=t1p6ha719w1YU2Gtcy_k2NY-X0kc8PJxwstKOGP0oPA,5183
|
|
10
|
+
scim2_models/utils.py,sha256=1fmJoVCtrFURmvBegGti8UnXdj9EnzkNmg83jtpj70A,2755
|
|
11
|
+
scim2_models/rfc7643/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
scim2_models/rfc7643/enterprise_user.py,sha256=TVa5aS-eLHcDkwyr58hZYsRKk0AwjUaUaSFhU51mn5E,1806
|
|
13
|
+
scim2_models/rfc7643/group.py,sha256=lJXKopa__LoWhkaNqu0JFVyQaOMe-AF4vISaq0Gg7cE,1458
|
|
14
|
+
scim2_models/rfc7643/resource.py,sha256=jPP6nGGEVOLIX7Zmka5xHLGk3jJBfpaMBPizU1mXFoo,17275
|
|
15
|
+
scim2_models/rfc7643/resource_type.py,sha256=scLqbD3HX3fXT2JOXY9OUVnZz7i5ty2lx4VuiVxt6DE,3314
|
|
16
|
+
scim2_models/rfc7643/schema.py,sha256=DJQvDx31jYYZyfS3noTu4-8C429u0ctUqRysmvUULyI,10647
|
|
17
|
+
scim2_models/rfc7643/service_provider_config.py,sha256=6xJ182T-1szEQnN5Zb1cTdQCgTYIFi4XKygbvDlTKTM,5446
|
|
18
|
+
scim2_models/rfc7643/user.py,sha256=ErOghhilUF7fipwDRqARyLwJhbntQx4GJG3u2sZNJXs,10664
|
|
19
|
+
scim2_models/rfc7644/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
scim2_models/rfc7644/bulk.py,sha256=ZVGtitEDy--iDBzU2WR-LT7_rIizZFBD3sOo6rJ_WII,2590
|
|
21
|
+
scim2_models/rfc7644/error.py,sha256=KZBJfI2z4TByAK6W3mN3e3m0ZrDguPLm66v9W971Awk,6302
|
|
22
|
+
scim2_models/rfc7644/list_response.py,sha256=8o1_WR3AOZNv0hbCGcgq8lyeXaNjo1CiLxfteq8gctk,2396
|
|
23
|
+
scim2_models/rfc7644/message.py,sha256=rX2KezTdM81Z9mw7JTJYjWF-VDnDeUm6-ZxsarmVdsE,3738
|
|
24
|
+
scim2_models/rfc7644/patch_op.py,sha256=Yk2qr-vsuU6MMh6uFijo3Tw1vgo-clbgj1T0B8S1Tcs,2856
|
|
25
|
+
scim2_models/rfc7644/search_request.py,sha256=kLhIfyjAjc7ar6wkT7t-A2ySB-_3XYP-gf_LspLU2RU,3063
|
|
26
|
+
scim2_models-0.3.7.dist-info/METADATA,sha256=tqCuz5S5ESdKVlEQhpsOVxgXHUDfUyAC32rkIOH1w98,16288
|
|
27
|
+
scim2_models-0.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
28
|
+
scim2_models-0.3.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
29
|
+
scim2_models-0.3.7.dist-info/RECORD,,
|