
    %                     Z    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  G d de	      Z
y	)
z5API utilities for gcloud compute ssl-policy commands.    )absolute_import)division)unicode_literals)poller)waiterc                   n    e Zd ZdZd Zed        Zed        Zd Z	 	 	 ddZ	d Z
d	 Zd
 Zd Zd Zd Zy)SslPolicyHelperz1Helper for SSL policy service in the Compute API.c                 H    |j                   | _        |j                  | _        y)zInitializes the helper for SSL policy operations.

    Args:
      holder: Object representing the Compute API holder instance.
    N)client_compute_client	resources
_resources)selfholders     Elib/googlecloudsdk/api_lib/compute/ssl_policies/ssl_policies_utils.py__init__zSslPolicyHelper.__init__   s     "==D&&DO    c                 .    | j                   j                  S N)r   apitools_clientr   s    r   _clientzSslPolicyHelper._client%   s    ///r   c                 .    | j                   j                  S r   )r   messagesr   s    r   	_messageszSslPolicyHelper._messages)   s    (((r   c                     | j                   j                  ||| j                   j                  j                  |      | j                   j                  j                  |      |      S )a  Returns the SslPolicy message for an insert request.

    Args:
      name: String representing the name of the SSL policy resource.
      description: String representing the description for the SSL policy
        resource.
      profile: String representing the SSL policy profile. Can be one of
        'COMPATIBLE', 'MODERN', 'RESTRICTED' or 'CUSTOM'.
      min_tls_version: String representing the minimum TLS version of the SSL
        policy. Can be one of 'TLS_1_0', 'TLS_1_1', 'TLS_1_2'.
      custom_features: The list of strings representing the custom features to
        use.

    Returns:
      The SslPolicy message object that can be used in an insert request.
    )namedescriptionprofileminTlsVersioncustomFeatures)r   	SslPolicyProfileValueValuesEnumMinTlsVersionValueValuesEnum)r   r   r   r   min_tls_versioncustom_featuress         r   GetSslPolicyForInsertz%SslPolicyHelper.GetSslPolicyForInsert-   s\    $ >>##((??Hnn..KK& $ ( (r   Nc                     | j                   }|j                  |      }|r |j                  j                  |      |_        |r |j                  j	                  |      |_        |||_        |S )a  Returns the SslPolicy message for a patch request.

    Args:
      fingerprint: String representing the existing fingerprint of the SSL
        policy resource.
      profile: String representing the SSL policy profile. Can be one of
        'COMPATIBLE', 'MODERN', 'RESTRICTED' or 'CUSTOM'.
      min_tls_version: String representing the minimum TLS version of the SSL
        policy. Can be one of 'TLS_1_0', 'TLS_1_1', 'TLS_1_2'.
      custom_features: The list of strings representing the custom features to
        use.
    )fingerprint)r   r"   r#   r   r$   r    r!   )r   r)   r   r%   r&   r   
ssl_policys          r   GetSslPolicyForPatchz$SslPolicyHelper.GetSslPolicyForPatchG   so    " ~~H###<J#--DDWMj



9
9/
J ""1jr   c                 ,   |j                         dk(  rAt        j                  | j                  j                  |      }t        j                  |||      S t        j                  | j                  j                  |      }t        j                  |||      S )a  Waits for the specified operation to complete and returns the target.

    Args:
      ssl_policy_ref: The SSL policy reference object.
      operation_ref: The operation reference object to wait for.
      wait_message: String representing the wait message to display while the
        operation is in progress.

    Returns:
      The resulting resource object after the operation completes.
    compute.regionSslPolicies)
Collectionr   Pollerr   regionSslPoliciesr   WaitForsslPolicies)r   ssl_policy_refoperation_refwait_messageoperation_pollers        r   WaitForOperationz SslPolicyHelper.WaitForOperationc   sw       "&AAt||'E'E'57^^,m\JJ}}T\\%=%=~N>>*M<HHr   c                 
   |j                         dk(  r~| j                  j                  |j                  |j                  |      }| j
                  j                  j                  |      }| j                  j                  |j                  d      S | j                  j                  |j                  |      }| j
                  j                  j                  |      }| j                  j                  |j                  d      S )a  Sends an Insert request for an SSL policy and returns the operation.

    Args:
      ref: The SSL policy reference object.
      ssl_policy: The SSL policy message object to use in the insert request.

    Returns:
      The operation reference object for the insert request.
    r-   projectregion	sslPolicycompute.regionOperations
collectionr:   r<   compute.globalOperations)r.   r   %ComputeRegionSslPoliciesInsertRequestr:   r;   r   r0   Insertr   ParseselfLinkComputeSslPoliciesInsertRequestr2   )r   refr*   request	operations        r   CreatezSslPolicyHelper.Createw   s     ~~66DD++cjjJ E Hg,,0077@i__""


)C # E E nn<<z = 3G((//8I??  'A ! C Cr   c                    |j                         dk(  re| j                  j                  |j                  |j                  |j                               }| j                  j                  j                  |      S | j                  j                  |j                  |j                               }| j                  j                  j                  |      S )zSends a Get request for an SSL policy and returns the resource.

    Args:
      ref: The SSL policy reference object.

    Returns:
      The SSL policy resource object.
    r-   r9   r@   )r.   r   "ComputeRegionSslPoliciesGetRequestr:   r;   Namer   r0   GetComputeSslPoliciesGetRequestr2   )r   rG   rH   s      r   DescribezSslPolicyHelper.Describe   s     ~~66AA++cjjCHHJ B Hg\\++//88nn99sxxz : 3G<<##''00r   c                 0   g }|r|j                  d       |j                         dk(  r| j                  j                  |j                  |j
                  |j                         |      }| j                  j                  |      5  | j                  j                  j                  |      }ddd       | j                  j                  j                  d      S | j                  j                  |j                  |j                         |      }| j                  j                  |      5  | j                  j                  j                  |      }ddd       | j                  j                  j                  d      S # 1 sw Y   xY w# 1 sw Y   <xY w)	a   Sends a Patch request for an SSL policy and returns the operation.

    Args:
      ref: The SSL policy reference object.
      ssl_policy: The SSL policy message object to use in the patch request.
      clear_custom_features: If True, customFeatures field is explicitly cleared
        by including it in the request even if empty. Otherwise it is included
        only if the SSL policy message has non-empty customFeatures field.

    Returns:
      The operation reference object for the patch request.
    r!   r-   )r:   r;   r<   sslPolicyResourceNr=   r>   )r:   r<   rR   rA   )appendr.   r   $ComputeRegionSslPoliciesPatchRequestr:   r;   rM   r   IncludeFieldsr0   Patchr   rD   rE   ComputeSslPoliciesPatchRequestr2   )r   rG   r*   clear_custom_featurescleared_fieldsrH   rI   s          r   rV   zSslPolicyHelper.Patch   sX    N ,-
~~66CC++HHJ&	 D (g
 <<%%n5LL2288A	 6__""


)C # E E nn;;sxxzZ < QG		#	#N	3,,**009i 
4??  'A ! C C 65 
4	3s   &F +&F F	Fc                 B   |j                         dk(  r| j                  j                  |j                  |j                  |j                               }| j                  j                  j                  |      }| j                  j                  |j                  d      S | j                  j                  |j                  |j                               }| j                  j                  j                  |      }| j                  j                  |j                  d      S )zSends a Delete request for an SSL policy and returns the operation.

    Args:
      ref: The SSL policy reference object.

    Returns:
      The operation reference object for the delete request.
    r-   r9   r=   r>   r@   rA   )r.   r   %ComputeRegionSslPoliciesDeleteRequestr:   r;   rM   r   r0   Deleter   rD   rE   ComputeSslPoliciesDeleteRequestr2   )r   rG   rH   rI   s       r   r\   zSslPolicyHelper.Delete   s     ~~66DD++cjjCHHJ E Hg,,0077@i__""


)C # E E nn<<sxxz = 3G((//8I??  'A ! C Cr   c                 4   |rL| j                   j                  ||      }| j                  j                  j	                  |      j
                  S | j                   j                  |      }| j                  j                  j	                  |      j
                  S )a.  Sends a ListAvailableFeatures request and returns the features.

    Args:
      project: String representing the project to use for the request.
      region: The region to use. If not set, the global scope is used.

    Returns:
      List of strings representing the list of available features.
    )r:   r;   )r:   )r   4ComputeRegionSslPoliciesListAvailableFeaturesRequestr   r0   ListAvailableFeaturesfeatures.ComputeSslPoliciesListAvailableFeaturesRequestr2   )r   r:   r;   rH   s       r   r`   z%SslPolicyHelper.ListAvailableFeatures   s     SS& T *g\\++AA
8 nnKK L G<<##99'BKKKr   )NNN)__name__
__module____qualname____doc__r   propertyr   r   r'   r+   r7   rJ   rP   rV   r\   r`    r   r   r	   r	      sk    9' 0 0 ) )(8 $(+/+/	8I(C.1$$CLC,Lr   r	   N)rf   
__future__r   r   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   objectr	   rh   r   r   <module>rm      s)    < &  ' < .ULf ULr   