Skip to content

Commit

Permalink
refactor: move model type classes inside the models
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 24, 2024
1 parent 9730234 commit 31129ce
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 101 deletions.
18 changes: 3 additions & 15 deletions pydantic_scim2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
from .responses import PatchOperation
from .responses import PatchRequest
from .responses import SCIMError
from .schema import AttributeKind
from .schema import Attribute
from .schema import Mutability
from .schema import Returned
from .schema import Schema
from .schema import Uniqueness
from .service_provider import AuthenticationScheme
from .service_provider import AuthenticationSchemeKind
from .service_provider import Bulk
from .service_provider import ChangePassword
from .service_provider import ETag
Expand All @@ -26,28 +25,23 @@
from .service_provider import ServiceProviderConfiguration
from .service_provider import Sort
from .user import Address
from .user import AddressKind
from .user import Email
from .user import EmailKind
from .user import Entitlement
from .user import Im
from .user import ImKind
from .user import Name
from .user import PhoneNumber
from .user import PhoneNumberKind
from .user import Photo
from .user import PhotoKind
from .user import Role
from .user import User
from .user import X509Certificate

__all__ = [
"Manager",
"EnterpriseUser",
"Attribute",
"Group",
"GroupMember",
"SchemaExtension",
"ResourceType",
"SCIMError",
"PatchOp",
"PatchOperation",
Expand All @@ -59,18 +53,12 @@
"ChangePassword",
"Sort",
"AuthenticationScheme",
"AuthenticationSchemeKind",
"ServiceProviderConfiguration",
"Name",
"EmailKind",
"Email",
"PhoneNumberKind",
"PhoneNumber",
"ImKind",
"Im",
"PhotoKind",
"Photo",
"AddressKind",
"Address",
"Entitlement",
"Role",
Expand All @@ -80,8 +68,8 @@
"Meta",
"ETag",
"Schema",
"AttributeKind",
"Mutability",
"Returned",
"Uniqueness",
"ResourceType",
]
23 changes: 11 additions & 12 deletions pydantic_scim2/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
from .resource import Meta


class AttributeKind(str, Enum):
string = "string"
boolean = "boolean"
decimal = "decimal"
integer = "integer"
date_time = "dateTime"
reference = "reference"
binary = "binary"
complex = "complex"


class Mutability(str, Enum):
read_only = "readOnly"
read_write = "readWrite"
Expand All @@ -38,10 +27,20 @@ class Uniqueness(str, Enum):


class Attribute(SCIM2Model):
class Type(str, Enum):
string = "string"
boolean = "boolean"
decimal = "decimal"
integer = "integer"
date_time = "dateTime"
reference = "reference"
binary = "binary"
complex = "complex"

name: str
"""The attribute's name."""

type: AttributeKind
type: Type
"""The attribute's data type."""

sub_attributes: Optional[List["Attribute"]] = None
Expand Down
17 changes: 8 additions & 9 deletions pydantic_scim2/service_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ class ETag(SCIM2Model):
"""A Boolean value specifying whether or not the operation is supported."""


class AuthenticationSchemeKind(str, Enum):
oauth = "oauth"
oauth2 = "oauth2"
oauthbearertoken = "oauthbearertoken"
httpbasic = "httpbasic"
httpdigest = "httpdigest"


class AuthenticationScheme(SCIM2Model):
type: AuthenticationSchemeKind
class Type(str, Enum):
oauth = "oauth"
oauth2 = "oauth2"
oauthbearertoken = "oauthbearertoken"
httpbasic = "httpbasic"
httpdigest = "httpdigest"

type: Type
"""The authentication scheme."""

name: str = Field(
Expand Down
79 changes: 37 additions & 42 deletions pydantic_scim2/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ class Name(SCIM2Model):
)


class EmailKind(str, Enum):
work = "work"
home = "home"
other = "other"


class Email(SCIM2Model):
class Type(str, Enum):
work = "work"
home = "home"
other = "other"

value: Optional[EmailStr] = Field(
None,
description="Email addresses for the user. The value SHOULD be canonicalized by the service provider, e.g., '[email protected]' instead of '[email protected]'. Canonical type values of 'work', 'home', and 'other'.",
Expand All @@ -53,7 +52,7 @@ class Email(SCIM2Model):
None,
description="A human-readable name, primarily used for display purposes. READ-ONLY.",
)
type: Optional[EmailKind] = Field(
type: Optional[Type] = Field(
None,
description="A label indicating the attribute's function, e.g., 'work' or 'home'.",
)
Expand All @@ -63,22 +62,21 @@ class Email(SCIM2Model):
)


class PhoneNumberKind(str, Enum):
work = "work"
home = "home"
mobile = "mobile"
fax = "fax"
pager = "pager"
other = "other"


class PhoneNumber(SCIM2Model):
class Type(str, Enum):
work = "work"
home = "home"
mobile = "mobile"
fax = "fax"
pager = "pager"
other = "other"

value: Optional[str] = Field(None, description="Phone number of the User.")
display: Optional[str] = Field(
None,
description="A human-readable name, primarily used for display purposes. READ-ONLY.",
)
type: Optional[PhoneNumberKind] = Field(
type: Optional[Type] = Field(
None,
description="A label indicating the attribute's function, e.g., 'work', 'home', 'mobile'.",
)
Expand All @@ -88,26 +86,25 @@ class PhoneNumber(SCIM2Model):
)


class ImKind(str, Enum):
aim = "aim"
gtalk = "gtalk"
icq = "icq"
xmpp = "xmpp"
msn = "msn"
skype = "skype"
qq = "qq"
yahoo = "yahoo"


class Im(SCIM2Model):
class Type(str, Enum):
aim = "aim"
gtalk = "gtalk"
icq = "icq"
xmpp = "xmpp"
msn = "msn"
skype = "skype"
qq = "qq"
yahoo = "yahoo"

value: Optional[str] = Field(
None, description="Instant messaging address for the User."
)
display: Optional[str] = Field(
None,
description="A human-readable name, primarily used for display purposes. READ-ONLY.",
)
type: Optional[ImKind] = Field(
type: Optional[Type] = Field(
None,
description="A label indicating the attribute's function, e.g., 'aim', 'gtalk', 'xmpp'.",
)
Expand All @@ -117,18 +114,17 @@ class Im(SCIM2Model):
)


class PhotoKind(str, Enum):
photo = "photo"
thumbnail = "thumbnail"


class Photo(SCIM2Model):
class Type(str, Enum):
photo = "photo"
thumbnail = "thumbnail"

value: Optional[AnyUrl] = Field(None, description="URL of a photo of the User.")
display: Optional[str] = Field(
None,
description="A human-readable name, primarily used for display purposes. READ-ONLY.",
)
type: Optional[PhotoKind] = Field(
type: Optional[Type] = Field(
None,
description="A label indicating the attribute's function, i.e., 'photo' or 'thumbnail'.",
)
Expand All @@ -138,13 +134,12 @@ class Photo(SCIM2Model):
)


class AddressKind(str, Enum):
work = "work"
home = "home"
other = "other"


class Address(SCIM2Model):
class Type(str, Enum):
work = "work"
home = "home"
other = "other"

formatted: Optional[str] = Field(
None,
description="The full mailing address, formatted for display or use with a mailing label. This attribute MAY contain newlines.",
Expand All @@ -159,7 +154,7 @@ class Address(SCIM2Model):
None, description="The zip code or postal code component."
)
country: Optional[str] = Field(None, description="The country name component.")
type: Optional[AddressKind] = Field(
type: Optional[Type] = Field(
None,
description="A label indicating the attribute's function, e.g., 'work' or 'home'.",
)
Expand Down
Loading

0 comments on commit 31129ce

Please sign in to comment.