|
1 | | -from enum import Enum |
2 | 1 | from inspect import isclass |
3 | 2 | from typing import Annotated |
4 | 3 | from typing import Any |
|
22 | 21 | from pydantic_core import PydanticCustomError |
23 | 22 | from typing_extensions import Self |
24 | 23 |
|
| 24 | +from scim2_models.annotations import Mutability |
| 25 | +from scim2_models.annotations import Required |
| 26 | +from scim2_models.annotations import Returned |
25 | 27 | from scim2_models.context import Context |
26 | 28 | from scim2_models.reference import Reference |
27 | 29 | from scim2_models.utils import normalize_attribute_name |
@@ -116,109 +118,6 @@ def contains_attribute_or_subattributes( |
116 | 118 | ) |
117 | 119 |
|
118 | 120 |
|
119 | | -class Mutability(str, Enum): |
120 | | - """A single keyword indicating the circumstances under which the value of the attribute can be (re)defined.""" |
121 | | - |
122 | | - read_only = "readOnly" |
123 | | - """The attribute SHALL NOT be modified.""" |
124 | | - |
125 | | - read_write = "readWrite" |
126 | | - """The attribute MAY be updated and read at any time.""" |
127 | | - |
128 | | - immutable = "immutable" |
129 | | - """The attribute MAY be defined at resource creation (e.g., POST) or at |
130 | | - record replacement via a request (e.g., a PUT). |
131 | | -
|
132 | | - The attribute SHALL NOT be updated. |
133 | | - """ |
134 | | - |
135 | | - write_only = "writeOnly" |
136 | | - """The attribute MAY be updated at any time. |
137 | | -
|
138 | | - Attribute values SHALL NOT be returned (e.g., because the value is a |
139 | | - stored hash). Note: An attribute with a mutability of "writeOnly" |
140 | | - usually also has a returned setting of "never". |
141 | | - """ |
142 | | - |
143 | | - _default = read_write |
144 | | - |
145 | | - |
146 | | -class Returned(str, Enum): |
147 | | - """A single keyword that indicates when an attribute and associated values are returned in response to a GET request or in response to a PUT, POST, or PATCH request.""" |
148 | | - |
149 | | - always = "always" # cannot be excluded |
150 | | - """The attribute is always returned, regardless of the contents of the |
151 | | - "attributes" parameter. |
152 | | -
|
153 | | - For example, "id" is always returned to identify a SCIM resource. |
154 | | - """ |
155 | | - |
156 | | - never = "never" # always excluded |
157 | | - """The attribute is never returned, regardless of the contents of the |
158 | | - "attributes" parameter.""" |
159 | | - |
160 | | - default = "default" # included by default but can be excluded |
161 | | - """The attribute is returned by default in all SCIM operation responses |
162 | | - where attribute values are returned, unless it is explicitly excluded.""" |
163 | | - |
164 | | - request = "request" # excluded by default but can be included |
165 | | - """The attribute is returned in response to any PUT, POST, or PATCH |
166 | | - operations if specified in the "attributes" parameter.""" |
167 | | - |
168 | | - _default = default |
169 | | - |
170 | | - |
171 | | -class Uniqueness(str, Enum): |
172 | | - """A single keyword value that specifies how the service provider enforces uniqueness of attribute values.""" |
173 | | - |
174 | | - none = "none" |
175 | | - """The values are not intended to be unique in any way.""" |
176 | | - |
177 | | - server = "server" |
178 | | - """The value SHOULD be unique within the context of the current SCIM |
179 | | - endpoint (or tenancy) and MAY be globally unique (e.g., a "username", email |
180 | | - address, or other server-generated key or counter). |
181 | | -
|
182 | | - No two resources on the same server SHOULD possess the same value. |
183 | | - """ |
184 | | - |
185 | | - global_ = "global" |
186 | | - """The value SHOULD be globally unique (e.g., an email address, a GUID, or |
187 | | - other value). |
188 | | -
|
189 | | - No two resources on any server SHOULD possess the same value. |
190 | | - """ |
191 | | - |
192 | | - _default = none |
193 | | - |
194 | | - |
195 | | -class Required(Enum): |
196 | | - """A Boolean value that specifies whether the attribute is required or not. |
197 | | -
|
198 | | - Missing required attributes raise a :class:`~pydantic.ValidationError` on :attr:`~scim2_models.Context.RESOURCE_CREATION_REQUEST` and :attr:`~scim2_models.Context.RESOURCE_REPLACEMENT_REQUEST` validations. |
199 | | - """ |
200 | | - |
201 | | - true = True |
202 | | - false = False |
203 | | - |
204 | | - _default = false |
205 | | - |
206 | | - def __bool__(self) -> bool: |
207 | | - return self.value |
208 | | - |
209 | | - |
210 | | -class CaseExact(Enum): |
211 | | - """A Boolean value that specifies whether a string attribute is case- sensitive or not.""" |
212 | | - |
213 | | - true = True |
214 | | - false = False |
215 | | - |
216 | | - _default = false |
217 | | - |
218 | | - def __bool__(self) -> bool: |
219 | | - return self.value |
220 | | - |
221 | | - |
222 | 121 | class BaseModel(PydanticBaseModel): |
223 | 122 | """Base Model for everything.""" |
224 | 123 |
|
|
0 commit comments