
    U                         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dl	Z	dZ
d	Zej                  ad
 Zd Zd Zd Zd Zy)z*Utilities for `gcloud app firewall-rules`.    )absolute_import)division)unicode_literals)
exceptions)	resourcesNizS
  table(
    priority:sort=1,
    action,
    source_range,
    description
  )
  c                     	 t         j                  j                  d|        t
        S # t         j                  $ r< t         j                  j	                         at
        j                  d|        Y t
        S w xY w)N	appengine)r   REGISTRYGetCollectionInfoInvalidCollectionExceptionCloneregistryRegisterApiByName)versions    9lib/googlecloudsdk/command_lib/app/firewall_rules_util.pyGetRegistryr   (   sd    5((g> 
/ 
	-	- 5!!'')H{G4	/5s    ( AA76A7c                     t        | j                               j                  t        j                  t        |            d| j                  id      }|S )zCreates a resource path given a firewall rule priority.

  Args:
    client: AppengineFirewallApiClient, the API client for this release track.
    priority: str, the priority of the rule.

  Returns:
    The resource for the rule.

  appsIdz$appengine.apps.firewall.ingressRules)params
collection)r   
ApiVersionParsesix	text_typeParsePriorityproject)clientpriorityress      r   ParseFirewallRuler    2   sN     	F%%'(..	mmM(+,'7 	/ 	9# 
*    c                     | dk(  rt         } 	 t        |       }|dk  s	|t         kD  r)t        j                  ddj	                  t                     |S # t
        $ r t        j                  dd      w xY w)z"Converts a priority to an integer.defaultr   r   z-Priority must be between 1 and {0} inclusive.z1Priority should be an integer value or `default`.)DEFAULT_RULE_PRIORITYintr   InvalidArgumentExceptionformat
ValueError)r   priority_ints     r   r   r   D   s    $H	Ix=LqL+@@//
ELL#%& & 	 I

-
-GI IIs   AA  A1c                 Z    |sy| j                   j                  |j                               S )aQ  Converts an action string to the corresponding enum value.

  Options are: 'allow' or 'deny', otherwise None will be returned.

  Args:
    messages: apitools.base.protorpclite.messages, the proto messages class for
      this API version for firewall.
    action: str, the action as a string
  Returns:
    ActionValueValuesEnum type
  N)FirewallRuleActionValueValuesEnumupper)messagesactions     r   ParseActionr0   U   s'     
				4	4V\\^	DDr!   c                  2    t        j                  g dd      )N)z--actionz--source-rangez--descriptionzCPlease specify at least one attribute to the firewall-rules update.)r   MinimumArgumentException r!   r   RaiseMinArgumentr4   f   s    ++ -J	L Lr!   )__doc__
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.corer   r   r$   LIST_FORMATr
   r   r   r    r   r0   r4   r3   r!   r   <module>r:      sT    1 &  ' . ) 
 "  $I"E"Lr!   