
                         n    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Z	dZ
d	Zd
ZeZ G d de      Zy)z7Helper functions for interacting with the binauthz API.    )absolute_import)division)unicode_literals)
list_pager)apiscontaineranalysisv1alpha1v1beta1v1c                   4    e Zd ZdZddZ	 	 	 	 	 ddZ	 ddZy)Clientz;A client to access containeranalysis for binauthz purposes.Nc                     |xs t         | _        t        j                  t        | j                        | _        t        j                  t        | j                        | _        y)zoCreates a ContainerAnalysisClient.

    Args:
      api_version: The containeranalysis API version to use.
    N)DEFAULT_VERSIONapi_versionr   GetClientInstanceAPI_NAMEclientGetMessagesModulemessages)selfr   s     Blib/googlecloudsdk/api_lib/container/binauthz/containeranalysis.py__init__zClient.__init__#   sE     #5oD((43C3CDDK**8T5E5EFDM    c              #      K   |dj                  |      nd}|B j                  j                  } j                  j	                  |j                         |      }nA j                  j                  } j                  j                  |j                         |      }t        j                  ||d|xs dd|	      }	 fd
}
|	D ]  } |
|      s|  yw)a`  Yields occurrences associated with a given attestor Note or Project.

    Args:
      note_ref: The Note reference that will be queried for attached
        occurrences. If None, then all occurrences from the given project will
        be listed. (containeranalysis.projects.notes Resource)
      project_ref: The Project referenece that will be queried for occurrences
        if note_ref is None.
      artifact_digest: Digest of the artifact for which to fetch occurrences. If
        None, then all occurrences attached to the AA Note are returned.
      page_size: The number of attestations to retrieve per request. (If None,
        use the default page size.)
      limit: The maxium number of attestations to retrieve. (If None,
        unlimited.)

    Yields:
      Occurrences bound to `note_ref` with matching `artifact_digest` (if
      passed).
    Nzhas_suffix(resourceUrl, "{}") )parentfilter)namer   occurrencesd   pageSize)servicerequestfield
batch_sizebatch_size_attributelimitc                 v    | j                   j                  j                  j                  j                  k7  ryy)NFT)kindr   
OccurrenceKindValueValuesEnumATTESTATION)
occurrencer   s    r   MatchesFilterz/Client.YieldAttestations.<locals>.MatchesFilterg   s1    
//]]%%99EEF r   )
formatr   projects_occurrencesr   /ContaineranalysisProjectsOccurrencesListRequestRelativeNameprojects_notes_occurrences4ContaineranalysisProjectsNotesOccurrencesListRequestr   YieldFromList)r   note_refproject_refartifact_digest	page_sizer'   artifact_filterr"   r#   occurrence_iterr.   r-   s   `           r   YieldAttestationszClient.YieldAttestations.   s     : & 	(..? 
 00gMM))+O N g 66g
--
L
L((*? M   !..#'O &
	z	" &s   CCCc                    | j                   t        k(  sJ | j                  j                  || j                  j	                  ||      g      }| j                  j                  | j                  j
                  j                  j                  ||j                         |      }	| j                  j                  |j                         |	      }
| ||	       | j                  j                  j                  |
      S )a  Creates an Occurrence referencing given URL and Note.

    This only supports the AttestationOccurrence-type Occurrence, currently only
    present in the v1 version of the API.

    Args:
      note_ref: The Note reference that the created Occurrence will be bound to.
        (containeranalysis.projects.notes Resource)
      project_ref: The project ref where the Occurrence will be created.
        (cloudresourcemanager.projects Resource)
      artifact_url: URL of artifact to which the signature is associated.
        (string)
      public_key_id: The URI of the public key that will be used to verify the
        signature. (string)
      signature: The content artifact's signature as generated by the specified
        key's signing operation. (string)
      plaintext: The content that was signed. (string)
      validation_callback: If provided, a function to validate the Occurrence
        prior to creation. (Callable[[Occurrence], None])

    Returns:
      Created Occurrence.
    )publicKeyId	signature)serializedPayload
signatures)r)   resourceUrinoteNameattestation)r   r-   )r   V1r   AttestationOccurrence	Signaturer*   r+   r,   r2   1ContaineranalysisProjectsOccurrencesCreateRequestr   r0   Create)r   r6   r7   artifact_urlpublic_key_idr?   	plaintextvalidation_callbackrD   r-   r#   s              r   CreateAttestationOccurrencez"Client.CreateAttestationOccurrences   s    B r!!!--55#MM##)Y $ 
 6 K ))]]%%99EE &&(	 * J mmMM'') N G
 &*%;;++227;;r   )N)NNNNN)__name__
__module____qualname____doc__r   r<   rN    r   r   r   r       s-    C	G CZ 8<r   r   N)rR   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   	V1_ALPHA1V1_BETA1rE   r   objectr   rS   r   r   <module>rZ      s@    > &  ' ' ,		K<V K<r   