
    T                        d Z ddlmZ ddlmZ ddlmZ ddl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ej                  j"                  fdZej                  j"                  fdZej                  j"                  fdZej                  j"                  fdZ G d d      Zy)zIAPI wrapper for `gcloud network-security intercept-deployments` commands.    )absolute_import)division)unicode_literalsN)
list_pager)apis)waiter)base)	resourcesv1alpha1v1beta1v1networksecurityc                 L    t        |       }t        j                  t        |      S N)GetApiVersionr   GetMessagesModule	_API_NAMErelease_trackapi_versions     Hlib/googlecloudsdk/api_lib/network_security/intercept_deployments/api.pyr   r   &       m,+				;	77    c                 L    t        |       }t        j                  t        |      S r   )r   r   GetClientInstancer   r   s     r   r   r   +   r   r   c                 L    t        |       }t        j                  t        |      S r   )r   r   GetEffectiveApiEndpointr   r   s     r   r   r   0   s    m,+		%	%i	==r   c                 ,    t         j                  |       S r   )_API_VERSION_FOR_TRACKget)r   s    r   r   r   5   s    		#	#M	22r   c                   r    e Zd ZdZd Z	 	 ddZd Zd Zd Z	 ddZ	d	 Z
d
 ej                  d      fdZy)ClientzAPI client for Intercept Deployments commands.

  Attributes:
    messages: API messages class, The Network Security API messages.
  c                 4   t        |      | _        | j                  j                  | _        | j                  j                  | _        t        |      | _        t        j                         | _
        | j                  j                  t        t        |             y r   )r   _client'projects_locations_interceptDeployments_deployments_clientprojects_locations_operations_operations_clientr   messagesr
   Registry_resource_parserRegisterApiByNamer   r   )selfr   s     r   __init__zClient.__init__@   sr    $]3DL<< 	 #llHHD%m4DM%..0D++=/r   Nc                     | j                   j                  |||      }t        |d      r||_        | j                   j	                  |||      }| j
                  j                  |      S )a  Calls the CreateInterceptDeployment API.

    Args:
      parent: The parent of the deployment, e.g.
        "projects/myproj/locations/us-central1"
      forwarding_rule: The forwarding rule of the deployment, e.g.
        "projects/myproj/regions/us-central1/forwardingRules/my-rule"
      intercept_deployment_group: The deployment group of the deployment, e.g.
        "projects/myproj/locations/global/interceptDeploymentGroups/my-group"
      description: The description of the deployment.
      deployment_id: The ID of the deployment, e.g. "my-deployment".
      labels: A dictionary with the labels of the deployment.

    Returns:
      NetworksecurityProjectsLocationsInterceptDeploymentsCreateResponse
    )forwardingRuleinterceptDeploymentGrouplabelsdescription)interceptDeploymentinterceptDeploymentIdparent)r)   InterceptDeploymenthasattrr3   ANetworksecurityProjectsLocationsInterceptDeploymentsCreateRequestr&   Create)	r-   r6   forwarding_ruleintercept_deployment_groupr3   deployment_idr2   
deploymentcreate_requests	            r   CreateDeploymentzClient.CreateDeploymentL   sv    4 22&!; 3 J z=)*j]]dd&+ e N
 ##**>::r   c                 p    | j                   j                  |      }| j                  j                  |      S )z(Calls the DeleteInterceptDeployment API.name)r)   ANetworksecurityProjectsLocationsInterceptDeploymentsDeleteRequestr&   Delete)r-   rC   delete_requests      r   DeleteDeploymentzClient.DeleteDeploymentw   s8    ]]dd e N ##**>::r   c                 ,   | j                   j                  |j                  dd            }t        |d      r||_        | j                   j                  ||dj                  |j                                     }| j                  j                  |      S )a9  Calls the UpdateInterceptDeployment API.

    Args:
      name: The name of the deployment.
      description: The description of the deployment.
      update_fields: A dictionary of the fields to update mapped to their new
        values.

    Returns:
      Operation ref to track the long-running process.
    r2   N)r2   r3   ,)rC   r4   
updateMask)
r)   r7   r    r8   r3   @NetworksecurityProjectsLocationsInterceptDeploymentsPatchRequestjoinkeysr&   Patch)r-   rC   r3   update_fieldsr>   update_requests         r   UpdateDeploymentzClient.UpdateDeployment~   s    " 22  40 3 J
 z=)*j]]cc&88M..01 d N
 ##)).99r   c                 p    | j                   j                  |      }| j                  j                  |      S )z%Calls the GetInterceptDeployment API.rB   )r)   >NetworksecurityProjectsLocationsInterceptDeploymentsGetRequestr&   Get)r-   rC   get_requests      r   DescribeDeploymentzClient.DescribeDeployment   s8    --^^ _ K ##''44r   c                     | j                   j                  ||      }t        j                  | j                  |||dd      S )z'Calls the ListInterceptDeployments API.)r6   filterinterceptDeploymentspageSize)
batch_sizelimitfieldbatch_size_attribute)r)   ?NetworksecurityProjectsLocationsInterceptDeploymentsListRequestr   YieldFromListr&   )r-   r6   r\   	page_sizelist_filterlist_requests         r   ListDeploymentszClient.ListDeployments   sP     ==``k a L ##  $' r   c                 N    | j                   j                  |j                  d      S )zAConverts an Operation to a Resource to use with `waiter.WaitFor`.z-networksecurity.projects.locations.operations)r+   ParseRelativeNamerC   )r-   	operations     r   GetOperationRefzClient.GetOperationRef   s%      22G r   TiX  )secondsc           	          |r+t        j                  | j                  | j                        }nt        j                  | j                        }t        j
                  |||t        |j                               dz        S )a  Waits for an operation to complete.

    Polls the Network Security Operation service until the operation completes,
    fails, or max_wait_seconds elapses.

    Args:
      operation_ref: A Resource created by GetOperationRef describing the
        Operation.
      message: The message to display to the user while they wait.
      has_result: If True, the function will return the target of the operation
        (the Intercept Deployment) when it completes. If False, nothing will be
        returned (useful for Delete operations).
      max_wait: The time to wait for the operation to succeed before timing out.

    Returns:
      If has_result = True, an Intercept Deployment entity.
      Otherwise, None.
    i  )max_wait_ms)r   CloudOperationPollerr&   r(   CloudOperationPollerNoResourcesWaitForinttotal_seconds)r-   operation_refmessage
has_resultmax_waitpollers         r   WaitForOperationzClient.WaitForOperation   sp    2 **

"
"D$;$;f 55d6M6MNf>>..01D8	 r   )NN)NNN)__name__
__module____qualname____doc__r.   r@   rG   rQ   rV   rd   rh   datetime	timedeltarv    r   r   r"   r"   9   sT    
$ );V;:@5 =A  !x!!#.%r   r"   )rz   
__future__r   r   r   r{   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper	   googlecloudsdk.corer
   ReleaseTrackALPHABETAGAr   r   r   r   r   r   r"   r}   r   r   <module>r      s    P &  '  ' , . ( ) 	ZI$ 
 	 %)$5$5$:$: 8
 %)$5$5$:$: 8
 +/*;*;*@*@ >
 !% 1 1 6 6 3g gr   