
    B                        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 ddlmZ ddlmZ ddlmZ ej"                   ej$                  ej&                  j(                  ej&                  j*                  ej&                  j,                         G d dej.                                      Zy)z Add Attestor public key command.    )absolute_import)division)unicode_literalsN)apis)	attestors)kms)arg_parsers)base)
exceptions)flags)pkixc                   &    e Zd ZdZed        Zd Zy)Adda  Add a public key to an Attestor.

  ## EXAMPLES

  To add a new KMS public key to an existing Attestor `my_attestor`:

    $ {command} \
        --attestor=my_attestor \
        --keyversion-project=foo \
        --keyversion-location=us-west1 \
        --keyversion-keyring=aring \
        --keyversion-key=akey \
        --keyversion=1

  To add a new PGP public key to an existing Attestor `my_attestor`:

    $ {command} \
        --attestor=my_attestor \
        --pgp-public-key-file=my_key.pub
  c                    t        j                  |t        j                  ddd             |j                  dd       |j	                  d      }|j                  d	      }|j                  d
t        j                         d       |j                  d      }t        j                  |t        j                  ddddt        j                  d                   |j                  d      }|j                  ddt        j                         d       |j                  dt        j                         j                  dt        j                  d             |j                  dt        t        j                  d             y )NTFz5The attestor to which the public key should be added.)required
positional
group_helpz	--commentz&The comment describing the public key.)help)r   zPGP key definitionz--pgp-public-key-filezHThe path to the file containing the ASCII-armored PGP public key to add.)typer   zCloud KMS key definition
keyversionz              The Cloud KMS (Key Management Service) CryptoKeyVersion whose
              public key will be added to the attestor.)	base_namer   r   use_global_project_flagr   zPKIX key definitionz--pkix-public-key-filez;The path to the file containing the PKIX public key to add.)r   r   r   z--pkix-public-key-algorithmz            The signing algorithm of the associated key. This will be used to
            verify the signatures associated with this key.)choicesr   r   z--public-key-id-overridea=            If provided, the ID to replace the default API-generated one. All IDs
          must be valid URIs as defined by RFC 3986
          (https://tools.ietf.org/html/rfc3986).

          When creating Attestations to be verified by this key, one must always
          provide this custom ID as the public key ID.)r   AddConceptsGetAttestorPresentationSpecadd_argumentadd_mutually_exclusive_group	add_groupr	   FileContents#GetCryptoKeyVersionPresentationSpectextwrapdedentr   GetAlgorithmMapperr   str)clsparser	key_group	pgp_group	kms_group
pkix_groups         ;lib/surface/container/binauthz/attestors/public_keys/add.pyArgszAdd.Args:   s   	))G		
 B  D 33T3BI##)=#>I%%'/  0
 ##)C#DI	11"$) (; <	=
 $$*?$@J %%'J	  L
 %'')11__ ? @	  A "__ : ;  	<    c                    t        j                  | j                               }t        j                  |      }|j
                  j                  j                         }|j                  r!|j                  rt        j                  d      |j                  r|j
                  j                  j                         }t        j                         j                  |j                               }|j!                  ||j"                  |j%                  |j&                        |j                  xs t        j(                  |      |j*                        S |j,                  rbt/        j0                  |      }|j!                  ||j,                  |j3                  |j4                        |j                  |j*                        S |j7                  ||j                  |j*                        S )Nz@--public-key-id-override may not be used with old-style PGP keys)pkix_pubkey_contentpkix_sig_algorithmid_overridecomment)pgp_pubkey_contentr2   )r   GetApiVersionReleaseTrackr   ClientCONCEPTSattestorParsepgp_public_key_filepublic_key_id_overrider   InvalidArgumentErrorr   r   GetPublicKeyRelativeName
AddPkixKeypem ConvertFromKmsSignatureAlgorithm	algorithm	GetKeyUrir2   pkix_public_key_filer   r#   GetEnumForChoicepkix_public_key_algorithm	AddPgpKey)selfargsapi_versionattestors_clientattestor_refkey_resource
public_key
alg_mappers           r+   RunzAdd.Runt   s   $$T%6%6%89K ''4==))//1LD$?$?++
LN N ]]--335l::<,,\-F-F-HIj((
(nn-NN""$22 3}}\2,, )     
	"	"**;7j((
"77'88,,.11,, )     ''
!55,, (    r-   N)__name__
__module____qualname____doc__classmethodr,   rP    r-   r+   r   r   !   s!    * 7< 7<r# r-   r   )rT   
__future__r   r   r   r!   )googlecloudsdk.api_lib.container.binauthzr   r   r   googlecloudsdk.callioper	   r
   -googlecloudsdk.command_lib.container.binauthzr   r   r   DefaultUniverseOnlyReleaseTracksr5   GABETAALPHACommandr   rV   r-   r+   <module>ra      s    ' &  '  : ? 9 / ( D ? > D%%(($*;*;*@*@%%++-s $,, s - s r-   