
                             d Z ddlZddlZddlZddlZddl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	 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 ddlm Z  ddl!m"Z" ddl!m#Z# ddl$Z$dZ%g dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ- G d dej\                        Z/d Z0d Z1d  Z2d! Z3	 	 d8d"Z4d# Z5d$ Z6	 d9d%Z7d& Z8d' Z9d( Z:d) Z;d* Z<d+ Z=d, Z>d- Z?d. Z@d/ ZAd0 ZBd:d1ZCd;d2ZDd3 ZEd4 ZFd5 ZGd6 ZHd7 ZIy)<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                   $    e Zd ZdZdZdZdZdZdZy)Toolsdockerhelmkptkubectl	kustomizeskaffoldN)	__name__
__module____qualname__DOCKERHELMKPTKUBECTL	KUSTOMIZESKAFFOLD     5lib/googlecloudsdk/command_lib/deploy/release_util.pyr   r   M   s     &	$#')(r'   r   c                     t         j                   j                         }| j                  t        |j	                  d            }|j                  t
        |j	                  d            }t        |       |S )a  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(   RenderPatternr4   V   s`     %%'(##M83D3DX3NO,%%mX5F5Fv5NO,L)	r'   c                     g }t        t        |             D ]/  }| |   dk(  s|j                  t        j                  |             1 |rt        j                  | |      y)z8Find and notify user about dollar signs in release name.$N)rangelenappendsix	text_typer   InvalidReleaseNameError)r1   dollar_positionsis      r(   r0   r0   i   s^     Z!a!}cmmA./ " 

,
,Z9I
JJ r'   c                     | s|S g }t        t        j                  |             D ]'  \  }}|j                  |j	                  ||             ) ||_        |S )aM  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:   	iteritemsr9   BuildArtifactbuildArtifacts)imagesmessagesrelease_configbuild_artifactskeyvalues         r(   SetBuildArtifactsrL   t   sZ     
/3==01jc58111GH 2"1.	r'   c           
      h   t        j                  |       5 }	 t        j                  ||       }i }|d   D ])  }|d   ||j                  d|j                  d            <   + |cddd       S # t        j                  $ r%}t        j                  | |j                        d}~ww xY w# 1 sw Y   yxY w)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buildsrA   r@   	imageName)	r   
FileReaderr   loadErrorr   ParserErrorinner_errorget)pathfstructured_dataerF   builds         r(   LoadBuildArtifactFiler\      s     8		!t4o F *;@<fUYYw		+ 678 +   :: 8""4778 s-   B(A-4B(-B%  B  B%%B((B1c                 \   |s|st        | ||       t        j                  t        j                               }|j	                         }||_        t        || ||||||||||      }t        ||||||	|
|      }t        ||||      }t        |t        j                  j                  ||      }|S )zReturns a build config.)_VerifyConfigFileExistsr   GetMessagesModuleGetClientInstanceReleasedescription
_SetSource_SetVersion
_SetImages_SetDeployParametersr   ResourceTypeRELEASE)sourcegcs_source_staging_dirignore_filerF   rI   rb   docker_versionhelm_versionkpt_versionkubectl_versionkustomize_versionskaffold_versionskaffold_filedeploy_config_filelocationpipeline_uuidfrom_k8s_manifestfrom_run_manifestpipeline_objdeploy_parameters	hide_logsrG   rH   s                          r(   CreateReleaseConfigr{      s    8 0FM3EF**;+H+H+JK(##%.*.. 	. hP.'&&	. 
r'   c                 p   t        j                  ||      }t        j                  |j                        }|sCt
        j                  j                  dj                  t        |j                        |             |j                  | |||      }dj                  |j                  |j                        S )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.
  )rk   zVCreating temporary archive of {num_files} file(s) totalling {size} before compression.)	num_filessize)rk   rz   gs://{bucket}/{object}bucketobject)r   Snapshotr   TransformSizeuncompressed_sizer   statusPrintformatr8   r   CopyArchiveToGCSr   name)
gcs_clientgcs_source_stagingri   rk   rz   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                    | xr | xr | xr | xr | xr | }|r| S |dk(  xs |xr |j                  d      dk(  }	|xs |xs |xs
 |xs |xs |	}
|
s	|| _        | S |j                  ||||||      }|| _        | S )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)rH   rG   rl   rm   rn   ro   rp   rq   should_default should_skaffold_use_tool_versionuse_tool_versiontool_versionss               r(   rd   rd     s   X  
/ 
  
	
 
   &6%A &;+11#6!; #  *	*	* 
* 
	*
 
*  
%5N"''
! ( - !..	r'   c           	         d}t        j                  |      }|d}t        j                  |      }|j	                  d      st        j                  d|      t        j                         }d}|j	                  d      st        j                  j                  |      r"t        j                  j                  |      \  }}dj                  t        j                  t        j                               t!        j"                         j$                  |      }t&        j(                  j+                  |d	
      }	 |j-                  |j.                  ||dd       |j4                  r|j4                  dz   |z   }t&        j(                  j7                  d	|j.                  |      }d}d}|j	                  d      r[t&        j(                  j+                  |d	
      }|j9                  ||      }dj                  |j.                  |j:                        }n|s|rd}t=        |||||||
      }nt        j                  j?                  |      rtA        |||||      }nt        j                  j                  |      r|sEtB        jD                  jG                  dj                  ||j.                  |j4                               |jI                  ||      }dj                  |j.                  |j:                        }|	r|	| _%        || _&        | S tO        | ||      } || _(        | S # t        j0                  $ r& t        j2                  ddj                  |            w xY w)a  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.
    deploy_config_file: path of the deploy config file relative to the source
      directory that contains the deploy config 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)rt   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osrW   isfilesplitextr   GetTimeStampFromDateTimeNowr   uuid4hexr   REGISTRYParseCreateBucketIfNotExistsr   BucketInWrongProjectErrorRequiredArgumentExceptionr   CreateRewriter   *_UploadTarballGeneratedSkaffoldAndManifestisdirr   r   r   r   CopyFileToGCSdeployConfigPathdeployConfigUri_SetSkaffoldConfigPathskaffoldConfigUri)rH   ri   rj   rk   rt   ru   kubernetes_manifestcloud_run_manifestrr   rs   rx   rz   default_gcs_sourcedefault_bucket_namer   r   _staged_objectr   gcs_uriskaffold_is_generated
gcs_sourcer   s                          r(   rc   rc   a  se   T +CC #5<< 
 	*	*7	3

/
/1& 
 ((**&w277>>&#9  (IAv +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 &8N#%,N" 
 ,'<N (/N$	O 
	.	.  
0
0 	$$*F+>$?	 s   8 L   9Mc                     i }| j                   j                  D ]:  }|j                  D ])  }||vrg ||<   ||   j                  |j                         + < |S )zIGet mapping of profile to list of targets where the profile is activated.)serialPipelinestagesprofilesr9   targetId)rx   profile_to_targetsstageprofiles       r(   _GetProfileToTargetMappingr     s_    **11e>>	*	*&(7#!((8 " 2
 
r'   c                 h    i }| j                         D ]  \  }}t        |      dk(  s|||d   <    |S )zKGet mapping of profile to target that is only activated in a single target.   r   )itemsr8   )r   target_to_unique_profiler   targetss       r(   !_GetUniqueProfilesToTargetMappingr     sC    ,224gw
7|q-4wqz* 5 
"!r'   c                     t        |       }t        |      }t        |      t        | j                  j                        k7  rt        j                  d      |S )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   r8   r   r   core_exceptionsrS   )rx   r   r   s      r(   _GetTargetAndUniqueProfilesr     s\     2,?>
 		!"c,*E*E*L*L&MM


G  
"!r'   c                    t        j                         5 }d}d}	| rE| }t        j                  |t        j
                  j                  |      t        j                        }	nF|rD|}t        j                  |t        j
                  j                  |      t        j                        }	t        j
                  j                  |      s%t        j                  dj                  |            t        j                  ||       t        j
                  j                  |t               }
t        j"                  |
      5 }|j%                  d       t'        j(                  |	|d       ddd       t+        |||||      }t,        j.                  j1                  dj                  |	             |cddd       S # 1 sw Y   RxY w# 1 sw Y   yxY w)
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   rW   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   rk   rz   rx   temp_dirmanifestskaffold_yamlskaffold_pathrX   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qT2	 
)
 &G JJ>EE 	F 	

 Y "!6 
)	(7 "!s%   D%G:*F5$AG5F>	:GG
c                 r   |sd}|sd}| j                  d      r t        j                  j                  d       yt        j
                  j                  |       s%t        j                  dj                  |             t        j
                  j                  |       rt        | ||       yt        | ||       y)a  Checks that the specified source contains a skaffold or deploy config file.

  Args:
    source: the location of the source files
    skaffold_file: path of the skaffold file relative to the source directory
    deploy_config_file: path of the deploy config file relative to the source
      directory.

  Raises:
    BadFileException: If the source directory or files can't be found.
  r   zdeploy-config.yamlr   zNSkipping config file check. Reason: source is not a local archive or directoryzcould not find source [{src}]r   N)r   r   r   r   r   rW   r   r   r   r   r   _VerifyConfigFileIsInArchive_VerifyConfigFileIsInFolder)ri   rr   rs   s      r(   r^   r^   t  s     
#M	-wJJ	= 77>>&!

'
''..6.:  
ww~~f 8JK7IJr'   c           	      (   t         j                  j                  |       \  }}|t        vr+t	        j
                  ddj                  t              z         t        j                  |       st	        j
                  d      t        j                  | d      5 }	 |j                  |       ddd       y# t        $ rI 	 |j                  |       n3# t        $ r' t	        j
                  dj                  ||            w xY wY Zw xY w# 1 sw Y   yxY w)	ay  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.
    deploy_config_file: path of the deploy config 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)modezvCould not find skaffold or deploy config file. File [{skaffold}] or [{deploy_config}] does not exist in source archiver   deploy_configN)r   rW   r   _ALLOWED_SOURCE_EXTr   r   r   tarfile
is_tarfileopen	getmemberKeyErrorr   )ri   rr   rs   r   extarchives         r(   r   r     s    77F#&!S##

'
'(4995H+II  
		F	#

'
'I  ||F(G
& )(  	

,- 
++EEKV&6H FL F
 	

 	.	
 )(sB   DB33	D=CD0C??DDDDDc                 N   t         j                  j                  | |      }t         j                  j                  | |      }t         j                  j                  |      sFt         j                  j                  |      s&t	        j
                  dj                  ||            yy)ag  Verifies 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
    deploy_config_file: path of the deploy config file relative to the source
      directory.

  Raises:
    BadFileException: If the config file can't be found.
  zdCould not find skaffold or deploy config file. File [{skaffold}] or [{deploy_config}] does not existr   N)r   rW   r   r   r   r   r   )ri   rr   rs   path_to_skaffoldpath_to_deploy_configs        r(   r   r     s     WW\\&-8'',,v/AB	(	)"''..3 
'
'	,,2F%5J -3 -
 3	)r'   c                 6    |rt        |      }t        || |      S )z3Set the image substitutions for the release config.)r\   rL   )rG   rH   rF   rI   s       r(   re   re     s    "?3F	68^	<<r'   c                 2    |r|| _         |rt        | _         | S )zJSet the path for skaffold configuration file relative to source directory.)skaffoldConfigPathr   )rH   rr   is_generateds      r(   r   r     s    (5N%(:N%	r'   c                     |rrt        | |j                        j                  } |       }|j                         D ]1  \  }}|j                  j                  |j                  ||             3 ||_        |S )z1Set the deploy parameters for the release config.)rJ   rK   )getattrrK   DeployParametersValuer   additionalPropertiesr9   AdditionalPropertydeployParameters)rG   resource_typerH   ry   dps_value_msg	dps_valuerJ   rK   s           r(   rf   rf     st     Hm&9&9:PPMI'--/
U$$++

*
*s%
*
@ 0
 '0N#	r'   c                 t   g }| j                         }| j                         }|D ]  }|j                  }t        j                  |      }t        j
                  ||      }|=t        j                  |j                        }	|	j                         j                         }
||
k(  s|j                  |        |S )aQ  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	   RolloutReferenceFromNamer9   )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//
LIK778H8HIK'..0==?,,j)  
r'   c                 h   g }g }g }|r| j                         }t        j                  ||d   |d         }|j                         |j                  D cg c]!  }t        j
                  |j                        # c}vr|j                  |j                                |j                  D ]a  }|j                  }		 t        j                  t        j                  |	            }
|
j                  |j                  k7  r|j                  |	       c |j&                  j                  }	 t)        j*                         j-                  |      }|j                  |j&                  j                  k7  r-|j                  | j/                         j                                |||fS c c}w # t        j                  $ ro}t        j                  dj!                  |	|             t        j"                  j%                  dj!                  |	             |j                  |	       Y d}~ud}~ww xY w# t        j                  $ ry}t        j                  dj!                  ||j0                               t        j"                  j%                  dj!                  |             |j                  |       Y d}~d}~ww xY w)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   r9   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   rx   s                 r(   DiffSnappedPipeliner@    sE   . !!#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4T5==IJJJ9@@FGd##$s:   &F8AF #A3H%  H"3A$HH"%J18A.J,,J1c                    t        | ||      \  }}}|r0|t        j                  dj                  t	        |                  z  }|r0|t
        j                  dj                  t	        |                  z  }|r0|t        j                  dj                  t	        |                  z  }t        j                  j                  |       y)aK  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  r8  	target_idpromptr<  r;  r:  s          r(   	PrintDiffrI  Y  s     <O;	<8$&8 
%%dii=M0N&OPPF
 ''		,123 F 
%%dii=M0N&OPPF**6r'   c                 N    t        t        |             D ]  }d| |   z   | |<    | S )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- )r7   r8   )str_listr>   s     r(   rD  rD  r  s0     Xa!$HQK   
/r'   c                 z    d}| j                   D ])  }t        j                  |j                        |k(  s&|} |S  |S )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   )r8  rG  r>  sss       r(   GetSnappedTargetrN    sF     *''bBGG$	1j	 (
 
r'   c                    g }g }t        j                  t        j                               }t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}|D ]i  }t        | |      }|s|j                  j                  }||j                  k(  r|j                  |       I||j                  k(  r|j                  |       jk |rEdj!                  |D cg c]  }|j"                   c}      }	t%        j&                  d| d|	 d      |rMdj!                  |D cg c]  }|j"                   c}      }	t(        j*                  j-                  d|	 d       yt/        |       }
|j0                  j2                  }|
|j4                  k(  rt%        j&                  d| d      |
|j6                  k(  r t(        j*                  j-                  d	       yyc c}w c c}w )
ay  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   r_   r`   r   r    r!   r"   r#   r$   r%   _GetToolVersionSupportStateToolVersionSupportedCondition&ToolVersionSupportStateValueValuesEnum&TOOL_VERSION_SUPPORT_STATE_UNSUPPORTEDr9   +TOOL_VERSION_SUPPORT_STATE_MAINTENANCE_MODEr   rK   r   rS   r   r   r   _GetSkaffoldSupportStateSkaffoldSupportedCondition#SkaffoldSupportStateValueValuesEnum"SKAFFOLD_SUPPORT_STATE_UNSUPPORTED'SKAFFOLD_SUPPORT_STATE_MAINTENANCE_MODE)r8  actiontools_in_maintenancetools_unsupportedrG   toolststatetool_version_enumjoinedskaffold_support_stateskaffold_support_state_enums               r(   CheckReleaseSupportStaterd    s    **;+H+H+JK(<<::99==??>>% a'Q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                     | j                   r6| j                   j                  r | j                   j                  j                  S y)zGets the Skaffold Support State from the release.

  Args:
    release_obj: release message obj.

  Returns:
    None or SkaffoldSupportStateValueValuesEnum
  N)	conditionskaffoldSupportedConditionskaffoldSupportState)r8  s    r(   rU  rU    s6     {44OO  ;;PPP	r'   c                    | j                   sy|t        j                  k(  r7| j                   j                  r | j                   j                  j                  S y|t        j
                  k(  r7| j                   j                  r | j                   j                  j                  S y|t        j                  k(  r7| j                   j                  r | j                   j                  j                  S y|t        j                  k(  r7| j                   j                  r | j                   j                  j                  S y|t        j                  k(  r7| j                   j                  r | j                   j                  j                  S y|t        j                  k(  r6| j                   j                  r | j                   j                  j                  S y)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)rf  r   r    dockerVersionSupportedConditiontoolVersionSupportStater!   helmVersionSupportedConditionr"   kptVersionSupportedConditionr#    kubectlVersionSupportedConditionr$   "kustomizeVersionSupportedConditionr%   !skaffoldVersionSupportedCondition)r8  tools     r(   rP  rP    sv    
			U\\<<



?
?
W
W8 
3 uzz::



=
=
U
U. 
) 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   r1  !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   rE  rC  rF  r-   r/   r   Enumr   r4   r0   rL   r\   r{   r   rd   rc   r   r   r   r   r^   r   r   re   r   rf   r&  r@  rI  rD  rN  rd  rU  rP  r&   r'   r(   <module>r     sV   7       > 6 : @ 6 > 9 8 : ; A 9 = # ) $ ; * * 
 @  . + ! /    % DII &K,T +BJ(VNz Yx""2GTK>!
H2= :G@T2"*M`*r'   