o
    e-                     @   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 rPed eeZG dd dejZdd ZeZdS )z.
This module provides a client class for ACL.
    N)bce_base_client)bce_v1_signer)bce_http_client)handler)http_methods)utils)required)compat3zutf-8c                   @   s   e Zd ZdZdZdddZdddZ		ddd	Zee	e
fd
dddZeeddddZee	e
fddddZee	e
fddddZee	e
fd						dddZdS )	AclClientz
    ACL base sdk client
    s   /v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   PD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/vpc/acl_client.pyr   .   s   zAclClient.__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_config1   s
   
zAclClient._merge_configc              
   C   sJ   |  |}|d u rtj}|d u rddd}t|tjtj|g|||||S )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_request>   s   

zAclClient._send_request)vpc_idc                 C   s.   t | jd}i }||d< | jtj|||dS )a"  
        Get the detail information of acl for specific vpc.

        :param vpc_id:
            the vpc id
        :type vpc_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        acls   vpcIdr   r   r   
append_uriprefixr   r   GET)r   r   r   r   r   r   r   r   list_acl_entrysL   s   
zAclClient.list_acl_entrys)	rule_listc                 C   sT   t | jdd}i }|du rt |d< n||d< d|i}| jtj|t|||dS )a,  
        Create  acl rules with the specified options.

        :param rule_list:
                a list contains acl rules.
                https://cloud.baidu.com/doc/VPC/API.html#AclRuleRequest
                The elements of the list are AclRuleRequest
        :type rule_list: list

        AclRuleRequest{
            :param protocol:
                The parameter specify which protocol will the acl rule work on
            :value: "all" or ""tcp" or "udp" or "icmp"
            :type protocol: string

            :param sourceIpAddress:
                Source ip address which the rule applied to
            :type sourceIpAddress: string

            :param destinationIpAddress:
                Destination ip address which the rule applied to
            :type destinationIpAddress: string

            :param sourcePort:
                Port used by source ip address
            :value 1-65535
            :type sourcePort: string

            :param destinationPort:
                Port used by destination ip address
            :value 1-65535
            :type destinationPort:string

            :param position:
                Priority of the rule
            :value 1-5000,unique,The smaller the value, the higher the priority
            :type:position:Integer

            :param direction:
                The rule is a ingress or a egress rule
            :value: "ingress" or "egress"
            :type direction:string

            :param action:
                The rule is allowed or denied
            :value "allow" or "deny"
            :type action:string

            :param description(Optional):
                The option param to describe the acl rule.
            :type description: string
        }

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   ruleN   clientTokenZaclRules)r   r   r   )	r   r    r!   generate_client_tokenr   r   POSTjsondumps)r   r$   client_tokenr   r   r   r   r   r   r   
create_aclb   s   B

zAclClient.create_acl)	subnet_idc                 C   sP   t | jdd}i }|dur||d< |dur||d< ||d< | jtj|||dS )a  
        Return a list of acl rules of specify subnet.

        :param subnet_id
            the id of subnet whhich the acl applied
        :type subnet_id: string

        :param marker
            The optional parameter marker specified in the original
            request to specify where in the results to begin listing.
            Together with the marker, specifies the list result
            which listing should begin. If the marker is not specified,
            the list result will listing from the first one.
        :type marker: string

        :param max_keys
            The optional parameter to specifies the max number of
            list result to return.
            The default value is 1000.
        :type max_keys: int

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
         r   r%   Ns   markers   maxKeyss   subnetIdr   r   )r   r-   markerZmax_keysr   r   r   r   r   r   list_subnet_acl   s   
zAclClient.list_subnet_acl)acl_rule_idc                 C   sF   t | jdd|}i }|du rt |d< n||d< | jtj|||dS )a  
        Delete the  specific acl rule.

        :param acl_rule_id:
            The id of the specified acl.
        :type acl_rule_id: 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   r%   Nr&   r   )r   r    r!   r'   r   r   DELETE)r   r0   r+   r   r   r   r   r   r   
delete_acl   s   
zAclClient.delete_aclc                 C   s   t | jdd|}i }|
du rt |d< n|
|d< i }|dur&t||d< |dur1t||d< |dur<t||d< |durGt||d< |durRt||d	< |dur]t||d
< |dure||d< |	durpt|	|d< | jtj|t	
|||dS )a  
        Modify the special attribute to new value of the acl owned by the user.

        :param acl_rule_id
                id of the acl to be modified
        :type acl_rule_id:string

        :param description:
                The option param to describe the acl rule.
        :type description: string

        :param protocol:
                 The parameter specify which protocol will the acl rule work on
        :value: "all" or ""tcp" or "udp" or "icmp"
        :type protocol: string

        :param source_ip_address:
                 source ip address which the rule applied to
        :type source_ip_address: string

        :param destination_ip_address:
                 destination ip address which the rule applied to
        :type destination_ip_address: string

        :param source_port:
                 port used by source ip address
        :value 1-65535
        :type source_port: string

        :param destination_port:
                 port used by destination ip address
        :value 1-65535
        :type destination_port:string

        :param position:
                 priority of the rule
        :value 1-5000,unique,The smaller the value, the higher the priority
        :type:position:Integer

        :param action:
                the rule is allowed or denied
        :value "allow" or "deny"
        :type action: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   r%   Nr&   descriptionprotocolZsourceIpAddressZdestinationIpAddressZ
sourcePortZdestinationPortpositionactionr   )r   r    r!   r'   r	   Zconvert_to_stringr   r   PUTr)   r*   )r   r0   r3   r4   Zsource_ip_addressZdestination_ip_addressZsource_portZdestination_portr5   r6   r+   r   r   r   r   r   r   r   
update_acl   s8   >zAclClient.update_aclr   )NNNNN)NN)NNN)
NNNNNNNNNN)__name__
__module____qualname____doc__r!   r   r   r   r   bytesstrr#   listr,   r/   r2   r8   r   r   r   r   r   (   s0    


Q(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
    )r>   uuiduuid4r   r   r   r   generate_client_token_by_uuid`  s   rB   )r<   r   r)   loggingr@   sysZbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   r   Zbaidubce.utilsr   r	   versionZsetdefaultencoding	getLoggerr9   Z_loggerr   r   rB   r'   r   r   r   r   <module>   s,   


  :