o
    !d<!                     @   s   d Z ddlmZ dd Zdd Zdd Zd	efd
efdefdefdefdefdefdefdefdefdefdefgZdZdZdZ	dZ
dZdd Zdd ZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZd(S ))a  
This customization adds the following scalar parameters to the
authorize operations:

* --protocol: tcp | udp | icmp or any protocol number
* --port:  A single integer or a range (min-max). You can specify ``all``
  to mean all ports (for example, port range 0-65535)
* --source-group: Either the source security group ID or name.
* --cidr -  The IPv4 address range, in CIDR format. Cannot be used when specifying a source or
  destination security group.
    )CustomArgumentc                 K   s   t dtd}|| d< d| d _tdtd}|| d< d| d _d| d _tdtd}|| d< d| d	 _td
td}|| d
< d| d _t	dt
d}|| d< d| d _d S )Nprotocol)Z	help_textTzip-protocolportz	from-portzto-portcidrzcidr-ipzsource-groupzsource-security-group-namezgroup-ownerzsource-security-group-owner-id)ProtocolArgumentPROTOCOL_DOCSZ_UNDOCUMENTEDPortArgument	PORT_DOCSCidrArgument	CIDR_DOCSSourceGroupArgumentSOURCEGROUP_DOCSGroupOwnerArgumentGROUPOWNER_DOCS)Zargument_tablekwargsarg r   Nusr/lib/python3.10/site-packages/awscli/customizations/ec2/secgroupsimplify.py_add_params   s,   




r   c                 K   s:   t | }|d rdD ]}|| rd| }t|q
d S d S )Nip_permissions)r   r   r   Zsource_groupZgroup_ownerzCThe --%s option is not compatible with the --ip-permissions option )vars
ValueError)Zparsed_argsr   Zarg_dictkeymsgr   r   r   _check_args8   s   r   c                 K   s6   | j }|j  |j  d}|| |j  d S )NzZTo specify multiple rules in a single command use the <code>--ip-permissions</code> option)docstyleZnew_paragraphZ
start_noteZinclude_doc_stringZend_note)Zhelp_commandr   r   r   r   r   r   	_add_docsF   s   


r   z<building-argument-table.ec2.authorize-security-group-ingressz;building-argument-table.ec2.authorize-security-group-egressz9building-argument-table.ec2.revoke-security-group-ingressz8building-argument-table.ec2.revoke-security-group-egressz:operation-args-parsed.ec2.authorize-security-group-ingressz9operation-args-parsed.ec2.authorize-security-group-egressz7operation-args-parsed.ec2.revoke-security-group-ingressz6operation-args-parsed.ec2.revoke-security-group-egressz4doc-description.ec2.authorize-security-group-ingressz3doc-description.ec2.authorize-security-group-egressz1doc-description.ec2.revoke-security-group-ingressz4doc-description.ec2.revoke-security-groupdoc-ingressa+  <p>The IP protocol: <code>tcp</code> | <code>udp</code> | <code>icmp</code></p> <p>(VPC only) Use <code>all</code> to specify all protocols.</p><p>If this argument is provided without also providing the <code>port</code> argument, then it will be applied to all ports for the specified protocol.</p>a  <p>For TCP or UDP: The range of ports to allow.  A single integer or a range (<code>min-max</code>).</p><p>For ICMP: A single integer or a range (<code>type-code</code>) representing the ICMP type number and the ICMP code number respectively. A value of -1 indicates all ICMP codes for all ICMP types. A value of -1 just for <code>type</code> indicates all ICMP codes for the specified ICMP type.</p>z.<p>The IPv4 address range, in CIDR format.</p>z3<p>The name or ID of the source security group.</p>zp<p>The AWS account ID that owns the source security group. Cannot be used when specifying a CIDR IP address.</p>c                 C   s   t D ]
\}}| || qd S )N)EVENTSregister)Zevent_handlereventhandlerr   r   r   register_secgroupv   s   r"   c                 C   s   d| vr	i g| d< |dkr*d| d d vrg | d d d< | d d d  | d S |dv rMd| d d vr?i g| d d d< || d d d d |< d S || d d |< d S )NZIpPermissionsCidrIpIpRangesr   r   )GroupId	GroupNameUserIdZUserIdGroupPairs)append)paramsr   valuer   r   r   _build_ip_permissions{   s   
r+   c                   @      e Zd Zdd ZdS )r   c                 C   s|   |r<zt |}|dk s|dkr|dkrd}t|W n ty3   |dvr+d}t||dkr1d}Y nw t|d	| d S d S )
Nr      zJprotocol numbers must be in the range 0-255 or -1 to specify all protocols)ZtcpZudpZicmpallzSprotocol parameter should be one of: tcp|udp|icmp|all or any valid protocol number.r/   -1Z
IpProtocol)intr   r+   )self
parametersr*   Z	int_valuer   r   r   r   add_to_params   s"   zProtocolArgument.add_to_paramsN__name__
__module____qualname__r4   r   r   r   r   r          r   c                   @   r,   )r   c                 C   s   |rBz2|dks|dkrd}d}nd|v r| dd\}}n||}}t|dt| t|dt| W d S  tyA   d}t|w d S )Nr0   r/   -   ZFromPortZToPortzCport parameter should be of the form <from[-to]> (e.g. 22 or 22-25))splitr+   r1   r   )r2   r3   r*   ZfromstrZtostrr   r   r   r   r4      s   
zPortArgument.add_to_paramsNr5   r   r   r   r   r      r9   r   c                   @   r,   )r
   c                 C   s"   |rd|ig}t |d| d S d S )Nr#   r$   r+   r2   r3   r*   r   r   r   r4      s   
zCidrArgument.add_to_paramsNr5   r   r   r   r   r
      r9   r
   c                   @   r,   )r   c                 C   s2   |r| drt|d| d S t|d| d S d S )Nzsg-r%   r&   )
startswithr+   r>   r   r   r   r4      s
   
z!SourceGroupArgument.add_to_paramsNr5   r   r   r   r   r      r9   r   c                   @   r,   )r   c                 C   s   |r
t |d| d S d S )Nr'   r=   r>   r   r   r   r4      s   z GroupOwnerArgument.add_to_paramsNr5   r   r   r   r   r      r9   r   N)__doc__Zawscli.argumentsr   r   r   r   r   r   r	   r   r   r   r"   r+   r   r   r
   r   r   r   r   r   r   <module>   sH   
