
    L^iL                         d dl mZ d dlmZ dZdZdZdZ G d de          Z	d!d
Z
	 	 d"dZd Zd Zd"dZd#dZd$dZd Zd Zd"dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd"dZd%dZd!dZd%d Z d	S )&    )_call_account_api)encode_listsub_accountsusersuser_groupsaccess_keysc                   .    e Zd ZdZdZdZdZdZdZdZ	dZ
d	S )
RolezM
    A user role to use in the user management API (create/update user).
    master_adminadminbillingtechnical_adminreportsmedia_library_adminmedia_library_userN)__name__
__module____qualname____doc__MASTER_ADMINADMINBILLINGTECHNICAL_ADMINREPORTSMEDIA_LIBRARY_ADMINMEDIA_LIBRARY_USER     BD:\Nbitz\venv\Lib\site-packages\cloudinary/provisioning/account.pyr
   r
   
   sA          "LEG'OG/-r   r
   Nc                 >    t           g}|| |d}t          d|fd|i|S )a  
    List all sub accounts
    :param enabled:     Whether to only return enabled sub-accounts (true) or disabled accounts (false).
                        Default: all accounts are returned (both enabled and disabled).
    :type enabled:      bool, optional
    :param ids:         List of sub-account IDs. Up to 100. When provided, other filters are ignored.
    :type ids:          list, optional
    :param prefix:      Search by prefix of the sub-account name. Case-insensitive.
    :type prefix:       str, optional
    :param options:     Generic advanced options dict, see online documentation
    :type options:      dict, optional
    :return:            A list of sub accounts
    :rtype:             dict
    )idsenabledprefixGETparamsSUB_ACCOUNTS_SUB_PATHr   )r"   r!   r#   optionsurir%   s         r   r   r      s8     !
!CW??FUCBBB'BBBr   c                 B    t           g}| ||||d}t          d|fd|i|S )a  
    Create a new sub account
    :param name:                Name of the new sub account
    :type name:                 str
    :param cloud_name:          A case-insensitive cloud name comprised of alphanumeric and underscore characters.
                                * Generates an error if the cloud name is not unique across all Cloudinary accounts.
    :type cloud_name:           str, optional
    :param custom_attributes:   Any custom attributes you want to associate with the sub-account
    :type custom_attributes:    dict, optional
    :param enabled:             Whether to create the account as enabled (default is enabled).
    :type enabled:              bool, optional
    :param base_account:        ID of sub-account from which to copy settings
    :type base_account:         str, optional
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    The created sub account
    :rtype:                     dict
    )name
cloud_namecustom_attributesr"   base_sub_account_idPOSTr%   r&   )r+   r,   r-   r"   base_accountr(   r)   r%   s           r   create_sub_accountr1   +   sF    ( !
!C&#4 %1	3 3F
 VSCCC7CCCr   c                 2    t           | g}t          d|i fi |S )aW  
    Delete a sub account
    :param sub_account_id:      The id of the sub account
    :type sub_account_id:       str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    Result message
    :rtype:                     dict
    deleter&   sub_account_idr(   r)   s      r   delete_sub_accountr6   H   s(     !.
1CXsB::':::r   c                 2    t           | g}t          d|i fi |S )ab  
    Get information of a sub account
    :param sub_account_id:      The id of the sub account
    :type sub_account_id:       str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    A sub account
    :rtype:                     dict
    getr&   r4   s      r   sub_accountr9   V   s(     !.
1CUC77w777r   c                 B    t           | g}||||d}t          d|fd|i|S )a=  
    Update a sub account
    :param sub_account_id:      The id of the sub account
    :type sub_account_id:       str
    :param name:                Name of the account
    :type name:                 str, optional
    :param cloud_name:          Unique cloud name
    :type cloud_name:           str, optional
    :param custom_attributes:   Any custom attributes you want to associate with the sub-account.
    :type custom_attributes:    dict, optional
    :param enabled:             Whether to create the account as enabled (default is enabled).
    :type enabled:              bool, optional
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    Updated sub account
    :rtype:                     dict
    )r+   r,   r-   r"   putr%   r&   )r5   r+   r,   r-   r"   r(   r)   r%   s           r   update_sub_accountr<   d   sE    $ !.
1C&#4 " "F UCBBB'BBBr   c                 d    t           g}t          |           } | ||||||d}	t          d|fd|	i|S )a  
    List all users
    :param user_ids:        The ids of the users to fetch
    :type user_ids:         list, optional
    :param sub_account_id:  The id of a sub account
    :type sub_account_id:   str, optional
    :param pending:         Limit results to pending users (True),
                            users that are not pending (False),
                            or all users (None, the default).
    :type pending:          bool, optional
    :param prefix:          User prefix
    :type prefix:           str, optional
    :param last_login:      Return only users that last logged in in the specified range of dates (true), 
                            users that didn't last logged in in that range (false), or all users (None).
    :type last_login:       bool, optional
    :param from_date:       Last login start date.
    :type from_date:        datetime, optional
    :param to_date:         Last login end date.
    :type to_date:          datetime, optional
    :param options:         Generic advanced options dict, see online documentation.
    :type options:          dict, optional
    :return:                List of users associated with the account
    :rtype:                 dict
    )r!   r5   pendingr#   
last_loginfromtor8   r%   )USERS_SUB_PATHr   r   )
user_idsr5   r>   r#   r?   	from_dateto_dater(   r)   r%   s
             r   r   r   ~   sY    4 
C8$$H . & F UCBBB'BBBr   c                 @    t           g}| |||d}t          d|fd|i|S )ak  
    Create a user
    :param name:                Username
    :type name:                 str
    :param email:               User's email
    :type email:                str
    :param role:                User's role
    :type role:                 str
    :param sub_account_ids:     Optional. Sub accounts to associate with the user
    :type sub_account_ids:      list, optional
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    Details of created user
    :rtype:                     dict
    r+   emailrolesub_account_idspostr%   rB   r   )r+   rH   rI   rJ   r(   r)   r%   s          r   create_userrM      sC      
C!02 2F VSCCC7CCCr   c                 2    t           | g}t          d|i fi |S )aP  
    Delete a user
    :param user_id:             The id of user to delete
    :type user_id:              str
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    Result message
    :rtype:                     dict
    r3   rL   user_idr(   r)   s      r   delete_userrQ      s(     7
#CXsB::':::r   c                 2    t           | g}t          d|i fi |S )aN  
    Get information of a user
    :param user_id:             The id of the user
    :type user_id:              str
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    A user
    :rtype:                     dict
    r8   rL   rO   s      r   userrS      s(     7
#CUC77w777r   c                 B    t           | g}||||d}t          d|fd|i|S )aS  
    Update a user
    :param user_id:             The id of the user to update
    :type user_id:              str
    :param name:                Username
    :type name:                 str, optional
    :param email:               User's email
    :type email:                str, optional
    :param role:                User's role
    :type role:                 Role, optional
    :param sub_account_ids:     The list of sub-account IDs that this user can access.
                                Note: This parameter is ignored if the role is specified as master_admin.
    :type sub_account_ids:      list, optional
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    The updated user
    :rtype:                     dict
    rG   r;   r%   rL   )rP   r+   rH   rI   rJ   r(   r)   r%   s           r   update_userrU      sE    & 7
#C!02 2F UCBBB'BBBr   c                  0    t           g}t          d|i fi | S )a   
    List all user groups
    :param options:         Generic advanced options dict, see online documentation
    :type options:          dict, optional
    :return:                List of user groups
    :rtype:                 ProvisioningAPIRespose
    r8   USER_GROUPS_SUB_PATHr   )r(   r)   s     r   r   r      s&      
 CUC77w777r   c                 8    t           g}d| i}t          d||fi |S )aH  
    Create a new user group
    :param name:            Name of the user group
    :type name:             str
    :param options:         Generic advanced options dict, see online documentation
    :type options:          dict, optional
    :return:                The newly created group
    :rtype:                 dict
    r+   rK   rW   )r+   r(   r)   r%   s       r   create_user_grouprZ      s/      
 Cd^FVS&<<G<<<r   c                 :    t           | g}d|i}t          d||fi |S )a  
    Update a user group
    :param user_group_id:       The id of the user group to update
    :type user_group_id:        str
    :param name:                Name of the user group
    :type name:                 str, optional
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    The updated group
    :rtype:                     dict
    r+   r;   rW   )user_group_idr+   r(   r)   r%   s        r   update_user_groupr]     s1      
/Cd^FUC;;7;;;r   c                 2    t           | g}t          d|i fi |S )ac  
    Delete a user group
    :param user_group_id:       The id of the user group to delete
    :type user_group_id:        str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    The result message
    :rtype:                     dict
    r3   rW   r\   r(   r)   s      r   delete_user_groupr`     s(      
/CXsB::':::r   c                 2    t           | g}t          d|i fi |S )ag  
    Get information of a user group
    :param user_group_id:       The id of the user group
    :type user_group_id:        str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    Details of the group
    :rtype:                     dict
    r8   rW   r_   s      r   
user_grouprb   -  s(      
/CUC77w777r   c                 6    t           | d|g}t          d|i fi |S )a  
    Add a user to a user group
    :param user_group_id:       The id of the user group to add the user to
    :type user_group_id:        str
    :param user_id:             The user id to add
    :type user_id:              str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    List of users in the group
    :rtype:                     dict
    r   rK   rW   r\   rP   r(   r)   s       r   add_user_to_groupre   ;  s,      
ACVS"88888r   c                 6    t           | d|g}t          d|i fi |S )a  
    Remove a user from a user group
    :param user_group_id:       The id of the user group to remove the user from
    :type user_group_id:        str
    :param user_id:             The id of the user to remove
    :type user_id:              str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    List of users in the group
    :rtype:                     dict
    r   r3   rW   rd   s       r   remove_user_from_grouprg   K  s,      
ACXsB::':::r   c                 4    t           | dg}t          d|i fi |S )a|  
    Get all users in a user group
    :param user_group_id:       The id of user group to get list of users
    :type user_group_id:        str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    List of users in the group
    :rtype:                     dict
    r   r8   rW   r_   s      r   user_group_usersri   [  s*      
8CUC77w777r   c                 2    t           | g}t          d|i fi |S )ah  
    Get all user groups a user belongs to
    :param user_id:             The id of user
    :type user_id:              str
    :param options:             Generic advanced options dict, see online documentation
    :type options:              dict, optional
    :return:                    List of groups user is in
    :rtype:                     dict
    r8   rW   rO   s      r   user_in_user_groupsrk   i  s(      
)CUC77w777r   c                 L    t           | t          g}||||d}t          d||fi |S )a  
    Get sub account access keys.

    :param sub_account_id:  The id of the sub account.
    :type sub_account_id:   str
    :param page_size:       How many entries to display on each page.
    :type page_size:        int
    :param page:            Which page to return (maximum pages: 100). **Default**: All pages are returned.
    :type page:             int
    :param sort_by:         Which response parameter to sort by.
                                **Possible values**: `api_key`, `created_at`, `name`, `enabled`.
    :type sort_by:          str
    :param sort_order:      Control the order of returned keys. **Possible values**: `desc` (default), `asc`.
    :type sort_order:       str
    :param options:         Generic advanced options dict, see online documentation.
    :type options:          dict, optional
    :return:                List of access keys
    :rtype:                 dict
    )	page_sizepagesort_by
sort_orderr8   r'   ACCESS_KEYSr   )r5   rm   rn   ro   rp   r(   r)   r%   s           r   r   r   w  sD    ( !.+
>C 	 F UC;;7;;;r   c                 H    t           | t          g}||d}t          d||fi |S )a@  
    Generate a new access key.

    :param sub_account_id:      The id of the sub account.
    :type sub_account_id:       str
    :param name:                The name of the new access key.
    :type name:                 str
    :param enabled:             Whether the new access key is enabled or disabled.
    :type enabled:              bool
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    Access key details
    :rtype:                     dict
    )r+   r"   rK   rq   )r5   r+   r"   r(   r)   r%   s         r   generate_access_keyrt     s>     !.+
>C F VS&<<G<<<r   c                 f    t           | t          t          |          g}|||d}t          d||fi |S )a  
    Update the name and/or status of an existing access key.

    :param sub_account_id:      The id of the sub account.
    :type sub_account_id:       str
    :param api_key:             The API key of the access key.
    :type api_key:              str|int
    :param name:                The updated name of the access key.
    :type name:                 str
    :param enabled:             Enable or disable the access key.
    :type enabled:              bool
    :param dedicated_for:       Designates the access key for a specific purpose while allowing it to be used for
                                other purposes, as well. This action replaces any previously assigned key.
                                **Possible values**: `webhooks`
    :type dedicated_for:        str
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    Access key details
    :rtype:                     dict
    )r+   r"   dedicated_forr;   )r'   rr   strr   )r5   api_keyr+   r"   rv   r(   r)   r%   s           r   update_access_keyry     sI    * !.+s7||
LC& F
 UC;;7;;;r   c                     t           | t          g}|"|                    t          |                     d|i}t	          d||fi |S )aD  
    Delete an existing access key by api_key or by name.

    :param sub_account_id:      The id of the sub account.
    :type sub_account_id:       str
    :param api_key:             The API key of the access key.
    :type api_key:              str|int
    :param name:                The name of the access key.
    :type name:                 str
    :param options:             Generic advanced options dict, see online documentation.
    :type options:              dict, optional
    :return:                    Operation status.
    :rtype:                     dict
    Nr+   r3   )r'   rr   appendrw   r   )r5   rx   r+   r(   r)   r%   s         r   delete_access_keyr|     sX     !.+
>C

3w<<    	F XsF>>g>>>r   )NNN)NNNN)NNNNNNN)N)NN)!&cloudinary.api_client.call_account_apir   cloudinary.utilsr   r'   rB   rX   rr   objectr
   r   r1   r6   r9   r<   r   rM   rQ   rS   rU   r   rZ   r]   r`   rb   re   rg   ri   rk   r   rt   ry   r|   r   r   r   <module>r      s!   D D D D D D ( ( ( ( ( (& $ 
. 
. 
. 
. 
.6 
. 
. 
.C C C C( OS$(D D D D:; ; ;8 8 8C C C C4#C #C #C #CLD D D D0; ; ;8 8 8C C C C6	8 	8 	8= = =< < <"; ; ;8 8 89 9 9 ; ; ; 8 8 88 8 8< < < <<= = = =.< < < <<? ? ? ? ? ?r   