Package: ldap3-ad-leavers
ldap3-ad-leaversThis is an extension to the orginal projectldap3python library.This library provides facilities to access the ldap3 library and functions that will be helpful when offboarding users from an AD.Getting StartedAssuming that you have Python and virtualenv installed, set up your environment and install the required dependencies using pip:pip install ldap3-ad-leaversUsing the moduleAfter installing the module, you need to import the main class operations object and instantiate it to create a connection to AWS:Currently, the followign class operations available are:UserOps: To manipulate user objects in ADClasses and methodsuser_operationsUserOps__init__get_alldeep_single_searchdeletemoveset_expirationdisablemodelsmodels.core.object_classObjectClass__init__models.coremodels.core.ad_opsAdOperations__init__get_alldeep_single_searchmovedeletemodels.core.exceptionsAdSearchExceptionAdModifyExceptionmodels.data_classes.userUser__init__is_eligible_to_disableis_eligible_for_deletionmodels.data_classes<a id="__init__"></a>__init__<a id="user_operations"></a>user_operations<a id="user_operations.UserOps"></a>UserOps ObjectsclassUserOps(AdOperations)<a id="user_operations.UserOps.__init__"></a>__init__def__init__(hosts,username,password)->NoneThis class will model a User/Person in an AD
It inherits the AdOperations abstract class
Authentication is done in constructor
It users the filter (|(objectclass=user)(objectclass=person)) from ldap3Arguments:hostslist[str]- This is a list of AD hosts that will be added to the Server Poolusernamestr- This is the username that ldap3 will assume to connect to the AD sostspasswordstr- This is the password for the account<a id="user_operations.UserOps.get_all"></a>get_alldefget_all(search_base:str)->list[User]This function will get all User/Person from the given search baseArguments:search_basestr- The AD search base that will be looked up fromRaises:AdSearchException- If the search is not successful, this exception will be raisedReturns:list[User]- The AD list of users obtained<a id="user_operations.UserOps.deep_single_search"></a>deep_single_searchdefdeep_single_search(search_base:str,unique_identifier:str)->UserThis function will search for a single User that matches the unique_identifier criteria.
If multiple is obtained, it will return the first one obtained.Arguments:search_basestr- The AD search base that will be looked up fromunique_identifierstr- A unique identifier that will be used to identify the userReturns:User- returns a User object<a id="user_operations.UserOps.delete"></a>deletedefdelete(distinguished_name:str)->NoneThis function will delete a User from ADArguments:distinguished_namestr- The dn of the UserRaises:AdModifyException- If an error occurs while deleting the User, it will raise this exception<a id="user_operations.UserOps.move"></a>movedefmove(distinguished_name:str,cn:str,new_ou:dict)->NoneThis function will move one User from an OU to anotherArguments:distinguished_namestr- The dn of the Usercnstr- The cn of the Usernew_oudict- The OU where to move the UserRaises:AdModifyException- If an error occurs while moving the User, it will raise this exception<a id="user_operations.UserOps.set_expiration"></a>set_expirationdefset_expiration(distinguished_name:str,expiration_date:datetime)This function will set an expiration on the User's account in ADArguments:distinguished_namestr- The dn of the user accountexpiration_datedatetime- The datetime to expire the accountRaises:AdModifyException- If an error occurs while setting an expiration on the account, it will raise this exception<a id="user_operations.UserOps.disable"></a>disabledefdisable(distinguished_name:str)This function will disable a User account in ADArguments:distinguished_namestr- The dn of the user accountRaises:AdModifyException- If an error occurs while disabling the User, it will raise this exception<a id="models"></a>models<a id="models.core.object_class"></a>models.core.object_class<a id="models.core.object_class.ObjectClass"></a>ObjectClass ObjectsclassObjectClass()<a id="models.core.object_class.ObjectClass.__init__"></a>__init__def__init__(name:str,distinguished_name:str,when_created:datetime)This is the ObjectClass model
This is the Parent class for all AD objectsArguments:namestr- The name of the AD objectdistinguished_namestr- The dn of the AD objectwhen_createddatetime- The datetime when the AD object was created<a id="models.core"></a>models.core<a id="models.core.ad_ops"></a>models.core.ad_ops<a id="models.core.ad_ops.AdOperations"></a>AdOperations ObjectsclassAdOperations(ABC)<a id="models.core.ad_ops.AdOperations.__init__"></a>__init__def__init__(hosts,username:str,password:str)->NoneThis is an abstract class that will model all AD objects of this project
All AD object class operations will inherit from this class
Authentication is done in constructorArguments:hostslist[str]- This is a list of AD hosts that will be added to the Server Poolusernamestr- This is the username that ldap3 will assume to connect to the AD sostspasswordstr- This is the password for the account<a id="models.core.ad_ops.AdOperations.get_all"></a>get_all@abstractmethoddefget_all(search_base:str)->list[ObjectClass]This function will get all objects from the given search baseArguments:search_basestr- The AD search base that will be looked up fromReturns:list[ObjectClass]- The AD list of objects obtained<a id="models.core.ad_ops.AdOperations.deep_single_search"></a>deep_single_search@abstractmethoddefdeep_single_search(search_base:str,unique_identifier:str)->ObjectClassThis function will search for single object that matches the unique_identifier criteria.
If multiple is obtained, it will return the first one obtained.Arguments:search_basestr- The AD search base that will be looked up fromunique_identifierstr- A unique identifier that will be used to identify the objectReturns:ObjectClass- An AD object class<a id="models.core.ad_ops.AdOperations.move"></a>move@abstractmethoddefmove(distinguished_name:str,cn:str,new_ou:dict)->NoneThis function will move one AD object from an OU to anotherArguments:distinguished_namestr- The dn of the AD objectcnstr- The cn of the AD objectnew_oudict- The OU where to move the AD object<a id="models.core.ad_ops.AdOperations.delete"></a>delete@abstractmethoddefdelete(distinguished_name:str)->NoneThis function will delete an AD objectArguments:distinguished_namestr- The dn of the AD object<a id="models.core.exceptions"></a>models.core.exceptions<a id="models.core.exceptions.AdSearchException"></a>AdSearchException ObjectsclassAdSearchException(Exception)Will raise all exceptions that are related to an AD search operationArguments:ExceptionException- Inherits the Exception class<a id="models.core.exceptions.AdModifyException"></a>AdModifyException ObjectsclassAdModifyException(Exception)Will raise all exceptions that are related to an AD Modify operationArguments:ExceptionException- Inherits the Exception class<a id="models.data_classes.user"></a>models.data_classes.user<a id="models.data_classes.user.User"></a>User Objects@dataclassclassUser(ObjectClass)<a id="models.data_classes.user.User.__init__"></a>__init__def__init__(schema:dict)This is the User data class model
It inherits from the ObjectClass model
This class will model a user object in an ADArguments:schemadict- The schema of an AD object that represent a User/Person from ldap3<a id="models.data_classes.user.User.is_eligible_to_disable"></a>is_eligible_to_disabledefis_eligible_to_disable()This function will verify if the user is eligible to have its account disabled
Eligibility will be calculated whether the account has already expired or notReturns:bool- Returns True or False<a id="models.data_classes.user.User.is_eligible_for_deletion"></a>is_eligible_for_deletiondefis_eligible_for_deletion(days_limit:int)This function will verify if the user is eligible to have its account deleted
Eligibility will be calculated whether the days_limit argument has already exceeded the
date that the account has been expiredArguments:days_limitint- The days after which an account is considered eligible to be deleted after it has been expiredReturns:bool- Returns True or False<a id="models.data_classes"></a>models.data_classe__init__user_operationsUserOps__init__get_allmodelsmodels.core.object_classObjectClass__init__models.coremodels.core.ad_opsAdOperations__init__get_alldeep_single_searchmovedeletemodels.core.exceptionsAdSearchExceptionAdModifyExceptionmodels.data_classes.userUser__init__is_eligible_to_disableis_eligible_for_deletionmodels.data_classes<a id="__init__"></a>__init__<a id="user_operations"></a>user_operations<a id="user_operations.UserOps"></a>UserOps ObjectsclassUserOps(AdOperations)<a id="user_operations.UserOps.__init__"></a>__init__def__init__(hosts,username,password)->NoneThis class will model a User/Person in an AD
It inherits the AdOperations abstract class
Authentication is done in constructorArguments:hostslist[str]- This is a list of AD hosts that will be added to the Server Poolusernamestr- This is the username that ldap3 will assume to connect to the AD sostspasswordstr- This is the password for the account<a id="user_operations.UserOps.get_all"></a>get_alldefget_all(search_base:str)->list[User]This function will get all User/Person from the given search baseArguments:search_basestr- The AD search base that will be looked up fromRaises:AdSearchException- If the search is not successful, this exception will be raisedReturns:list[User]- The AD list of users obtained<a id="models"></a>models<a id="models.core.object_class"></a>models.core.object_class<a id="models.core.object_class.ObjectClass"></a>ObjectClass ObjectsclassObjectClass()<a id="models.core.object_class.ObjectClass.__init__"></a>__init__def__init__(name:str,distinguished_name:str,when_created:datetime)This is the ObjectClass model
This is the Parent class for all AD objectsArguments:namestr- The name of the AD objectdistinguished_namestr- The dn of the AD objectwhen_createddatetime- The datetime when the AD object was created<a id="models.core"></a>models.core<a id="models.core.ad_ops"></a>models.core.ad_ops<a id="models.core.ad_ops.AdOperations"></a>AdOperations ObjectsclassAdOperations(ABC)<a id="models.core.ad_ops.AdOperations.__init__"></a>__init__def__init__(hosts,username:str,password:str)->NoneThis is an abstract class that will model all AD objects of this project
All AD object class operations will inherit from this class
Authentication is done in constructorArguments:hostslist[str]- This is a list of AD hosts that will be added to the Server Poolusernamestr- This is the username that ldap3 will assume to connect to the AD sostspasswordstr- This is the password for the account<a id="models.core.ad_ops.AdOperations.get_all"></a>get_all@abstractmethoddefget_all(search_base:str)->list[ObjectClass]This function will get all objects from the given search baseArguments:search_basestr- The AD search base that will be looked up fromReturns:list[ObjectClass]- The AD list of objects obtained<a id="models.core.ad_ops.AdOperations.deep_single_search"></a>deep_single_search@abstractmethoddefdeep_single_search(search_base:str,unique_identifier:str)->ObjectClassThis function will search for single object that matches the unique_identifier criteria.
If multiple is obtained, it will return the first one obtained.Arguments:search_basestr- The AD search base that will be looked up fromunique_identifierstr- A unique identifier that will be used to identify the objectReturns:ObjectClass- An AD object class<a id="models.core.ad_ops.AdOperations.move"></a>move@abstractmethoddefmove(distinguished_name:str,cn:str,new_ou:dict)->NoneThis function will move one AD object from an OU to anotherArguments:distinguished_namestr- The dn of the AD objectcnstr- The cn of the AD objectnew_oudict- The OU where to move the AD object<a id="models.core.ad_ops.AdOperations.delete"></a>delete@abstractmethoddefdelete(distinguished_name:str)->NoneThis function will delete an AD objectArguments:distinguished_namestr- The dn of the AD object<a id="models.core.exceptions"></a>models.core.exceptions<a id="models.core.exceptions.AdSearchException"></a>AdSearchException ObjectsclassAdSearchException(Exception)Will raise all exceptions that are related to an AD search operationArguments:ExceptionException- Inherits the Exception class<a id="models.core.exceptions.AdModifyException"></a>AdModifyException ObjectsclassAdModifyException(Exception)Will raise all exceptions that are related to an AD Modify operationArguments:ExceptionException- Inherits the Exception class<a id="models.data_classes.user"></a>models.data_classes.user<a id="models.data_classes.user.User"></a>User Objects@dataclassclassUser(ObjectClass)<a id="models.data_classes.user.User.__init__"></a>__init__def__init__(schema:dict)This is the User data class model
It inherits from the ObjectClass model
This class will model a user object in an ADArguments:schemadict- The schema of an AD object that represent a User/Person from ldap3<a id="models.data_classes.user.User.is_eligible_to_disable"></a>is_eligible_to_disabledefis_eligible_to_disable()This function will verify if the user is eligible to have its account disabled
Eligibility will be calculated whether the account has already expired or notReturns:bool- Returns True or False<a id="models.data_classes.user.User.is_eligible_for_deletion"></a>is_eligible_for_deletiondefis_eligible_for_deletion(days_limit:int)This function will verify if the user is eligible to have its account deleted
Eligibility will be calculated whether the days_limit argument has already exceeded the
date that the account has been expiredArguments:days_limitint- The days after which an account is considered eligible to be deleted after it has been expiredReturns:bool- Returns True or False<a id="models.data_classes"></a>Running TestsYou can run the tests by following the steps below:Clone or download the project to a folder on your computer.Run the tests using the command./run_test.shLicenseCopyright Mervin Hemaraju