
    -                        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	m
Z ddlmZ ej                  j                  d	ej                  j                   d
ej                  j"                  diZd Z G d dej(                        Zy)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                 >    t         |    }t        j                  |      S 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                   >    e Zd ZdZd Zd Zd Zd	dZd Z	 	 	 d
dZ	y)r   z=Client used by gcloud to communicate with the App Engine API.c                 D    t         j                  j                  | |       y r   )r	   AppengineApiClientBase__init__)selfclients     r   r   z#AppengineFirewallApiClient.__init__*   s    ((v6r   c                     | j                   j                  ||||      }| j                   j                  | j                         |      }| j                  j
                  j                  |      S )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*   z!AppengineFirewallApiClient.Create-   sn     ==%% 	 & "D mmJJ t K 5G ;;1188AAr   c                     | j                   j                  |j                               }| j                  j                  j                  |       y)zDeletes 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   r3   z!AppengineFirewallApiClient.DeleteF   sD     mmJJ""$ K &G 	KK**11':r   Nc                     | j                   j                  | j                         |      }t        j                  | j
                  j                  |dd      S )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   ListzAppengineFirewallApiClient.ListQ   sW     mmHH 2B I DG ##..'	) )r   c                     | j                   j                  |j                               }| j                  j                  j                  |      }|S )zGets a firewall rule for the given application.

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

    Returns:
      A FirewallRule object.
    r/   )r%   +AppengineAppsFirewallIngressRulesGetRequestr2   r   r)   Get)r   r4   r-   responses       r   rA   zAppengineFirewallApiClient.Getd   sK     mmGG""$ H &G {{5599'BHOr   c                    g }|r|j                  d       |r|j                  d       |r|j                  d       | j                  j                  ||||      }|st        j                         | j                  j                  |j                         |dj                  |            }| j                  j                  j                  |      S )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   ,)r0   r$   
updateMask)appendr%   r&   r   NoFieldsSpecifiedError-AppengineAppsFirewallIngressRulesPatchRequestr2   joinr   r)   Patch)	r   r4   r   r+   r    r!   mask_fieldsr,   r-   s	            r   Updatez!AppengineFirewallApiClient.Updatet   s    . K"''==%% 	 & "D ''))mmII""$88K( J *G
 ;;1177@@r   r   )NNN)
__name__
__module____qualname____doc__r   r*   r3   r>   rA   rL    r   r   r   r   '   s0    E7B2	;)&& .Ar   r   N)rP   
__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   rQ   r   r   <module>r\      sw    K &  ' ' + L 9 !!4$$i##X>
{A!<!< {Ar   