-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from alan-turing-institute/16-validate-ldap
Validate LDAP data
- Loading branch information
Showing
15 changed files
with
285 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .ldap_group_of_names import LdapGroupOfNames | ||
from .ldap_inetorgperson import LdapInetOrgPerson | ||
from .ldap_inetuser import LdapInetUser | ||
from .ldap_person import LdapPerson | ||
from .ldap_posix_account import LdapPosixAccount | ||
from .ldap_posix_group import LdapPosixGroup | ||
|
||
__all__ = [ | ||
"LdapGroupOfNames", | ||
"LdapInetOrgPerson", | ||
"LdapInetUser", | ||
"LdapPerson", | ||
"LdapPosixAccount", | ||
"LdapPosixGroup", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class LdapGroupOfNames(BaseModel): | ||
cn: str | ||
description: str | ||
member: list[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class LdapInetOrgPerson(BaseModel): | ||
cn: str | ||
description: str | ||
displayName: str # noqa: N815 | ||
givenName: str # noqa: N815 | ||
sn: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class LdapInetUser(BaseModel): | ||
memberOf: list[str] # noqa: N815 | ||
uid: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class LdapPerson(BaseModel): | ||
cn: str | ||
sn: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import re | ||
|
||
from pydantic import BaseModel, StringConstraints, validator | ||
from typing_extensions import Annotated | ||
|
||
ID_MIN = 2000 | ||
ID_MAX = 60000 | ||
|
||
|
||
class LdapPosixAccount(BaseModel): | ||
cn: str | ||
gidNumber: int # noqa: N815 | ||
homeDirectory: Annotated[ # noqa: N815 | ||
str, StringConstraints(strip_whitespace=True, to_lower=True) | ||
] | ||
uid: str | ||
uidNumber: int # noqa: N815 | ||
|
||
@validator("gidNumber") # type: ignore[misc] | ||
@classmethod | ||
def validate_gid_number(cls, gid_number: int) -> int: | ||
"""Avoid conflicts with existing users""" | ||
if not ID_MIN <= gid_number <= ID_MAX: | ||
msg = f"Must be in range {ID_MIN} to {ID_MAX}." | ||
raise ValueError(msg) | ||
return gid_number | ||
|
||
@validator("homeDirectory") # type: ignore[misc] | ||
@classmethod | ||
def validate_home_directory(cls, home_directory: str) -> str: | ||
return re.sub(r"\s+", "-", home_directory) | ||
|
||
@validator("uidNumber") # type: ignore[misc] | ||
@classmethod | ||
def validate_uid_number(cls, uid_number: int) -> int: | ||
"""Avoid conflicts with existing users""" | ||
if not ID_MIN <= uid_number <= ID_MAX: | ||
msg = f"Must be in range {ID_MIN} to {ID_MAX}." | ||
raise ValueError(msg) | ||
return uid_number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pydantic import BaseModel, validator | ||
|
||
ID_MIN = 2000 | ||
ID_MAX = 4294967295 | ||
|
||
|
||
class LdapPosixGroup(BaseModel): | ||
description: str | ||
gidNumber: int # noqa: N815 | ||
memberUid: list[str] # noqa: N815 | ||
|
||
@validator("gidNumber") # type: ignore[misc] | ||
@classmethod | ||
def validate_gid_number(cls, gid_number: int) -> int: | ||
"""Avoid conflicts with existing groups""" | ||
if not ID_MIN <= gid_number <= ID_MAX: | ||
msg = f"Must be in range {ID_MIN} to {ID_MAX}." | ||
raise ValueError(msg) | ||
return gid_number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.