o
    #j=                     @   s   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddl
mZ ddl
mZ ddlmZ dd	lmZ dd
lmZ ejdk rTee ed eeZG dd dejZdd ZeZdS )z7
This module provides a client class for User Service.
    N)bce_base_client)bce_v1_signer)bce_http_client)handler)http_methods)utils)required)compat3zutf-8c                   @   sD  e Zd ZdZdZd#ddZd#ddZ		d$dd	Zee	e
fe	e
fe	e
fd
		d%ddZee	e
fd		d$ddZee	e
fe	e
fd	d&ddZee	e
fd	d&ddZee	e
fed	d&ddZee	e
fed	d&ddZee	e
fed	d&ddZd%ddZee	e
fdd#dd Zee	e
fd	d&d!d"ZdS )'UserServiceClientz
    BLB base sdk client
    s   /v1Nc                 C   s   t j| | dS )u   初始化BceClient对象。

        Args:
            config (dict，可选参数，默认值为None): BceClient的配置字典。

        N)r   BceBaseClient__init__)selfconfig r   j/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/blb/user_service_client.pyr   /   s   zUserServiceClient.__init__c                 C   s(   |du r| j S t| j }|| |S )zg
        :param config:
        :type config: baidubce.BceClientConfiguration
        :return:
        N)r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_config8   s
   
zUserServiceClient._merge_configc              
   C   sJ   |  |}|du rtj}|du rddd}t|tjtj|g|||||S )u  
        发送请求方法

        Args:
            http_method (str): 请求的方法，可选值包括"GET", "POST", "PUT", "DELETE"。
            path (str): 请求路径。
            body (Any, optional): 请求体内容，可以是任意类型。默认值为None。
            headers (dict[bytes, bytes], optional): 请求头信息，以键值对形式存储。默认值为None。
            params (dict[str, str], optional): 请求参数，以键值对形式存储。默认值为None。
            config (dict, optional): 配置信息。
            body_parser (func, optional): 解析响应体的函数。如果为空则默认使用parse_json方法。

        Returns:
            Any: 返回请求返回的内容。
        Ns   */*s   application/json;charset=utf-8)s   Accepts   Content-Type)r   r   Z
parse_jsonr   send_requestr   signZparse_error)r   Zhttp_methodpathbodyheadersparamsr   Zbody_parserr   r   r   _send_requestE   s   

zUserServiceClient._send_request)nameserviceName
instanceIdc                 C   s   t | jd}i }	|du rt |	d< n||	d< i }
|dur$t||
d< ||
d< ||
d< ||
d< |dur9||
d< nd	d
dg|
d< | jtj|t	
|
|	|dS )a  
        Create user service for specified LoadBalancer

        :param name:
                name of user service
        :type name: string

        :param desc:
                description of user service
        :type desc: string

        :param serviceName:
                The name of service
        :type serviceName: string

        :param instanceId:
                The id of LoadBalancer
        :type instanceId: string

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param authList:
                List of Auth information
        :type service: list<Auth>

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        serviceN   clientTokendescriptionr   r   r   authList*Zdeny)uidauthr   r   r   )r   
append_uriversiongenerate_client_tokenr	   convert_to_stringr   r   POSTjsondumps)r   r   descr   r   client_tokenr!   r   r   r   r   r   r   r   create_user_servicea   s$   (


z%UserServiceClient.create_user_service)r   c           	      C   s~   t | jd|}i }|du rt |d< n||d< d|d< i }|dur)t||d< |dur1||d< | jtj|t	
|||dS )a  
        Update user service for specified LoadBalancer

        :param name:
                name of user service
        :type name: string

        :param desc:
                description of user service
        :type desc: string

        :param service:
                domain name of the service
        :type service: string

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s   modifyAttributer    r   r%   )r   r&   r'   r(   r	   r)   r   r   PUTr+   r,   )	r   r   r-   r   r.   r   r   r   r   r   r   r   update_user_service   s   

z%UserServiceClient.update_user_service)r   r   c                 C   s`   t | jd|}i }|du rt |d< n||d< d|d< i }||d< | jtj|t|||dS )ae  
        Bind a specified LoadBalancer to user service

        :param instanceId:
                The id of LoadBalancer
        :type instanceId: string

        :param service:
                domain name of the service
        :type service: string

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s   bindr   r%   	r   r&   r'   r(   r   r   r0   r+   r,   )r   r   r   r.   r   r   r   r   r   r   r   user_service_bind_instance      

z,UserServiceClient.user_service_bind_instancec                 C   sL   t | jd|}i }|du rt |d< n||d< d|d< | jtj|||dS )a  
        Unbind a specified LoadBalancer from user service

        :param service:
                domain name of the service
        :type service: string

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s   unbindr   r   )r   r&   r'   r(   r   r   r0   r   r   r.   r   r   r   r   r   r   user_service_unbind_instance   s   
z.UserServiceClient.user_service_unbind_instance)r   r!   c                 C   `   t | jd|}i }|du rt |d< n||d< d|d< i }||d< | jtj|t|||dS )a  
        Add a new auth information to user service

        :param service:
                domain name of the service
        :type service: string

        :param authList:
                List of Auth information
        :type service: list<Auth>

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s   addAuthr!   r%   r2   r   r   r!   r.   r   r   r   r   r   r   r   user_service_add_auth   s   

z'UserServiceClient.user_service_add_authc                 C   r8   )a]  
        Edit auth information to user service
        :param service:
                domain name of the service
        :type service: string

        :param authList:
                List of Auth information
        :type service: list<Auth>

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s   editAuthr!   r%   r2   r9   r   r   r   user_service_edit_authH  s   

z(UserServiceClient.user_service_edit_auth)r   uidListc                 C   r8   )aV  
        Remove auth information from user service

        :param service:
                domain name of the service
        :type service: string

        :param uidList:
                List of uid
        :type service: list<String>

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   s
   removeAuthr<   r%   r2   )r   r   r<   r.   r   r   r   r   r   r   r   user_service_remove_auths  r4   z*UserServiceClient.user_service_remove_authc                 C   sF   t | jd}i }|dur||d< |dur||d< | jtj|||dS )a  
        Get list of user service

        :param marker:
                Mark the start position of query
        :type marker: string

        :param max_keys:
               Max number of one page, default number is 1000
        :type max_keys: integer

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Ns   markers   maxKeysr5   r   r&   r'   r   r   GET)r   markerZmax_keysr   r   r   r   r   r   get_user_service_list  s   
z'UserServiceClient.get_user_service_listc                 C   s"   t | jd|}| jtj||dS )a(  
        Get user service detail information

        :param service:
                domain name of the service
        :type service: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   )r   r>   )r   r   r   r   r   r   r   get_user_service_detail  s   z)UserServiceClient.get_user_service_detailc                 C   sD   t | jd|}i }|du rt |d< n||d< | jtj|||dS )a  
        Delete user service

        :param service:
                domain name of the service
        :type service: string

        :param client_token:
                If the clientToken is not specified by the user,
                a random String generated by default algorithm will be used.
        :type client_token: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Nr   r5   )r   r&   r'   r(   r   r   DELETEr6   r   r   r   delete_user_service  s   
z%UserServiceClient.delete_user_service)N)NNNNN)NNN)NN)__name__
__module____qualname____doc__r'   r   r   r   r   bytesstrr/   r1   r3   r7   listr:   r;   r=   rA   rB   rD   r   r   r   r   r   )   s`    

	
<0*"&)
*r   c                   C   s   t t S )z
    The default method to generate the random string for client_token
    if the optional parameter client_token is not specified by the user.

    :return:
    :rtype string
    )rJ   uuiduuid4r   r   r   r   generate_client_token_by_uuid  s   rN   )rH   r   r+   loggingrL   sysZbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   r   Zbaidubce.utilsr   r	   r'   reloadZsetdefaultencoding	getLoggerrE   _loggerr   r   rN   r(   r   r   r   r   <module>   s0   


   N