+
    g(                        ^ RI t ^ RIt^ RIt^ RIt^ RIHtHtHtHt ^ RI	H
t
HtHtHtHt ^ RIHt ]P"                  ! ]P$                  ! ]4      4      tRtRtRtRtR	tR
tRR.RRR.RRR.RRR.RRR./t ! R R]4      tR# )    N)AnyDictListOptional)
exceptionshttpsecret_managersystemutil)PublicCloudAutoAttachInstancezhttp://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=contracts.canonical.com&format=full&licenses=TRUEzThttp://metadata.google.internal/computeMetadata/v1/instance/licenses/?recursive=truez&wait_for_change=truez&last_etag={etag}z/sys/class/dmi/id/product_namezGoogle Compute Enginexenial8045211386737108299bionic60224277247198918307427070211152946628focal5999592893498423827818678586103571931jammy2592866803419978320160084055690847662noble21760544822697860254168323874790319525c                      a  ] tR t^$t o R t]]P                  ! ]P                  . ROR7      V 3R lR l4       4       t
]V 3R lR l4       t]V 3R lR l4       tV 3R	 lR
 ltV 3R lR ltV 3R lR ltRtV tR# )GCPAutoAttachInstancec                    R V n         R # )Netagselfs   &5/usr/lib/python3/dist-packages/uaclient/clouds/gcp.py__init__GCPAutoAttachInstance.__init__%   s     	    )retry_sleepsc                6   < V ^8  d   QhRS[ S[S[3,          /#    return)r   strr   )format__classdict__s   "r"   __annotate__"GCPAutoAttachInstance.__annotate__.   s     
 
d38n 
r%   c                   \         P                  ! \        R R/^R7      pVP                  ^8X  d8   \        P
                  P                  VP                  4       RVP                  /# VP                  P                  R4      pV'       d8   RVP                  4       9   d#   \        P                  ! VP                  VR7      h\        P                  ! VP                  VP                  R7      h)Metadata-FlavorGoogle)headerstimeoutidentityTokenerror_descriptionzservice account)status_code	error_msg)codebody)r   readurl	TOKEN_URLr9   r	   secrets
add_secretr:   	json_dictgetlowerr   GCPServiceAccountErrorCloudMetadataError)r!   response
error_descs   &  r"   identity_doc"GCPAutoAttachInstance.identity_doc,   s     << 18<a
 ==C""--hmm<#X]]33''++,?@
+z/?/?/AA33$MMZ  ++X]]
 	
r%   c                    < V ^8  d   QhRS[ /# r(   )r+   )r,   r-   s   "r"   r.   r/   @   s      C r%   c                    R # )gcp r    s   &r"   
cloud_type GCPAutoAttachInstance.cloud_type?   s    r%   c                    < V ^8  d   QhRS[ /# r(   bool)r,   r-   s   "r"   r.   r/   D   s      4 r%   c                    \         P                  P                  \        4      '       d6   \        P
                  ! \        4      p\        VP                  4       8X  d   R# R# )z$This machine is a viable GCPInstanceTF)ospathexistsDMI_PRODUCT_NAMEr
   	load_fileGCP_PRODUCT_NAMEstrip)r!   product_names   & r"   	is_viableGCPAutoAttachInstance.is_viableC   s@     77>>*++!++,<=L<#5#5#77r%   c                0   < V ^8  d   QhRS[ S[,          /# r(   )r   r+   )r,   r-   s   "r"   r.   r/   M   s     
 
DI 
r%   c                <   V P                   R,          p\        P                  ! VP                  R4      ^,          R,           4      p\        P
                  ! VP                  R4      4      pVP                  R/ 4      P                  R/ 4      P                  R. 4      # )zGet a list of licenses from the GCP metadata.

Instance identity token (jwt) carries a list of licenses
associated with the instance itself.

Returns an empty list if licenses are not present in the metadata.
r5   .z===zutf-8googlecompute_engine
license_id)rF   base64urlsafe_b64decodesplitjsonloadsdecoder@   )r!   tokenidentityidentity_dicts   &   r"   get_licenses_from_identity0GCPAutoAttachInstance.get_licenses_from_identityM   s|     !!/2++EKK,<Q,?%,GH

8??7#;<h+S!2&Sr"	
r%   c                    < V ^8  d   QhRS[ /# r(   rO   )r,   r-   s   "r"   r.   r/   ^   s      T r%   c                    \         P                  ! 4       P                  pV\        9  d   \        P                  R 4       R# R# )z0This series isn't supported for GCP auto-attach.FT)r
   get_release_infoseriesGCP_LICENSESLOGinfo)r!   rp   s   & r"   should_poll_for_pro_license1GCPAutoAttachInstance.should_poll_for_pro_license^   s1    ((*11%HHGHr%   c                &   < V ^8  d   QhRS[ RS[ /# )r)   wait_for_changer*   rO   )r,   r-   s   "r"   r.   r/   e   s     6 6 6$ 6r%   c                  \         pV'       dG   V\        ,          pV P                  '       d(   V\        P	                  V P                  R 7      ,          p\
        P                  ! VRR/R7      pVP                  ^8X  d   VP                   Uu. uF  qDR,          NK  	  ppVP                  P                  R4      V n        \        P                  ! 4       P                  p\        P                  V. 4       F  pWu9   g   K   R# 	  R# \        P!                  VP"                  4       VP                  R8X  d   \$        P&                  ! 4       h\$        P(                  ! 4       hu upi )	r   r1   r2   )r3   idr   TFi  )LICENSES_URLWAIT_FOR_CHANGEr   	LAST_ETAGr,   r   r;   r9   	json_listr3   r@   r
   ro   rp   rq   rr   errorr:   r   CancelProLicensePollingDelayProLicensePolling)r!   rw   urlrD   licenselicense_idsrp   lics   &$      r"   is_pro_license_present,GCPAutoAttachInstance.is_pro_license_presente   s   ?"Cyyyy''TYY'77<<.?-JK==C8@8J8JK8JW4==8JKK ((,,V4DI,,.55F#''3% 4 		(-- ==C44663355 Ls   E"r   N)g      ?   r   )__name__
__module____qualname____firstlineno__r#   propertyr   retryr   rC   rF   rL   rZ   rk   rt   r   __static_attributes____classdictcell__)r-   s   @r"   r   r   $   s~      	ZZ
--KH
 I 
"    
 
" 6 6r%   r   )rb   re   loggingrR   typingr   r   r   r   uaclientr   r   r	   r
   r   uaclient.cloudsr   	getLoggerreplace_top_level_logger_namer   rr   r<   rz   r{   r|   rU   rW   rq   r   rK   r%   r"   <module>r      s       	 , , C C 9::8DE  
  *	3 *  $%$&;<"$9:#%9:#%:;W69 W6r%   