
    z                     f    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	  G d d	e
      Zy
)3API helpers for interacting with platform policies.    )absolute_import)division)unicode_literals)encoding)
list_pager)apisc                   D    e Zd ZdZd
dZd Zd Z	 	 ddZd Zd Z	dd	Z
y)Clientr   Nc                 l    t        j                  |      | _        t        j                  |      | _        y N)r	   GetClientInstanceclientGetMessagesModulemessages)selfapi_versions     @lib/googlecloudsdk/api_lib/container/binauthz/platform_policy.py__init__zClient.__init__   s&    ((5DK**;7DM    c                     | j                   j                  |      }| j                  j                  j	                  |      S )zDescribes a policy.

    Args:
      policy_ref: the resource name of the policy being described.

    Returns:
      The policy resource.
    name)r   6BinaryauthorizationProjectsPlatformsPoliciesGetRequestr   projects_platforms_policiesGet)r   
policy_refget_reqs      r   DescribezClient.Describe!   sA     	LL 	M 	
 
 ;;2266w??r   c                 Z    ||_         | j                  j                  j                  |      S )zUpdates a policy.

    Args:
      policy_ref: the resource name of the policy being updated.
      policy: the contents of the new policy.

    Returns:
      The updated policy resource.
    )r   r   r   ReplacePlatformPolicy)r   r   policys      r   UpdatezClient.Update1   s&     FK;;22HHPPr   c           	          t        j                  | j                  j                  | j                  j                  |      d|d|xs d      S )a|  Lists policies.

    Args:
      platform_ref: the resource name of the platform whose policies are being
        listed.
      page_size: The number of policies to retrieve in one request (when None,
        use the default size).
      limit: int, The maximum number of policies to yield (when None, unlimted).

    Returns:
      A list of policies for the given platform.
    )parentplatformPoliciespageSized   )fieldlimitbatch_size_attribute
batch_size)r   YieldFromListr   r   r   7BinaryauthorizationProjectsPlatformsPoliciesListRequest)r   platform_ref	page_sizer*   s       r   ListzClient.List>   sP    $ ##//MM 	N 	! '# r   c                     | j                   j                  |j                         j                         |j	                         |      }| j
                  j                  j                  |      S )zCreates a policy.

    Args:
      policy_resource_name: Resource object representing the resource name of
        the policy to create.
      policy: The policy to create.

    Returns:
      The policy resource.
    )r%   policyIdplatformPolicy)r   9BinaryauthorizationProjectsPlatformsPoliciesCreateRequestParentRelativeNameNamer   r   Create)r   policy_resource_namer"   requests       r   r9   zClient.CreateZ   sb     	OO'..0==?)..0! 	P 	# 
 ;;2299'BBr   c                     | j                   j                  |      }| j                  j                  j	                  |      S )zDeletes a policy.

    Args:
      policy_ref: the resource name of the policy being deleted.

    Returns:
      The resource name of the deleted policy.
    r   )r   9BinaryauthorizationProjectsPlatformsPoliciesDeleteRequestr   r   Delete)r   r   r;   s      r   r>   zClient.Deletel   sA     	OO 	P 	
 
 ;;2299'BBr   c                     t        j                  d|i|d| j                  j                        }|r9| j                  j                  j
                  j                  |j                  _        | j                  j                  j                  |      S )aI  Evaluate a policy against a Kubernetes resource.

    Args:
      policy_ref: the resource name of the policy.
      resource: the Kubernetes resource in JSON or YAML form.
      generate_deploy_attestations: whether to sign results or not.

    Returns:
      The result of the evaluation in EvaluateGkePolicyResponse form.
    resource)evaluateGkePolicyRequestr   )r   DictToMessager   >BinaryauthorizationProjectsPlatformsGkePoliciesEvaluateRequestEvaluateGkePolicyRequestAttestationModeValueValuesEnumGENERATE_DEPLOYrA   attestationModer   projects_platforms_gke_policiesEvaluate)r   r   r@   generate_deploy_attestationsr;   s        r   rI   zClient.Evaluate|   s     $$ H) 		
 	TTG $
--
0
0
O
O
_
_ &&6 ;;66??HHr   r   )r(   N)F)__name__
__module____qualname____doc__r   r   r#   r1   r9   r>   rI    r   r   r   r      s5    ;8@ Q  	8C$C Ir   r   N)rN   
__future__r   r   r   apitools.base.pyr   r   )googlecloudsdk.api_lib.container.binauthzr	   objectr   rO   r   r   <module>rT      s,    : &  ' % ' :{IV {Ir   