
    <                     P    d 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 Z	d Z
y	)
z1Utilities for reCAPTCHA Firewall Policy Commands.    )absolute_import)division)unicode_literals)apis)
exceptionsc                     t        j                  dd      }| j                  d      }g }|D ]  }|j                  t	        ||              |S )Nrecaptchaenterprisev1,)r   GetMessagesModulesplitappendParseAction)actionsmessagesactions_listaction_messagesactions        Blib/googlecloudsdk/command_lib/recaptcha/firewall_policies_util.pyParseFirewallActionsr      sM    ##$94@(s#,/f;vx89 	    c                 h   |j                         }| j                  d      }|d   dv r6t        |      dkD  r(t        j                  ddj                  |d               |d   dk(  r$t        |      dk7  rt        j                  dd	      |d   d
k(  r$t        |      dk7  rt        j                  dd      |d   dk(  r|j                         |_        |S |d   dk(  r|j                         |_	        |S |d   dk(  r|j                         |_        |S |d   dk(  r+|j                         |_        |d   |j                  _        |S |d   d
k(  r@|j                         |_        |d   |d   c|j                   _        |j                   _        |S t        j                  ddj                  |             )a  Parses a string action into a FirewallAction and returns it.

  Actions are parsed to be one of AllowAction, BlockAction, RedirectAction,
  SubstituteAction or SetHeaderAction.

  Args:
    action: The action string to parse.
    messages: The message module in which FirewallAction is found in the cloud
      API.

  Returns:
    An instance of FirewallAction containing the action represented in the given
    string.

  Raises:
    BadArgumentException: A parsing error occurred.
  =r   >   allowblockredirect   z	--actionsz)Action {0} has > 0 arguments, expected 0.
substitute   zVSubstituteAction requires exactly one argument for path, in the form substitute=$PATH.
set_header   zlSetHeaderAction requires exactly two arguments for header key and value, in the form set_header=$KEY=$VALUE.r   r   r   z5Action string {0} cannot be parsed as FirewallAction.).GoogleCloudRecaptchaenterpriseV1FirewallActionr   lenr   BadArgumentExceptionformat9GoogleCloudRecaptchaenterpriseV1FirewallActionAllowActionr   9GoogleCloudRecaptchaenterpriseV1FirewallActionBlockActionr   <GoogleCloudRecaptchaenterpriseV1FirewallActionRedirectActionr   >GoogleCloudRecaptchaenterpriseV1FirewallActionSubstituteActionr   path=GoogleCloudRecaptchaenterpriseV1FirewallActionSetHeaderAction	setHeaderkeyvalue)r   r   parsed_actionaction_piecess       r   r   r   "   s   $ IIK-,,s#- 1  "=1A5

)
)3::=;KLN N 1%#m*<*A

)
)`  1%#m*<*A

)
)v  1 "\\ M* 
' Q7""\\ M$ 
! Q:%%bb M 
 Q<''ff  M$1!$4M! 
 Q<'&dd MAN	B! ?M!8!8!> 
 
)
)?FFvNP Pr   N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   r    r   r   <module>r6      s#    8 &  ' , .=r   