
    -                        S 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  \R                  R                  S	\R                  R                   S
\R                  R"                  S0rS r " S S\R(                  5      rg)zDFunctions for creating a client to talk to the App Engine Admin API.    )absolute_import)division)unicode_literals)
list_pager)util)appengine_api_client_base)basev1v1alphav1betac                 >    [         U    n[        R                  U5      $ N)VERSION_MAPAppengineFirewallApiClientGetApiClient)release_trackapi_versions     Clib/googlecloudsdk/api_lib/app/api/appengine_firewall_api_client.pyGetApiClientForTrackr   "   s    M*+	#	0	0	==    c                   J    \ rS rSrSrS rS rS rSS jrS r	   SS	 jr
S
rg)r   '   z=Client used by gcloud to communicate with the App Engine API.c                 B    [         R                  R                  X5        g r   )r	   AppengineApiClientBase__init__)selfclients     r   r   #AppengineFirewallApiClient.__init__*   s    ((6r   c                     U R                   R                  UUUUS9nU R                   R                  U R                  5       US9nU R                  R
                  R                  U5      $ )a  Creates a firewall rule for the given application.

Args:
  priority: int, the priority of the rule between [1, 2^31-1].
            The default rule may not be created, only updated.
  source_range: str, the ip address or range to take action on.
  action: firewall_rules_util.Action, optional action to take on matched
    addresses.
  description: str, an optional string description of the rule.

Returns:
  The new firewall rule.
priorityactiondescriptionsourceRange)parentfirewallRule)messagesFirewallRule.AppengineAppsFirewallIngressRulesCreateRequest
_FormatAppr   apps_firewall_ingressRulesCreate)r   r!   source_ranger"   r#   rulerequests          r   r,   !AppengineFirewallApiClient.Create-   sn     ==%% 	 & "D mmJJ t K 5G ;;1188AAr   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5        g)zsDeletes a firewall rule for the given application.

Args:
  resource: str, the resource path to the firewall rule.
nameN)r'   .AppengineAppsFirewallIngressRulesDeleteRequestRelativeNamer   r+   Delete)r   resourcer/   s      r   r6   !AppengineFirewallApiClient.DeleteF   sD     mmJJ""$ K &G 	KK**11':r   Nc                     U R                   R                  U R                  5       US9n[        R                  " U R
                  R                  USSS9$ )zLists all ingress firewall rules for the given application.

Args:
  matching_address: str, an optional ip address to filter matching rules.

Returns:
  A list of FirewallRule objects.
)r%   matchingAddressingressRulespageSize)fieldbatch_size_attribute)r'   ,AppengineAppsFirewallIngressRulesListRequestr*   r   YieldFromListr   r+   )r   matching_addressr/   s      r   ListAppengineFirewallApiClient.ListQ   sW     mmHH 2B I DG ##..'	) )r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      nU$ )zGets a firewall rule for the given application.

Args:
  resource: str, the resource path to the firewall rule.

Returns:
  A FirewallRule object.
r2   )r'   +AppengineAppsFirewallIngressRulesGetRequestr5   r   r+   Get)r   r7   r/   responses       r   rF   AppengineFirewallApiClient.Getd   sK     mmGG""$ H &G {{5599'BHOr   c                    / nU(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U R                  R                  UUUUS9nU(       d  [        R                  " 5       eU R                  R                  UR                  5       USR                  U5      S9nU R                  R                  R                  U5      $ )a  Updates a firewall rule for the given application.

Args:
  resource: str, the resource path to the firewall rule.
  priority: int, the priority of the rule.
  source_range: str, optional ip address or range to take action on.
  action: firewall_rules_util.Action, optional action to take on matched
    addresses.
  description: str, optional string description of the rule.

Returns:
  The updated firewall rule.

Raises:
  NoFieldsSpecifiedError: when no fields have been specified for the update.
r"   r$   r#   r    ,)r3   r&   
updateMask)appendr'   r(   r   NoFieldsSpecifiedError-AppengineAppsFirewallIngressRulesPatchRequestr5   joinr   r+   Patch)	r   r7   r!   r-   r"   r#   mask_fieldsr.   r/   s	            r   Update!AppengineFirewallApiClient.Updatet   s    . K"''==%% 	 & "D ''))mmII""$88K( J *G
 ;;1177@@r    r   )NNN)__name__
__module____qualname____firstlineno____doc__r   r,   r6   rB   rF   rR   __static_attributes__rT   r   r   r   r   '   s0    E7B2	;)&& .Ar   r   N)rY   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.app.apir   r	   googlecloudsdk.calliopecalliope_baseReleaseTrackGAALPHABETAr   r   r   r   rT   r   r   <module>re      sw    K &  ' ' + L 9 !!4$$i##X>
{A!<!< {Ar   