
    Q                     (   S r SSKrSSKrSSKrSSK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  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$r$Sr%/ SQr&Sr'Sr(Sr)Sr*Sr+Sr,Sr- " S S\R\                  5      r/S r0S r1S  r2S! r3  S8S" jr4S# r5S$ r6 S9S% jr7S& r8S' r9S( r:S) r;S* r<S+ r=S, r>S- r?S. r@S/ rAS0 rBS:S1 jrCS;S2 jrDS3 rES4 rFS5 rGS6 rHS7 rIg)<z0Utilities for the cloud deploy release commands.    N)
exceptions)snapshot)client_util)delivery_pipeline)storage_api)deploy_util)rollout_util)skaffold_util)staging_bucket_util)target_util)log)	resources)yaml)resource_transform)files)timesz9clouddeploy.projects.locations.deliveryPipelines.releases)z.zip.tgzz.gzzgs://{}/sourcezThe following resources are snapped in the release, but no longer exist:
{}

These resources were cached when the release was created, but their source may have been deleted.

zThe following target is not snapped in the release:
{}

You may have specified a target that wasn't cached when the release was created.

zThe following snapped releases resources differ from their current definition:
{}

The pipeline or targets were cached when the release was created, but the source has changed since then. You should review the differences before proceeding.
z$DATEz$TIMEskaffold.yamlc                   ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
ToolsM   dockerhelmkptkubectl	kustomizeskaffold N)__name__
__module____qualname____firstlineno__DOCKERHELMKPTKUBECTL	KUSTOMIZESKAFFOLD__static_attributes__r       5lib/googlecloudsdk/command_lib/deploy/release_util.pyr   r   M   s     &	$#')(r*   r   c                     [         R                   R                  5       nU R                  [        UR	                  S5      5      nUR                  [
        UR	                  S5      5      n[        U5        U$ )ap  Finds and replaces keywords in the release name.

  When adding to the list of keywords that can be expanded, care must be taken
  when two words share the same prefix ie. ($D and $DATE). In that case the
  longer keyword ($DATE) must be processed before the shorter one ($D).
Args:
  release_id: str, the release name template.

Returns:
  The formatted release name
z%Y%m%dz%H%M)datetimeutcnowreplace_DATE_PATTERNstrftime_TIME_PATTERN_CheckForRemainingDollars)
release_idtime_nowformatted_ids      r+   RenderPatternr7   V   s`     %%'(##M83D3DX3NO,%%mX5F5Fv5NO,L)	r*   c                     / n[        [        U 5      5       H2  nX   S:X  d  M  UR                  [        R                  " U5      5        M4     U(       a  [
        R                  " X5      eg)z8Find and notify user about dollar signs in release name.$N)rangelenappendsix	text_typer   InvalidReleaseNameError)r4   dollar_positionsis      r+   r3   r3   i   sY     Z!a}cmmA./ " 

,
,Z
JJ r*   c                     U (       d  U$ / n[        [        R                  " U 5      5       H#  u  pEUR                  UR	                  XES95        M%     X2l        U$ )a=  Set build_artifacts field of the release message.

Args:
  images: dict[str,dict], docker image name and tag dictionary.
  messages: Module containing the Cloud Deploy messages.
  release_config: apitools.base.protorpclite.messages.Message, Cloud Deploy
    release message.

Returns:
  Cloud Deploy release message.
)imagetag)sortedr=   	iteritemsr<   BuildArtifactbuildArtifacts)imagesmessagesrelease_configbuild_artifactskeyvalues         r+   SetBuildArtifactsrO   t   sT     
/3==01jc8111GH 2"1	r*   c           
      r   [         R                  " U 5       n [        R                  " XS9n0 nUS    H)  nUS   XER                  SUR                  S5      5      '   M+     UsSSS5        $ ! [        R                   a%  n[
        R                  " XR                  5      eSnAff = f! , (       d  f       g= f)zLoad images from a file containing JSON build data.

Args:
  path: str, build artifacts file path.

Returns:
  Docker image name and tag dictionary.
)	file_hintNbuildsrD   rC   	imageName)	r   
FileReaderr   loadErrorr   ParserErrorinner_errorget)pathfstructured_dataerI   builds         r+   LoadBuildArtifactFiler_      s     8		!4o F *;@<fYYw		+ 678 +   :: 8""4778 s-   B(A,5B(,B%  B  B%%B((
B6c                 l   U(       d  U(       d  [        X5        [        R                  " [        R                  " 5       5      nUR	                  5       nUUl        [        UU UUUUUUUUU5      n[        UUUUUU	U
U5      n[        UUX45      n[        U[        R                  R                  UU5      nU$ )zReturns a build config.)_VerifySkaffoldFileExistsr   GetMessagesModuleGetClientInstanceReleasedescription
_SetSource_SetVersion
_SetImages_SetDeployParametersr   ResourceTypeRELEASE)sourcegcs_source_staging_dirignore_filerI   rL   re   docker_versionhelm_versionkpt_versionkubectl_versionkustomize_versionskaffold_versionskaffold_filelocationpipeline_uuidfrom_k8s_manifestfrom_run_manifestpipeline_objdeploy_parameters	hide_logsrJ   rK   s                         r+   CreateReleaseConfigr}      s    6 0f4**;+H+H+JK(##%.*.. 	. hP.'&&	. 
r*   c                 d   [         R                  " X#S9n[        R                  " UR                  5      nU(       d@  [
        R                  R                  SR                  [        UR                  5      US95        UR                  U UUUS9nSR                  UR                  UR                  S9$ )a  Creates a local tarball and uploads it to GCS.

   After creating and uploading the tarball, this sets the Skaffold config URI
   in the release config.

Args:
  gcs_client: client for Google Cloud Storage API.
  gcs_source_staging: directory in Google cloud storage to use for staging
  source: the location of the source files
  ignore_file: the ignore file to use
  hide_logs: whether to show logs, defaults to False

Returns:
  the gcs uri where the tarball was uploaded.
)rn   zVCreating temporary archive of {num_files} file(s) totalling {size} before compression.)	num_filessize)rn   r|   gs://{bucket}/{object}bucketobject)r   Snapshotr   TransformSizeuncompressed_sizer   statusPrintformatr;   r   CopyArchiveToGCSr   name)
gcs_clientgcs_source_stagingrl   rn   r|   source_snapshotsize_strstaged_source_objs           r+   _CreateAndUploadTarballr      s    , %%fF/--o.O.OP(	JJ	006///0x 17 1
 &66	 7  
"	(	(%%.?.D.D 
) 
 r*   c           	         U(       + =(       a?    U(       + =(       a1    U(       + =(       a#    U(       + =(       a    U(       + =(       a    U(       + nU(       a  U $ US:H  =(       d    U=(       a    UR                  S5      S:H  n	U=(       d&    U=(       d    U=(       d    U=(       d    U=(       d    U	n
U
(       d  Xpl        U $ UR                  UUUUUUS9nXl        U $ )a  Set the version for the release config.

Sets the ToolVersions for the release config or the SkaffoldVersion for the
release config.

The ToolVersions are always used if any of the tool version fields are set:
  docker_version
  helm_version
  kpt_version
  kubectl_version
  kustomize_version
The ToolVersion of skaffold_version is only used if and only if the specified
version is a full semver or 'latest'.

The SkaffoldVersion on the release config is set if and only if
skaffold_version is the only version specified and it does not match the
full semver or 'latest'. This is purposefully done to allow uses to continue
referencing existing supported Cloud Deploy images: e.g. 2.14/2.16.

Args:
  release_config: a Release message
  messages: Module containing the Cloud Deploy messages.
  docker_version: the docker version to use, can be None.
  helm_version: the helm version to use, can be None.
  kpt_version: the kpt version to use, can be None.
  kubectl_version: the kubectl version to use, can be None.
  kustomize_version: the kustomize version to use, can be None.
  skaffold_version: the skaffold version to use, can be None.

Returns:
  Modified release_config
latest.   )r   r   r   r   r   r   )countskaffoldVersionToolVersionstoolVersions)rK   rJ   ro   rp   rq   rr   rs   rt   should_default should_skaffold_use_tool_versionuse_tool_versiontool_versionss               r+   rg   rg     s   X  
/ 
  
	
 
   &6%A &;+11#6!; #  *	*	* 
* 
	*
 
*  
%5"''
! ( - !.	r*   c           	         Sn[         R                  " U5      nUc  Sn[        R                  U5      nUR	                  S5      (       d  [
        R                  " SUS9e[        R                  " 5       nSnUR	                  S5      (       d$  [        R                  R                  U5      (       a!  [        R                  R                  U5      u  pSR                  [        R                  " [        R                  " 5       5      [         R"                  " 5       R$                  US9n[&        R(                  R+                  US	S
9n UR-                  UR.                  UUSSS9  UR4                  (       a  UR4                  S-   U-   n[&        R(                  R7                  S	UR.                  US9nSnSnUR	                  S5      (       aU  [&        R(                  R+                  US	S
9nUR9                  UU5      nSR                  UR.                  UR:                  S9nOU(       d  U(       a  Sn[=        UUUUUU
U	5      nO[        R                  R?                  U5      (       a  [A        UUUUU
5      nO[        R                  R                  U5      (       a  U
(       dB  [B        RD                  RG                  SR                  UUR.                  UR4                  S95        URI                  UU5      nSR                  UR.                  UR:                  S9n[K        XU5      n UU l&        U $ ! [        R0                   a'    [
        R2                  " SSR                  U5      5      ef = f)ae  Set the source for the release config.

Sets the source for the release config and creates a default Cloud Storage
bucket with location for staging if gcs-source-staging-dir is not specified.

Args:
  release_config: a Release message
  source: the location of the source files
  gcs_source_staging_dir: directory in google cloud storage to use for staging
  ignore_file: the ignore file to use
  location: the cloud region for the release
  pipeline_uuid: the unique id of the release's parent pipeline.
  kubernetes_manifest: path to kubernetes manifest (e.g. /home/user/k8.yaml).
    If provided, a Skaffold file will be generated and uploaded to GCS on
    behalf of the customer.
  cloud_run_manifest: path to Cloud Run manifest (e.g.
    /home/user/service.yaml).If provided, a Skaffold file will be generated
    and uploaded to GCS on behalf of the customer.
  skaffold_file: path of the skaffold file relative to the source directory
    that contains the Skaffold file.
  pipeline_obj: the pipeline_obj used for this release.
  hide_logs: whether to show logs, defaults to False

Returns:
  Modified release_config
FTgs://z--gcs-source-staging-dir)parameter_namemessager   z{stamp}-{uuid}{suffix})stampuuidsuffixzstorage.objects)
collection)rv   check_ownershipenable_uniform_level_accessenable_public_access_preventionzgcs-source-staging-dirzvA bucket with name {} already exists and is owned by another project. Specify a bucket using --gcs-source-staging-dir./)r   r   r    r   r   z9Uploading local file [{src}] to [gs://{bucket}/{object}].)srcr   r   )'r   GetDefaultStagingBucket_SOURCE_STAGING_TEMPLATEr   
startswithc_exceptionsInvalidArgumentExceptionr   StorageClientosrZ   isfilesplitextr   GetTimeStampFromDateTimeNowr   uuid4hexr   REGISTRYParseCreateBucketIfNotExistsr   BucketInWrongProjectErrorRequiredArgumentExceptionr   CreateRewriter   *_UploadTarballGeneratedSkaffoldAndManifestisdirr   r   r   r   CopyFileToGCS_SetSkaffoldConfigPathskaffoldConfigUri)rK   rl   rm   rn   rv   rw   kubernetes_manifestcloud_run_manifestru   rz   r|   default_gcs_sourcedefault_bucket_namer   r   _staged_objectr   gcs_uriskaffold_is_generated
gcs_sourcer   s                         r+   rf   rf   _  sV   N +CC #5<< 
 	*	*7	3	3

/
/1& 
 ((**&w277>>&#9#9  (IA +11**599;7::< 2 -
 %--33): 4 &&%%*$((, ' " ""*11C7-GM ))00"#** 1  'w##))&=N)OJ"**:7IJ&-- ''0A0F0F . G
 0":






g 
v		'




g 
		

GNN)00)00 O 	
 %226;MN(//"))2C2H2H 0 g *%:. &-."	G 
	.	.  
0
0 	$$*F+>$?	 s   L* *;M%c                     0 nU R                   R                   H<  nUR                   H)  nX1;  a  / X'   X   R                  UR                  5        M+     M>     U$ )zIGet mapping of profile to list of targets where the profile is activated.)serialPipelinestagesprofilesr<   targetId)rz   profile_to_targetsstageprofiles       r+   _GetProfileToTargetMappingr     sX    **11e>>		*&(#!((8 " 2
 
r*   c                 l    0 nU R                  5        H  u  p#[        U5      S:X  d  M  X!US   '   M     U$ )zKGet mapping of profile to target that is only activated in a single target.   r   )itemsr;   )r   target_to_unique_profiler   targetss       r+   !_GetUniqueProfilesToTargetMappingr     s>    ,224g
7|q-4wqz* 5 
"!r*   c                     [        U 5      n[        U5      n[        U5      [        U R                  R                  5      :w  a  [
        R                  " S5      eU$ )zGet one unique profile for every target if it exists.

Args:
  pipeline_obj: The Delivery Pipeline object.

Returns:
  A map of target_id to profile.

Raises:
 Error: If the pipeline targets don't each have a dedicated profile.
z=Target should use one profile not shared with another target.)r   r   r;   r   r   core_exceptionsrV   )rz   r   r   s      r+   _GetTargetAndUniqueProfilesr     s\     2,?>
 		!"c,*E*E*L*L&MM


G  
"!r*   c                    [         R                  " 5        nSnSn	U (       aF  U n[        R                  " U[        R
                  R                  U5      [        R                  5      n	OLU(       aE  Un[        R                  " U[        R
                  R                  U5      [        R                  5      n	[        R
                  R                  U5      (       d#  [        R                  " SR                  US95      e[        R                  " X5        [        R
                  R                  U[         5      n
[         R"                  " U
5       nUR%                  S5        [&        R(                  " XSS9  SSS5        [+        UUUUU5      n[,        R.                  R1                  SR                  US	95        UsSSS5        $ ! , (       d  f       NT= f! , (       d  f       g= f)
a  Generates a Skaffold file and uploads the file and k8 manifest to GCS.

Args:
  kubernetes_manifest: path to kubernetes manifest (e.g. /home/user/k8.yaml).
    If provided, a Skaffold file will be generated and uploaded to GCS on
    behalf of the customer.
  cloud_run_manifest: path to Cloud Run manifest (e.g.
    /home/user/service.yaml). If provided, a Skaffold file will be generated
    and uploaded to GCS on behalf of the customer.
  gcs_client: client for Google Cloud Storage API.
  gcs_source_staging: directory in google cloud storage to use for staging
  ignore_file: the ignore file to use
  hide_logs: whether to show logs, defaults to False
  pipeline_obj: the pipeline_obj used for this release.

Returns:
  the gcs uri where the tarball was uploaded.
r   z$could not find manifest file [{src}]r   z(# Auto-generated by Google Cloud Deploy
T)
round_tripNz4Generated Skaffold file can be found here: {gcs_uri})r   )r   TemporaryDirectoryr
   CreateSkaffoldFileForManifestr   rZ   basenameGKE_GENERATED_SKAFFOLD_TEMPLATE%CLOUD_RUN_GENERATED_SKAFFOLD_TEMPLATEexistsr   BadFileExceptionr   shutilcopyjoinGENERATED_SKAFFOLD
FileWriterwriter   dumpr   r   r   r   )r   r   r   r   rn   r|   rz   temp_dirmanifestskaffold_yamlskaffold_pathr[   r   s                r+   r   r   !  s|   6 !XHM$h#AA

''

8
$

7
7m
 
#h#AA

''

8
$

=
=m 77>>(##))
0
7
7H
7
E 
 KK#GGLL+=>M			-	(Agg9:
iiT2	 
)
 &G JJ>EE 	F 	

 Y "!6 
)	(7 "!s%   D5G'G 2AG 
G	
G
Gc                    U(       d  SnU R                  S5      (       a   [        R                  R                  S5        g[        R
                  R                  U 5      (       d#  [        R                  " SR                  U S95      e[        R
                  R                  U 5      (       a  [        X5        g[        X5        g)a  Checks that the specified source contains a skaffold file.

Args:
  source: the location of the source files
  skaffold_file: path of the skaffold file relative to the source directory

Raises:
  BadFileException: If the source directory or files can't be found.
r   r   zPSkipping skaffold file check. Reason: source is not a local archive or directoryzcould not find source [{src}]r   N)r   r   r   r   r   rZ   r   r   r   r   r   _VerifySkaffoldFileIsInArchive_VerifySkaffoldFileIsInFolder)rl   ru   s     r+   ra   ra   k  s     
#MwJJ	= 77>>&!!

'
''..6.:  
ww~~f"69!&8r*   c                    [         R                  R                  U 5      u  p#U[        ;  a,  [        R
                  " SSR                  [        5      -   5      e[        R                  " U 5      (       d  [        R
                  " S5      e[        R                  " U SS9 n UR                  U5         SSS5        g! [         a$    [        R
                  " SR                  US95      ef = f! , (       d  f       g= f)	a  Verifies the skaffold or deploy config file is in the archive.

Args:
  source: the location of the source archive.
  skaffold_file: path of the skaffold file in the source archive.

Raises:
  BadFileException: If the config file is not a readable compressed file or
  can't be found.
zlocal file [{src}] is none of , z?Specified source file is not a readable compressed file archivezr:gz)modezPCould not find skaffold file. File [{skaffold}] does not exist in source archiver   N)r   rZ   r   _ALLOWED_SOURCE_EXTr   r   r   tarfile
is_tarfileopen	getmemberKeyErrorr   )rl   ru   r   extarchives        r+   r   r     s     77F#&!##

'
'(4995H+II  
		F	#	#

'
'I  ||F(G& )(  ))..4fmf.L  )(s   C, B;;.C))C,,
C:c                     [         R                  R                  X5      n[         R                  R                  U5      (       d#  [        R
                  " SR                  US95      eg)zVerifies the skaffold or deploy config file is in the folder.

Args:
  source: the location of the source files
  skaffold_file: path of the skaffold file relative to the source directory

Raises:
  BadFileException: If the config file can't be found.
z>Could not find skaffold file. File [{skaffold}] does not existr   N)r   rZ   r   r   r   r   r   )rl   ru   path_to_skaffolds      r+   r   r     sZ     WW\\&8	(	)	)

'
'HOO% 	P 	
  
*r*   c                 >    U(       a  [        U5      n[        X U5      $ )z3Set the image substitutions for the release config.)r_   rO   )rJ   rK   rI   rL   s       r+   rh   rh     s    "?3F	6^	<<r*   c                 D    U(       a  Xl         U(       a  [        U l         U $ )zJSet the path for skaffold configuration file relative to source directory.)skaffoldConfigPathr   )rK   ru   is_generateds      r+   r   r     s    (5%(:N%	r*   c                     U(       am  [        XR                  5      R                  nU" 5       nUR                  5        H-  u  pgUR                  R                  UR                  XgS95        M/     XRl        U$ )z1Set the deploy parameters for the release config.)rM   rN   )getattrrN   DeployParametersValuer   additionalPropertiesr<   AdditionalPropertydeployParameters)rJ   resource_typerK   r{   dps_value_msg	dps_valuerM   rN   s           r+   ri   ri     sl     H&9&9:PPMI'--/
$$++

*
*s
*
@ 0
 '0#	r*   c                    / nU R                  5       nU R                  5       nU H  nUR                  n[        R                  " U5      n[        R
                  " Xt5      nUc  M@  [        R                  " UR                  5      n	U	R                  5       R                  5       n
X::X  d  M  UR                  U5        M     U$ )aA  Lists the targets where the given release is the latest.

Args:
  release_ref: protorpc.messages.Message, protorpc.messages.Message, release
    reference.
  targets: protorpc.messages.Message, protorpc.messages.Message, list of
    target objects.

Returns:
  A list of target references where this release is deployed.
)	RelativeNameParentr   r   TargetReferenceFromNameGetCurrentRolloutr	   RolloutReferenceFromNamer<   )release_refr   matching_targetsrelease_namepipeline_refobjtarget_name
target_refrollout_objrollout_refdeployed_release_names              r+   ListCurrentDeployedTargetsr$    s     ))+,##%,c((K44[AJ//
IK778H8HIK'..0==?,j)  
r*   c                    / n/ n/ nU(       a  U R                  5       n[        R                  " UUS   US   5      nUR                  5       UR                   Vs/ s H#  n[        R
                  " UR                  5      PM%     sn;  a  UR                  UR                  5       5        UR                   Hg  nUR                  n	 [        R                  " [        R                  " U	5      5      n
U
R                  UR                  :w  a  UR                  U	5        Mg  Mi     UR&                  R                  n [(        R*                  " 5       R-                  U5      nUR                  UR&                  R                  :w  a-  UR                  U R/                  5       R                  5       5        XTU4$ s  snf ! [        R                   ap  n[        R                  " SR!                  X5      5        [        R"                  R%                  SR!                  U	5      5        UR                  U	5         SnAGM  SnAff = f! [        R                   ay  n[        R                  " SR!                  XR0                  5      5        [        R"                  R%                  SR!                  U5      5        UR                  U5         SnAGNSnAff = f)a  Detects the differences between current delivery pipeline and target definitions, from those associated with the release being promoted.

Changes are determined through etag value differences.

This runs the following checks:
  - if the to_target is one of the snapped targets in the release.
  - if the snapped targets still exist.
  - if the snapped targets have been changed.
  - if the snapped pipeline still exists.
  - if the snapped pipeline has been changed.

Args:
  release_ref: protorpc.messages.Message, release resource object.
  release_obj: apitools.base.protorpclite.messages.Message, release message.
  to_target: str, the target to promote the release to. If specified, this
    verifies if the target has been snapped in the release.

Returns:
  the list of the resources that no longer exist.
  the list of the resources that have been changed.
  the list of the resources that aren't snapped in the release.

projectsIdlocationsIdzFailed to get target {}: {}zUnable to get target {}
NzFailed to get pipeline {}: {}z"Unable to get delivery pipeline {})AsDictr   TargetReferenceNametargetSnapshotsTargetIdr   r<   r  	GetTargetr  etagapitools_exceptions	HttpErrorr   debugr   r   r   deliveryPipelineSnapshotr   DeliveryPipelinesClientGetr  content)r  release_obj	to_targetresource_not_foundresource_changedresource_createdref_dictr   r  r  
target_objerrorr   rz   s                 r+   DiffSnappedPipeliner>    sB   . !!#H,,J 2=2M2M!2M3SXX&2M!  j5578((c((K
-((

-
-k
:j 
CHH	$, 
% ) 
	-	-	2	2$$$<<>BB4HLK@@EEEk002??AB 
-?	??A! (( -	ii-44[HI	jj299+FG,,- 
	&	& $II-44T==IJJJ9@@FGd##$s:   *F/AF46A5H; 4H8A$H33H8;KA.KKc                    [        XU5      u  pEnU(       a0  U[        R                  SR                  [	        U5      5      5      -  nU(       a0  U[
        R                  SR                  [	        U5      5      5      -  nU(       a0  U[        R                  SR                  [	        U5      5      5      -  n[        R                  R                  U5        g)a?  Prints differences between current and snapped delivery pipeline and target definitions.

Args:
  release_ref: protorpc.messages.Message, release resource object.
  release_obj: apitools.base.protorpclite.messages.Message, release message.
  target_id: str, target id, e.g. test/stage/prod.
  prompt: str, prompt text.

N)
r>  RESOURCE_CREATEDr   r   BulletedListRESOURCE_NOT_FOUNDRESOURCE_CHANGEDr   r   r   )r  r6  	target_idpromptr:  r9  r8  s          r+   	PrintDiffrG  @  s     <O	<8&8 
%%dii=M0N&OPPF
 ''		,123 F 
%%dii=M0N&OPPF**6r*   c                 N    [        [        U 5      5       H  nSX   -   X'   M     U $ )zConverts a list of string to a bulleted list.

The returned list looks like ['- string1','- string2'].

Args:
  str_list: [str], list to be converted.

Returns:
  list of the transformed strings.
z- )r:   r;   )str_listrA   s     r+   rB  rB  Y  s,     Xa$HK   
/r*   c                     SnU R                    H,  n[        R                  " UR                  5      U:X  d  M)  Un  U$    U$ )zGet the snapped target in a release by target ID.

Args:
  release_obj: apitools.base.protorpclite.messages.Message, release message
    object.
  target_id: str, target ID.

Returns:
  target message object.
N)r+  r   r,  r   )r6  rE  r<  sss       r+   GetSnappedTargetrL  j  sF     *''bBGG$	1j	 (
 
r*   c                 X   / n/ n[         R                  " [         R                  " 5       5      n[        R                  [        R
                  [        R                  [        R                  [        R                  [        R                  /nU Hq  n[        X5      nU(       d  M  UR                  R                  nXxR                  :X  a  UR                  U5        MO  XxR                  :X  a  UR                  U5        Mq  Ms     U(       aH  SR!                  U Vs/ s H  ofR"                  PM     sn5      n	[$        R&                  " SU SU	 S35      eU(       aO  SR!                  U Vs/ s H  ofR"                  PM     sn5      n	[(        R*                  R-                  SU	 S35        g[/        U 5      n
UR0                  R2                  nU
UR4                  :X  a  [$        R&                  " SU S35      eU
UR6                  :X  a   [(        R*                  R-                  S	5        ggs  snf s  snf )
ak  Checks the support state on a release.

If the release is in maintenance mode, a warning will be logged.
If the release is in expiration mode, an exception will be raised.

Args:
  release_obj: The release object to check.
  action: the action that is being performed that requires the check.

Raises: an core_exceptions.Error if any support state is unsupported
r   z
You can't z' because the versions used for tools: [zS] are no longer supported.
https://cloud.google.com/deploy/docs/select-tool-versionz'WARNING: The versions used for tools: [zp] are in maintenance mode and will be unsupported soon.
https://cloud.google.com/deploy/docs/select-tool-versionNz because the Skaffold version that was used to create the release is no longer supported.
https://cloud.google.com/deploy/docs/using-skaffold/select-skaffold#skaffold_version_deprecation_and_maintenance_policyzWARNING: This release's Skaffold version is in maintenance mode and will be unsupported soon.
 https://cloud.google.com/deploy/docs/using-skaffold/select-skaffold#skaffold_version_deprecation_and_maintenance_policy)r   rb   rc   r   r#   r$   r%   r&   r'   r(   _GetToolVersionSupportStateToolVersionSupportedCondition&ToolVersionSupportStateValueValuesEnum&TOOL_VERSION_SUPPORT_STATE_UNSUPPORTEDr<   +TOOL_VERSION_SUPPORT_STATE_MAINTENANCE_MODEr   rN   r   rV   r   r   r   _GetSkaffoldSupportStateSkaffoldSupportedCondition#SkaffoldSupportStateValueValuesEnum"SKAFFOLD_SUPPORT_STATE_UNSUPPORTED'SKAFFOLD_SUPPORT_STATE_MAINTENANCE_MODE)r6  actiontools_in_maintenancetools_unsupportedrJ   toolststatetool_version_enumjoinedskaffold_support_stateskaffold_support_state_enums               r+   CheckReleaseSupportStaterb    s    **;+H+H+JK(lljjiimmoonn% a'7E..UU  HHHq!	OO	O!!!$  YY):;):A):;<F



VHCF8 LC 	C 
 YY)=>)=A)=>?FJJ
1& :C 	C
  4K@))MM  	$	G	GH 


VH ? 	?  	$	L	LM JJ	?MC < ?s   H"&H'c                     U R                   (       a;  U R                   R                  (       a   U R                   R                  R                  $ g)zGets the Skaffold Support State from the release.

Args:
  release_obj: release message obj.

Returns:
  None or SkaffoldSupportStateValueValuesEnum
N)	conditionskaffoldSupportedConditionskaffoldSupportState)r6  s    r+   rS  rS    s6     {44OO  ;;PPP	r*   c                    U R                   (       d  gU[        R                  :X  a=  U R                   R                  (       a   U R                   R                  R                  $  gU[        R
                  :X  a=  U R                   R                  (       a   U R                   R                  R                  $  gU[        R                  :X  a=  U R                   R                  (       a   U R                   R                  R                  $  gU[        R                  :X  a=  U R                   R                  (       a   U R                   R                  R                  $  gU[        R                  :X  a=  U R                   R                  (       a   U R                   R                  R                  $  gU[        R                  :X  a;  U R                   R                  (       a   U R                   R                  R                  $ g)zGets the Tool Version Support State from the release for a particular tool.

Args:
  release_obj: release message obj.
  tool: Tools.Enum.

Returns:
  None or ToolVersionSupportStateValueValuesEnum
N)rd  r   r#   dockerVersionSupportedConditiontoolVersionSupportStater$   helmVersionSupportedConditionr%   kptVersionSupportedConditionr&    kubectlVersionSupportedConditionr'   "kustomizeVersionSupportedConditionr(   !skaffoldVersionSupportedCondition)r6  tools     r+   rN  rN    s    
			U\\<<



?
?
W
W =: 
3 uzz::



=
=
U
U ;0 
) uyy99



<
<
T
T :& 
 u}}==



@
@
X
X > 
 u??



B
B
Z
Z @ 
 u~~>>



A
A
Y
Y 
r*   )NF)F)N)Nr   )J__doc__r-   enumos.pathr   r   r   r   apitools.base.pyr   r/  !googlecloudsdk.api_lib.cloudbuildr   "googlecloudsdk.api_lib.clouddeployr   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   !googlecloudsdk.command_lib.deployr   r	   r
   r   r   googlecloudsdk.corer   r   r   r   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r   r=   _RELEASE_COLLECTIONr   r   rC  rA  rD  r0   r2   r   Enumr   r7   r3   rO   r_   r}   r   rg   rf   r   r   r   r   ra   r   r   rh   r   ri   r$  r>  rG  rB  rL  rb  rS  rN  r   r*   r+   <module>r~     sT   7       > 6 : @ 6 > 9 8 : ; A 9 = # ) $ ; * * 
 @  . + ! /    % DII &K,R )@F(VNx Rj""2GT96<&= :G@T2"*Od*r*   