
                             S 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  \R                  R                   R"                  R$                  rS	 rS
 rS rS rSS jrS rS rS rS rS rS rS rS r S r!S r"S\#S\#4S jr$g)zHContains shared methods for printing k8s object in a human-readable way.    N)resource_name_conversion)
conditions)console_attr)custom_printer_base)	condition)vendor_settingsc                 N     U R                  U5        U $ ! [         a    Us $ f = f)zBChoose the best symbol (if it's in this encoding) or an alternate.)encodeUnicodeError)bestaltencodings      >lib/googlecloudsdk/command_lib/run/printers/v2/printer_util.py_PickSymbolr       s,    KKK	 Js    $$c                     [         R                  " 5       R                  5       n[        R                  " U 5      nUc  [        SSU5      S4$ [        R                  " U5      (       a  [        SSU5      S4$ g)zAReturn a tuple of ready_symbol and display color for this object.   ….yellow   ✔+green)Xred)r   GetConsoleAttrGetEncodingr   GetTerminalConditionr   IsConditionReady)recordr   terminal_conditions      r   ReadySymbolAndColorr    )   sv    ((*668(!66v>-sH=  ""#566-sH=wFF    c                 p   [         R                  " U 5      nU(       aq  UR                  (       a`  [        U 5      u  p#[        R
                  " 5       R                  [        R                  " SR                  X!R                  5      S5      U5      $ Uc%  [        R
                  " 5       R                  SS5      $ g)zDReturns the record's status condition Ready (or equivalent) message.z{} {}d   z Error getting status informationr    )
r   r   messager    r   r   Colorizetextwrapfillformat)r   r   symbolcolors       r   FormatReadyMessager,   8   s    !66v>.66'/MF&&(11gnnV-G-GH#N  !&&(11*E  r!   c                     U R                   (       d  gU R                  =(       d    SnSnU R                   R                  (       a  U R                   R                  nSR                  X!5      $ )NzUnknown update information?zLast updated on {} by {})r   last_modifierlast_transition_timer)   )r   modifierr0   s      r   LastUpdatedMessager2   I   sW    		"	"'!!(S(33!44II	#	*	*+?	JJr!   c                 v   [         R                  " 5       nUR                  " [        U 5      6 nU(       a&  [        R
                  " U R                  5      u  pV  pWnO#[        R                  " U R                  5      u  pVpxU(       a  SOSU-   n	U(       a  SOSU-   n
UR                  SR                  XJX5      5      $ )z(Returns a display header for a resource.zregions zregion zMulti-Region r$   z{} {} {} in {})
r   r   r&   r    r   GetInfoFromFullChildNamenameGetInfoFromFullName	Emphasizer)   )r   is_multi_regionis_child_resourceconstatus_regionresource_kindr5   placekinds              r   BuildHeaderrA   S   s    ##%#<<,V45& 99&++F )Aq!D
 	!44V[[A #A} ):i6
A%,/"	E$	'..vTI	JJr!   c                    S nU R                   nU(       a,  [        R                  " SU4SU" U R                  5      4/5      $ U R                  (       d  g U R                  S   n[        R                  " SUR
                  (       a  UR
                  OS4SUR                  (       a  UR                  OS4SU" U R                  5      4/5      $ ! [         a     gf = f)a7  Returns the VPC Network setting.

Either the values of the vpc-access-connector and vpc-access-egress, or the
values of the network and subnetwork in network-interfaces annotation and
vpc-access-egress.

Args:
  record:
    googlecloudsdk.generated_clients.gapic_clients.run_v2.types.vendor_settings.VpcAccess.
c                     U [         R                  R                  R                  :X  a  gU [         R                  R                  R                  :X  a  gg)Nzall-trafficzprivate-ranges-onlyr$   )r   	VpcAccess	VpcEgressALL_TRAFFICPRIVATE_RANGES_ONLY)egresss    r   
_GetEgress!GetVpcNetwork.<locals>._GetEgressp   s?    **44@@@	?,,66JJ	J"r!   	ConnectorEgressr$   r   NetworkSubnet)	connectorcpLabeledrH   network_interfacesnetwork
subnetwork	Exception)r   rI   rO   network_interfaces       r   GetVpcNetworkrW   d   s     )::	i v}}%	
   
	"	"11!4::):)B)B%%	

  ++ ((		
 v}}%	
    
 s   A7C 
CCc                 X    [         R                  " U R                  S5      5      u      pU$ )zExtracts short name from a resource.

Args:
  resource: dict representing a Cloud Run v2 resource.

Returns:
  Short name of the resource.
r5   r   r6   getresourcer<   r5   s      r   GetNameFromDictr]      s-     +>>ll6-!Q 
+r!   c                 \    [         R                  " U R                  S5      5      u          pU$ )zExtracts short name from a resource.

Args:
  resource: dict representing a Cloud Run v2 child resource.

Returns:
  Short name of the resource.
r5   r   r4   rZ   r[   s      r   GetChildNameFromDictr`      s2     1IIll6!Q1a 
+r!   c                 X    [         R                  " U R                  S5      5      u  p  nU$ )zExtracts region from a resource.

Args:
  resource: dict representing a Cloud Run v2 resource.

Returns:
  Region of the resource.
r5   rY   )r\   r<   r=   s      r   GetRegionFromDictrb      s-     -@@ll6/!Q 
-r!   c                 \    [         R                  " U R                  S5      5      u      p  nU$ )zExtracts region from a child resource.

Args:
  resource: dict representing a Cloud Run v2 child resource.

Returns:
  Region of the resource.
r5   r_   )r\   r<   parents      r   GetParentFromDictre      s2     3KKll6!Q1a 
-r!   c                     U R                  S5      (       a)  U R                  S5      R                  S5      nU(       a  U$ g)zExtracts last transition time from a resource.

Args:
  resource: dict representing a Cloud Run v2 resource.

Returns:
  Last transition time of the resource if it exists, otherwise None.
r   r0   NrZ   )r\   results     r   GetLastTransitionTimeFromDictri      s:     \\&''\\./334JKFm	r!   c                 f    U R                  S5       H  nUR                  S5      U:X  d  M  Us  $    g)z>Returns the condition matching the given type from a resource.r   type_Nrg   )r\   condition_typer   s      r   _GetConditionFromDictrm      s1    <<-i}}W/ . 
r!   c                 h    U R                  S5      (       a  U R                  S5      $ [        U S5      $ )z*Returns the ready condition of a resource.r   Ready)rZ   rm   )r\   s    r   _GetReadyConditionFromDictrp      s/    \\&''<<,--	x	11r!   c                     [         R                  " 5       R                  5       n[        U 5      nUc  [	        SSU5      $ UR                  S5      [        :X  a  [	        SSU5      $ g)zReturn a ready_symbol for a resource.

Args:
  resource: dict representing a Cloud Run v2 resource.

Returns:
  A string representing the symbol for the resource ready state.
r   r   stater   r   r   )r   r   r   rp   r   rZ   _CONDITION_SUCCEEDED_VALUE)r\   r   ready_conditions      r   GetReadySymbolFromDictru      sb     ((*668(.x8/0#x@@7#'AA-sH==r!   c                 Z    [        U S5      nU(       a  UR                  S5      [        :H  $ g)zReturn active state for a resource.

Args:
  resource: dict representing a Cloud Run v2 resource.

Returns:
  True if the resource is active, false otherwise.
Activerr   F)rm   rZ   rs   )r\   active_conditions     r   GetActiveStateFromDictry     s.     +8X>(,FFF	r!   cmek_keyreturnc                 >    U (       d  gU R                  S5      S   nU$ )zwReturns the CMEK name from a full CMEK key name.

Args:
  cmek_key: The full CMEK key name.

Returns:
  The CMEK name.
r$   /)split)rz   	cmek_names     r   GetCMEKr     s#     
nnS!"%)	r!   )FF)%__doc__r'   googlecloudsdk.command_lib.runr   !googlecloudsdk.command_lib.run.v2r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   rP   ;googlecloudsdk.generated_clients.gapic_clients.run_v2.typesr   condition_objectsr   	ConditionStateCONDITION_SUCCEEDEDvaluers   r   r    r,   r2   rA   rW   r]   r`   rb   re   ri   rm   rp   ru   ry   strr    r!   r   <module>r      s     O  C 8 4 B f W %%99?? 
"KK"2j 2&c c r!   