
    $+                     ~    S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJr   " S
 S\5      rg)z+API helpers for interacting with attestors.    )absolute_import)division)unicode_literals)
list_pager)apis)util)
exceptions)mapsc                       \ rS rSrSrSS jrS rSS jrS rS r	S	 r
SS
 jrSS jr SS jrS r SS jrSS jrS rS rSrg)Client   z(A client for interacting with attestors.Nc                 |    [         R                  " U5      U l        [         R                  " U5      U l        Xl        g N)r   GetClientInstanceclientGetMessagesModulemessagesapi_version)selfr   s     :lib/googlecloudsdk/api_lib/container/binauthz/attestors.py__init__Client.__init__    s,    ((5DK**;7DM"    c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ )zGet the specified attestor.name)r   projects_attestorsGetr   .BinaryauthorizationProjectsAttestorsGetRequestRelativeName)r   attestor_refs     r   r   
Client.Get%   sC    ;;))--DD**, 	E 	
 r   c           	          [         R                  " U R                  R                  U R                  R                  UR                  5       S9U=(       d    SUSSS9$ )z7List the attestors associated with the current project.)parentd   	attestorspageSize)
batch_sizelimitfieldbatch_size_attribute)r   YieldFromListr   r   r   /BinaryauthorizationProjectsAttestorsListRequestr    )r   project_refr)   	page_sizes       r   ListClient.List,   sW    ##&&EE++- 	F 	0#') )r   c                     U R                   [        R                  :X  a  U R                  R                  $ U R                  R
                  $ r   )r   r   V1r   UserOwnedGrafeasNoteUserOwnedDrydockNoter   s    r   _GetNoteClassClient._GetNoteClass7   s:    477* MM.. 0MM..0r   c                 F    U R                   [        R                  :X  a  S$ S$ )NuserOwnedGrafeasNoteuserOwnedDrydockNote)r   r   r3   r6   s    r   GetNotePropertyNameClient.GetNotePropertyName<   s&    477* # $"$r   c                 n    U R                   [        R                  :X  a  UR                  $ UR                  $ )z7Return the Attestor's version-dependent Note attribute.)r   r   r3   r:   r;   )r   attestors     r   GetNoteAttrClient.GetNoteAttrA   s,    477"******r   c                    UR                  [        R                  5      nU R                  R                  R                  U R                  R                  U R                  R                  " SUR                  5       US.U R                  5       U R                  5       " UR                  5       S90D6UR                  5       UR                  5       S95      $ )z8Create an attestors associated with the current project.)r   description)noteReference)r?   
attestorIdr$    )Parentr   PROJECTS_COLLECTIONr   r   Creater   1BinaryauthorizationProjectsAttestorsCreateRequestAttestorr    r<   r7   Name)r   r!   note_refrC   r.   s        r   rI   Client.CreateH   s    %%d&>&>?K;;))00GG]]++ !..0' ++-t/A/A/C"*"7"7"90  $((*++- 	H 
	
 r   c                 d  ^ U R                  U5      n[        S U R                  U5      R                   5       5      nX%;   a/  [        R
                  " SR                  UR                  5      5      e[        S U R                  U5      R                   5       5      mU R                  U5      R                  R                  U R                  R                  UUS95        U R                  R                  R                  U5      n[        U4S jU R                  U5      R                   5       5      $ )aT  Add a PGP key to an attestor.

Args:
  attestor_ref: ResourceSpec, The attestor to be updated.
  pgp_pubkey_content: The contents of the PGP public key file.
  comment: The comment on the public key.

Returns:
  The added public key.

Raises:
  AlreadyExistsError: If a public key with the same key content was found on
      the attestor.
c              3   :   #    U  H  nUR                   v   M     g 7fr   )asciiArmoredPgpPublicKey.0
public_keys     r   	<genexpr>#Client.AddPgpKey.<locals>.<genexpr>i   s      A?J 	++?   z4Provided public key already present on attestor [{}]c              3   :   #    U  H  nUR                   v   M     g 7fr   idrR   s     r   rU   rV   q         A?J 	?rW   )rQ   commentc              3   L   >#    U  H  nUR                   T;  d  M  Uv   M     g 7fr   rY   rS   rT   existing_idss     r   rU   rV   |   &      .GJ==, 	
G   $	$)r   setr@   
publicKeysr	   AlreadyExistsErrorformatr   appendr   AttestorPublicKeyr   r   Updatenext)r   r!   pgp_pubkey_contentr\   r?   existing_pub_keysupdated_attestorr_   s          @r   	AddPgpKeyClient.AddPgpKeyX   s#    xx%H A**84??A A .))
@
G
Gmm   A**84??A AL 	X))00''%7 	( 	
 {{55<<XF .**+;<GG. . .r   c           
      H  ^ U R                  U5      n[        S U R                  U5      R                   5       5      mUb5  UT;   a/  [        R
                  " SR                  XFR                  5      5      eU R                  U5      R                  R                  U R                  R                  UU R                  R                  UUS9US95        U R                  R                  R                  U5      n[        U4S jU R                  U5      R                   5       5      $ )a  Add a key to an attestor.

Args:
  attestor_ref: ResourceSpec, The attestor to be updated.
  pkix_pubkey_content: The PEM-encoded PKIX public key.
  pkix_sig_algorithm: The PKIX public key signature algorithm.
  id_override: If provided, the key ID to use instead of the API-generated
      one.
  comment: The comment on the public key.

Returns:
  The added public key.

Raises:
  AlreadyExistsError: If a public key with the same key content was found on
      the attestor.
c              3   :   #    U  H  nUR                   v   M     g 7fr   rY   rR   s     r   rU   $Client.AddPkixKey.<locals>.<genexpr>   r[   rW   z8Public key with ID [{}] already present on attestor [{}])publicKeyPemsignatureAlgorithm)rZ   pkixPublicKeyr\   c              3   L   >#    U  H  nUR                   T;  d  M  Uv   M     g 7fr   rY   r^   s     r   rU   rq      r`   ra   )r   rb   r@   rc   r	   rd   re   r   rf   r   rg   PkixPublicKeyr   r   rh   ri   )	r   r!   pkix_pubkey_contentpkix_sig_algorithmid_overrider\   r?   rl   r_   s	           @r   
AddPkixKeyClient.AddPkixKey   s   & xx%H A**84??A AL ;,#>))
D
K
K==*+ + 	X))00''--550#5 6 7  	( 	 {{55<<XF .**+;<GG. . .r   c                    U R                  U5      n[        S U R                  U5      R                   5       5      nX$;  a/  [        R
                  " SR                  UR                  5      5      eU R                  U5      R                   Vs/ s H  nUR                  U:w  d  M  UPM     snU R                  U5      l        U R                  R                  R                  U5        gs  snf )zRemove a key on an attestor.

Args:
  attestor_ref: ResourceSpec, The attestor to be updated.
  pubkey_id: The ID of the key to remove.

Raises:
  NotFoundError: If an expected public key could not be located by ID.
c              3   :   #    U  H  nUR                   v   M     g 7fr   rY   rR   s     r   rU   #Client.RemoveKey.<locals>.<genexpr>   r[   rW   -No matching public key found on attestor [{}]N)r   rb   r@   rc   r	   NotFoundErrorre   r   rZ   r   r   rh   )r   r!   	pubkey_idr?   r_   rT   s         r   	RemoveKeyClient.RemoveKey   s     xx%H A**84??A AL $$$
9
@
@mm  **84??-'?J==I% 	?-'DX)
 	KK""))(3-'s   C)&C)c                   ^ U R                  U5      nU R                  U5      R                   Vs/ s H  nUR                  T:X  d  M  UPM     nnU(       d/  [        R
                  " SR                  UR                  5      5      e[        U5      S:  a/  [        R                  " SR                  UR                  5      5      eUS   nUb-  UR                  (       d  [        R                  " S5      eX8l
        Ub  XHl        U R                  R                  R                  U5      n	[!        U4S jU R                  U	5      R                   5       5      $ s  snf )a  Update a key on an attestor.

Args:
  attestor_ref: ResourceSpec, The attestor to be updated.
  pubkey_id: The ID of the key to update.
  pgp_pubkey_content: The contents of the public key file.
  comment: The comment on the public key.

Returns:
  The updated public key.

Raises:
  NotFoundError: If an expected public key could not be located by ID.
  InvalidStateError: If multiple public keys matched the provided ID.
  InvalidArgumentError: If a non-PGP key is updated with pgp_pubkey_content.
r      z4Multiple matching public keys found on attestor [{}]r   z7Cannot update a non-PGP PublicKey with a PGP public keyc              3   L   >#    U  H  nUR                   T:X  d  M  Uv   M     g 7fr   rY   )rS   rT   r   s     r   rU   #Client.UpdateKey.<locals>.<genexpr>   s&      'GJ==I% 	
Gra   )r   r@   rc   rZ   r	   r   re   r   lenInvalidStateErrorrQ   InvalidArgumentErrorr\   r   r   rh   ri   )
r   r!   r   rj   r\   r?   rT   existing_keysexisting_keyrl   s
     `       r   	UpdateKeyClient.UpdateKey   sG   $ xx%H **84??'?J==I% 	?  '
 $$
9
@
@mm  =A((
@
G
Gmm  !#L%22--EG 	G.@+${{55<<XF '**+;<GG' ' '3's   EEc                     U R                  U5      nUb  X#l        U R                  R                  R	                  U5      $ )zUpdate an attestor.

Args:
  attestor_ref: ResourceSpec, The attestor to be updated.
  description: string, If provided, the new attestor description.

Returns:
  The updated attestor.
)r   rC   r   r   rh   )r   r!   rC   r?   s       r   rh   Client.Update   s9     xx%H(;;))00::r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5        g)zDelete the specified attestor.r   N)r   1BinaryauthorizationProjectsAttestorsDeleteRequestr    r   r   Delete)r   r!   reqs      r   r   Client.Delete  sB    
--
I
I&&( J C 	KK""))#.r   c                 ~   U R                   R                  R                  n[        R                  nUR
                  R                  UR                  UR                  R                  UR                  UR                  R                  UR                  UR                  R                  UR                  UR                  R                  UR                  UR                  R                  UR                  UR                   R                  UR                   UR"                  R                  UR"                  UR$                  R                  UR&                  UR(                  R                  UR*                  0
n XAR                     $ ! [,         a0    [.        R0                  " SR3                  UR                  5      5      ef = f)zDConvert a KMS SignatureAlgorithm into a Binauthz SignatureAlgorithm.z3Unsupported PkixPublicKey signature algorithm: "{}")r   rv   !SignatureAlgorithmValueValuesEnumkms_mapsALGORITHM_ENUMRSA_SIGN_PSS_2048_SHA256r   RSA_PSS_2048_SHA256RSA_SIGN_PSS_3072_SHA256RSA_PSS_3072_SHA256RSA_SIGN_PSS_4096_SHA256RSA_PSS_4096_SHA256RSA_SIGN_PSS_4096_SHA512RSA_PSS_4096_SHA512RSA_SIGN_PKCS1_2048_SHA256RSA_SIGN_PKCS1_3072_SHA256RSA_SIGN_PKCS1_4096_SHA256RSA_SIGN_PKCS1_4096_SHA512EC_SIGN_P256_SHA256ECDSA_P256_SHA256EC_SIGN_P384_SHA384ECDSA_P384_SHA384KeyErrorr	   r   re   )r   kms_algorithmbinauthz_enumkms_enumalg_maps        r    ConvertFromKmsSignatureAlgorithm'Client.ConvertFromKmsSignatureAlgorithm  sf   MM//QQM&&H))..--))..--))..--))..--++0044++0044++0044++0044$$))++$$))++)G,#''(( #++
?
F
F  "# ##s   4F :F<)r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r   r0   r7   r<   r@   rI   rm   rz   r   r   rh   r   r   __static_attributes__rF   r   r   r   r      sZ    0#
	)0
$
+ '.T ,0*.X48 GK0'd;"/#r   r   N)r   
__future__r   r   r   apitools.base.pyr   )googlecloudsdk.api_lib.container.binauthzr   r   -googlecloudsdk.command_lib.container.binauthzr	   googlecloudsdk.command_lib.kmsr
   r   objectr   rF   r   r   <module>r      s0     2 &  ' ' : : D ;U#V U#r   