o
    .&ßa!  ã                   @   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 CIDR range. 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)Ú	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_DOCSÚ_UNDOCUMENTEDÚPortArgumentÚ	PORT_DOCSÚCidrArgumentÚ	CIDR_DOCSÚSourceGroupArgumentÚSOURCEGROUP_DOCSÚGroupOwnerArgumentÚGROUPOWNER_DOCS)Úargument_tableÚkwargsÚarg© r   úL/usr/lib/python3/dist-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   Úsource_groupÚgroup_ownerzCThe --%s option is not compatible with the --ip-permissions option )ÚvarsÚ
ValueError)Úparsed_argsr   Ú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ÚstyleÚnew_paragraphÚ
start_noteÚinclude_doc_stringÚend_note)Ú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 CIDR IP range.</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)Ú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 )NÚIpPermissionsÚCidrIpÚIpRangesr   r   )ÚGroupIdÚ	GroupNameÚUserIdÚ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)ÚtcpÚudpÚicmpÚallzSprotocol parameter should be one of: tcp|udp|icmp|all or any valid protocol number.rA   ú-1Ú
IpProtocol)Úintr   r:   )ÚselfÚ
parametersr9   Ú	int_valuer    r   r   r   Úadd_to_paramsŒ   s"   €€úòzProtocolArgument.add_to_paramsN©Ú__name__Ú
__module__Ú__qualname__rH   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 )NrB   rA   ú-é   ÚFromPortÚToPortzCport parameter should be of the form <from[-to]> (e.g. 22 or 22-25))Úsplitr:   rD   r   )rE   rF   r9   ÚfromstrÚtostrr    r   r   r   rH       s   
ýñzPortArgument.add_to_paramsNrI   r   r   r   r   r
   ž   rM   r
   c                   @   r;   )r   c                 C   s"   |rd|ig}t |d|ƒ d S d S )Nr1   r2   ©r:   ©rE   rF   r9   r   r   r   rH   ¸   s   
þzCidrArgument.add_to_paramsNrI   r   r   r   r   r   ¶   rM   r   c                   @   r;   )r   c                 C   s2   |r|  d¡rt|d|ƒ d S t|d|ƒ d S d S )Nzsg-r3   r4   )Ú
startswithr:   rV   r   r   r   rH   À   s
   
üz!SourceGroupArgument.add_to_paramsNrI   r   r   r   r   r   ¾   rM   r   c                   @   r;   )r   c                 C   s   |r
t |d|ƒ d S d S )Nr5   rU   rV   r   r   r   rH   Ê   s   ÿz GroupOwnerArgument.add_to_paramsNrI   r   r   r   r   r   È   rM   r   N)Ú__doc__Úawscli.argumentsr   r   r!   r)   r*   r   r   r   r   r   r/   r:   r   r
   r   r   r   r   r   r   r   Ú<module>   sH   ÿÿÿñ
