
    %                        S r SSKJr  SSKJr  SSKJr  SSKrSSK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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  \R8                  " \R:                  R<                  \R:                  R>                  5       " S S\R@                  5      5       r!g)zCA command to sign and create attestations for Binary Authorization.    )absolute_import)division)unicode_literalsN)apis)	attestors)containeranalysis)containeranalysis_apis)kms)base)
exceptions)flags)util)
validation)log)
properties)	resources)
console_ioc                   .    \ rS rSrSr\S 5       rS rSrg)SignAndCreate(   a  Sign and create a Binary Authorization Attestation using a Cloud KMS key.

This command signs and creates a Binary Authorization attestation for your
project. The attestation is created for the specified artifact (e.g. a gcr.io
container URL), associate with the specified attestor, and stored under the
specified project.

## EXAMPLES

To sign and create an attestation in the project "my_proj" as the attestor
with resource path "projects/foo/attestors/bar" with the key
"projects/foo/locations/us-west1/keyRings/aring/cryptoKeys/akey/cryptoKeyVersions/1",
run:

    $ {command} \
        --project=my_proj \
        --artifact-url='gcr.io/example-project/example-image@sha256:abcd' \
        --attestor=projects/foo/attestors/bar \
        --keyversion-project=foo \
        --keyversion-location=us-west1 \
        --keyversion-keyring=aring \
        --keyversion-key=akey \
        --keyversion=1

To sign and create an attestation in the project "my_proj" in note "bar"
with the key "projects/foo/locations/us-west1/keyRings/aring/cryptoKeys/akey/cryptoKeyVersions/1",
run:

    $ {command} \
        --project=my_proj \
        --artifact-url='gcr.io/example-project/example-image@sha256:abcd' \
        --note=projects/my_proj/notes/bar \
        --keyversion-project=foo \
        --keyversion-location=us-west1 \
        --keyversion-keyring=aring \
        --keyversion-key=akey \
        --keyversion=1
c                 2   [         R                  " U5        UR                  5       nUR                  5       n[         R                  " U[         R
                  " SSSS[        R                  " S5      S95        [         R                  " U[         R                  " SSSS[        R                  " S5      S95        [         R                  " U[         R                  " SSS[        R                  " S	5      S
95        UR                  S[        [        R                  " S5      S9  UR                  SSS[        R                  " S5      S9  UR                  SSS[        R                  " S5      S9  UR                  S[        S[        R                  " S5      S9  g )NattestorFa                The Attestor whose Container Analysis Note will be used to host
              the created attestation. In order to successfully attach the
              attestation, the active gcloud account (core/account) must
              be able to read this attestor and must have the
              `containeranalysis.notes.attachOccurrence` permission for the
              Attestor's underlying Note resource (usually via the
              `containeranalysis.notes.attacher` role).)	base_namerequired
positionaluse_global_project_flag
group_help
keyversionTz{              The Cloud KMS (Key Management Service) CryptoKeyVersion to use to
              sign the attestation payload.noteag            The Container Analysis Note which will be used to host
          the created attestation. In order to successfully attach the
          attestation, the active gcloud account (core/account) must have the
          `containeranalysis.notes.attachOccurrence` permission for the
          Note (usually via the `containeranalysis.notes.attacher` role).)r   r   r   r   z--public-key-id-overridea            If provided, the ID of the public key that will be used to verify the
          Attestation instead of the default generated one. This ID should match
          the one found on the Attestor resource(s) which will use this
          Attestation.

          This parameter is only necessary if the `--public-key-id-override`
          flag was provided when this KMS key was added to the Attestor.)typehelpz
--validate
store_truezo          Whether to validate that the Attestation can be verified by the
          provided Attestor.
        )actiondefaultr!   z--pae-encode-payloadzD          Whether to pae-encode the payload before signing.
        z--dsse-typez0application/vnd.dev.cosign.simplesigning.v1+jsonz*          DSSE type used for pae encoding.)r    r$   r!   )r   AddArtifactUrlFlagadd_mutually_exclusive_group	add_groupAddConceptsGetAttestorPresentationSpectextwrapdedent#GetCryptoKeyVersionPresentationSpecGetNotePresentationSpecadd_argumentstr)clsparserexclusive_groupgroups       >lib/surface/container/binauthz/attestations/sign_and_create.pyArgsSignAndCreate.ArgsQ   s   	V$99;O%%'E	)) $) (; <	
$ 
11"$) (/ 0	
 
%% (M N	
	
 "__ L M   
__  	   __  	   B__ . /	      c           
          [         R                  R                  [        R                  R
                  R                  R                  SS9SS9n[        R                  " UR                  5      n[        R                  " U R                  5       5      nUR                  R                  R                  5       nUR                   =(       d    ["        R$                  " U5      nSU;   =(       a    UR&                  nS nUR(                  (       Ga  UR                  R(                  R                  5       n	[*        R,                  " U5      R                  U	5      n
[         R                  R/                  SU
R0                  R2                  0 5      nU(       a%  [4        R6                  " [8        R:                  U	US9nOU[=        S U
R0                  R>                   5       5      ;  a7  [@        RB                  " S	UU
RD                  5        [F        RH                  " S
SS9  OLURJ                  (       a%  UR                  RJ                  R                  5       nO[L        RN                  " S5      e[        RP                  " UR                  5      nUnURR                  (       a0  [        RT                  " URV                  URY                  S5      5      n["        R,                  " 5       nUR[                  UR]                  5       5      nUR_                  UR]                  5       ["        R`                  " URb                  5      U5      n[d        R,                  " [f        R                  " U R                  5       5      5      nURi                  UUUUURj                  UUS9$ )NT)r   zcloudresourcemanager.projects)
collectionvalidatez containeranalysis.projects.notes)attestor_refapi_versionc              3   8   #    U  H  oR                   v   M     g 7f)N)id).0pubkeys     r4   	<genexpr>$SignAndCreate.Run.<locals>.<genexpr>   s      
$L&II$Ls   z1No public key with ID [%s] found on attestor [%s]z%Create and upload Attestation anyway?)prompt_stringcancel_on_noz-One of --attestor or --note must be provided.zutf-8)project_refnote_refartifact_urlpublic_key_id	signature	plaintextvalidation_callback)6r   REGISTRYParser   VALUEScoreprojectGetbinauthz_command_utilRemoveArtifactUrlSchemerG   r   GetApiVersionReleaseTrackCONCEPTSr   public_key_id_overrider
   	GetKeyUrir:   r   r   ClientParseResourceIduserOwnedDrydockNotenoteReference	functoolspartialr   validate_attestationset
publicKeysr   warningnamer   PromptContinuer   r   InvalidArgumentErrorMakeSignaturePayloadpae_encode_payload	PaeEncode	dsse_typedecodeGetPublicKeyRelativeNameAsymmetricSignGetAlgorithmDigestType	algorithmr   ca_apisCreateAttestationOccurrencerI   )selfargsrE   artifact_url_without_schemer<   key_refkey_idvalidation_enabledrK   r;   r   rF   payloadpayload_for_signing
kms_clientpubkey_responsesign_responseclients                     r4   RunSignAndCreate.Run   s   $$**&&**D*92 + K #8"O"O# $$T%6%6%89Kmm&&,,.G((BCMM',BF $t+=}}}]]++113l!!+.22<@h##33
,

'
'
5
5
h 
'//++%#
  
$,$A$A$L$L
 
 
 ++Amm
 
#
#C 
##))+h ++
9  $889J9JKG!1;;
..'..1 J --g.B.B.DEO--""?#<#<=M %%d//12F --0))/ .  r7    N)	__name__
__module____qualname____firstlineno____doc__classmethodr5   r~   __static_attributes__r   r7   r4   r   r   (   s%    %N W WrUr7   r   )"r   
__future__r   r   r   r]   r*   )googlecloudsdk.api_lib.container.binauthzr   r   r   r	   rp   r
   googlecloudsdk.callioper   -googlecloudsdk.command_lib.container.binauthzr   r   r   rR   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   ReleaseTracksrU   BETAALPHACreateCommandr   r   r7   r4   <module>r      s    J &  '   : ? G W 9 ( D ? W D # * ) 2 D%%**D,=,=,C,CDWD&& W EWr7   