
    9i3                         S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr   " S S\R&                  5      rS r\rg)z.
This module provides a client class for esg.
    )unicode_literalsN)bce_base_client)compat)bce_v1_signer)bce_http_client)handler)http_methods)	esg_model)requiredc                   "   \ rS rSrSrSrSS jrSS jr  SS jr\	" \
\4\S9     SS	 j5       rSS
 jr\	" \
\4S9SS j5       r\	" \
\4\R"                  S9  SS j5       r\	" \
\4S9          SS j5       r\	" \
\4S9SS j5       rSrg)	EsgClient    z
Bcc base sdk client
s   /v1Nc                 B    [         R                  R                  X5        g N)r   BceBaseClient__init__)selfconfigs     `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/esg/esg_client.pyr   EsgClient.__init__'   s    %%..t<    c                     Uc  U R                   $ [        R                  " U R                   5      nUR                  U5        U$ r   )r   copymerge_non_none_values)r   r   
new_configs      r   _merge_configEsgClient._merge_config*   s7    >;;4;;/J,,V4r   c	           
          U R                  U5      nUc  [        R                  nUc  [        R                  n[
        R                  " U[        R                  [        R                  U/XU-   X4U5      $ r   )
r   r   
parse_jsonr   prefixr   send_requestr   signparse_error)	r   http_methodpathbodyheadersparamsr   body_parserr    s	            r   _send_requestEsgClient._send_request2   sk     ##F+!,,K>%%F++M&&)<)<k(J$v? 	?r   )namerulesc                 8   SnSUc
  [        5       OU0nU V	s/ s H  oR                  PM     n
n	UUU
S.nUb  X;S'   Ub  U Vs/ s H  oR                  PM     nnXS'   U R                  [        R                  U[
        R                  " U5      XS9$ s  sn	f s  snf )aL  
Creating a newly esg with specified rules.

:param name:
    The name of esg that will be created.
:type name: string

:param rules:
    The list of rules which define how the esg works.
:type rules: list<esg_model.EnterpriseSecurityGroupRuleModel>

:param desc:
    The optional parameter to describe the esg that will be created.
:type desc: string

:param tags:
    The optional list of tag to be bonded.
:type tags: list<esg_model.TagModel>

:param client_token:
    An ASCII string whose length is less than 64.
    The request will be idempotent if client token is provided.
    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
   /enterprise/securityclientToken)r,   descr-   r1   tagsr(   r   )generate_client_token__dict__r*   r	   POSTjsondumps)r   r,   r-   r1   r2   client_tokenr   r%   r(   rule	rule_listr&   tagtag_lists                 r    create_enterprise_security_group*EsgClient.create_enterprise_security_group?   s    N 'l6J02P\
 055ut]]u	5

 L045H5#L!!,"3"3T4::d;KTZ!jj 6 6s   BBc                 r    Sn0 nUb  XS'   Ub  X&S'   Ub  X6S'   U R                  [        R                  XVUS9$ )a  
Listing EnterpriseSecurityGroup owned by the authenticated user.

    :param instance_id:
        The id of instance. The optional parameter to list the SecurityGroup.
        If it's specified,only the SecurityGroup related to the specified instance will be listed
    :type instance_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/   
instanceIdmarkermaxKeysr3   )r*   r	   GET)r   instance_idrB   max_keysr   r%   r(   s          r   list_enterprise_security_groups)EsgClient.list_enterprise_security_groupsw   sW    6 '"#.< %8 (9!!,"2"2DPV!WWr   )enterprise_security_group_idc                 t    [         R                  " U5      nSU-  nU R                  [        R                  X2S9$ )a<  
Deleting the specified EnterpriseSecurityGroup.

    :param enterprise_security_group_id:
        The id of SecurityGroup that will be deleted.
    :type enterprise_security_group_id: string

    :param config:
        :type config: baidubce.BceClientConfiguration
:return:
:rtype baidubce.bce_response.BceResponse
   /enterprise/security/%s)r   r   convert_to_bytesr*   r	   DELETE)r   rI   r   r%   s       r    delete_enterprise_security_group*EsgClient.delete_enterprise_security_group   s=     (.'>'>?['\$),HH!!,"5"5t!KKr   )rI   r:   c                    [         R                  " U5      nSU-  nSS0nUc  [        5       US'   OX6S'   U Vs/ s H  owR                  PM     nnSU0n	U R	                  [
        R                  U[        R                  " U	5      XdS9$ s  snf )a  
authorize a security group rule to the specified security group

    :param enterprise_security_group_id:
        The id of EnterpriseSecurityGroup that will be authorized.
    :type enterprise_security_group_id: string

    :param rules:
        The list of rules which define how the esg works.
    :type rules: list<esg_model.EnterpriseSecurityGroupRuleModel>

    :param client_token:
        An ASCII string whose length is less than 64.
        The request will be idempotent if client token is provided.
        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
rK   authorizeRule r0   r-   r3   )	r   rM   r4   r5   r*   r	   PUTr7   r8   )
r   rI   r-   r9   r   r%   r(   r:   r;   r&   s
             r   (authorize_enterprise_security_group_rule2EsgClient.authorize_enterprise_security_group_rule   s    : (.'>'>?['\$),HH!2&$9$;F=!$0=!/45ut]]u	5Y
 !!,"2"2D$**T:JSY!ii	 6s   B)!enterprise_security_group_rule_idc                     [         R                  " U5      nSU-  nUUUUUUUUU	U
S.
nU R                  [        R                  U[
        R                  " U5      SUS9$ )a@  
uodate a enterprise security group rule from the specified security group
:param enterprise_security_group_rule_id:
    The id of EnterpriseSecurityGroupRule that will be updated.
:param: remark:
    The remark for the rule.
:param: portrange:
    The port range to specify the port which the rule will work on.
    Available range is rang [0, 65535], the fault value is "" for all port.
:param: source_portrange:
    The source port range to specify the port which the rule will work on.
    Available range is rang [0, 65535], the fault value is "" for all port.
:param: protocol:
    The parameter specify which protocol will the rule work on, the fault value is "" for all protocol.
    Available protocol are tcp, udp and icmp.
:param: source_ip:
    The source ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
    other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
    Only works for  direction = "ingress".
:param: dest_ip:
    The destination ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
    other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
    Only works for  direction = "egress".
:param: local_ip:
    The parameter specify the localIP (allow all ip address: all).
:param: priority:
    The parameter specify the priority of the rule(range 1-1000).
:param: action:
    The parameter specify the action of the rule, available value are "allow/deny".
:param config:
    :type config: baidubce.BceClientConfiguration
:return:
:rtype baidubce.bce_response.BceResponse
   /enterprise/security/rule/%s)
enterpriseSecurityGroupRuleIdremarkprotocol	portRangesourceIpdestIpactionlocalIpprioritysourcePortRangeNr3   )r   rM   r*   r	   rT   r7   r8   )r   rW   r[   r\   	portrange	source_ipdest_ipr`   local_iprb   source_portranger   r%   r&   s                 r   %update_enterprise_security_group_rule/EsgClient.update_enterprise_security_group_rule   sv    \ -3,C,CDe,f).1RR-N "! /
 !!,"2"2D$**T:JSW`f!ggr   c                 x    [         R                  " U5      nSU-  nU R                  [        R                  USUS9$ )aT  
delete a enterprise security group rule from the specified security group
:param enterprise_security_group_rule_id:
    The id of EnterpriseSecurityGroupRule that will be deleted.
:type enterprise_security_group_id: string

:param config:
    :type config: baidubce.BceClientConfiguration
:return:
:rtype baidubce.bce_response.BceResponse
rY   Nr3   rL   )r   rW   r   r%   s       r   %delete_enterprise_security_group_rule/EsgClient.delete_enterprise_security_group_rule  sB     -3,C,CDe,f).1RR!!,"5"5tDQW!XXr    r   )NNNNNN)NNNNN)NNNN)NN)
NNNNNNNNNN)__name__
__module____qualname____firstlineno____doc__r    r   r   r*   r   bytesstrlistr>   rG   rO   r
    EnterpriseSecurityGroupRuleModelrU   ri   rl   __static_attributes__rn   r   r   r   r       s    F= 7;<@? E3<;?.2.26:04	4k4kl$XL E3<8L 9L" E3<==? ?C8<&j?&jP =597;8<8<6:597;7;?C59;h >;hz =Y >Yr   r   c                  >    [        [        R                  " 5       5      $ )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
)ru   uuiduuid4rn   r   r   generate_client_token_by_uuidr|   )  s     tzz|r   )rs   
__future__r   r   r7   rz   baidubcer   r   baidubce.authr   baidubce.httpr   r   r	   baidubce.services.esgr
   baidubce.utilsr   r   r   r|   r4   rn   r   r   <module>r      sT    (    $  ' ) ! & + #FY-- FYR 6 r   