+
    GvKjS;                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
HtHtHtHtHtHtHtHt ^ RI
Ht ^ RI
HtHt ^ RI
Ht ^ RI
HtHtHt ^ RIHtHtHtH t  ^ R	I!H"t"H#t# ^ R
I$H%t%H&t&H't'H(t(H)t) ]PT                  ! 4       t+]PX                  ! ]PZ                  ! ].4      4      t/R't0^
t1R R lt2R(R R llt3R(R R llt4R)R R llt5RRRRRRRR/R R llt6RRRR/R R lltR R  lt7R*R! R" llt8R# R$ lt9R% R& lt:R# )+    N)ListOptional)apicloudsconfigcontractentitlementsevent_logger
exceptions	livepatch)log)messagessecret_manager)status)systemtimerutil)APPARMOR_PROFILESCLOUD_BUILD_INFODEFAULT_CONFIG_FILEDEFAULT_LOG_PREFIX)machine_tokennotices)AttachmentDataattachment_data_filemachine_id_fileonly_series_check_marker_filetimer_jobs_state_filec                x    V ^8  d   QhR\         P                  R\        P                  R\        P                  /# )   cfgcontract_clientattached_at)r   UAConfigr   UAContractClientdatetime)formats   "2/usr/lib/python3/dist-packages/uaclient/actions.py__annotate__r)   9   s6     
, 
,	
,..
, ""
,    c                     ^ RI Hp \        P                  ! \	        VR7      4       \
        P                  ! V R7       V! V 4       VP                  4        R# )r   update_motd_messagesr#   r!   N)uaclient.timer.update_messagingr-   r   writer   	ua_statusr   update_activity_token)r!   r"   r#   r-   s   &&& r(   _handle_partial_attachr4   9   s=    
 E~+FG))+r*   Fc          
          V ^8  d   QhR\         P                  R\        \        P                  ,          R\        P
                  R\        P                  R\        /# )r    r!   services_to_be_enabledr"   r#   silent)r   r$   r   r   EnableByDefaultServicer%   r&   bool)r'   s   "r(   r)   r)   F   sU     ? ?	? !@!@A? ..? ""	?
 ?r*   c                 R   R p. p. p V Fu  p\        V VP                  VP                  VR7      w  rWY,          pV	'       g   VP                  VP                  4       KU  \        P                  VP                  R7       Kw  	  T'       g   \        YT4       \        P                  T4       T'       dr   \        P                  ! \        Yg4       UUu. uFD  w  rT\        P                   P#                  \%        T4      \&        P(                  ! 4       R7      3NKF  	  uppR7      h\        P*                  ! T Uu. uF  pT\        P,                  3NK  	  upR7      hR#   \        P                   d3   p\        P                  XP                  4       \        YT4       ThRp?i\        P                   d"    TP                  XP                  4       Rp ELU\         d:   pRpTP                  XP                  4       TP                  T4        Rp?ELRp?ii ; iu uppi u upi )T)r!   namevariantr7   )serviceNF)	error_msglog_path)failed_services)enable_entitlement_by_namer;   r<   appendeventservice_processedr   ConnectivityErrorservice_failedr4   UbuntuProError	Exceptionservices_failedAttachFailureUnknownErrorzipr   UNEXPECTED_ERRORr'   strpro_logget_user_or_root_log_file_pathAttachFailureDefaultServices!E_ATTACH_FAILURE_DEFAULT_SERVICES)r!   r6   r"   r#   r7   retr@   unexpected_errorsenable_by_default_serviceent_retreasonexcer;   	exceptions   &&&&&          r(   _enable_default_servicesrZ   F   s    CO$)?%8.33199	OG NC&&'@'E'EF''0I0N0N'O *@2 s[Ao.66 ,/',!,  1188&))n%,%K%K%M 9 ,!  99 !0! / 8EEF /! +  '' 6;;<s[A	$$ 8==> $8==>  ##$!!sC   A;E A
H
9H$H3-F  H7HH!H".HHc          
      `    V ^8  d   QhR\         P                  R\        R\        R\        RR/# )r    r!   tokenallow_enabler7   returnN)r   r$   rM   r9   )r'   s   "r(   r)   r)      sE     \ \	\\ \ 	\
 
\r*   c                   ^ RI Hp ^ RIHp \        P
                  P                  V4       \        P                  ! V 4      p\        P                  ! V 4      p\        P                  P                  \        P                  P                  R7      pVP                  WR7      p	\         P"                  ! 4       P$                  p
V	P'                  R/ 4      P'                  R/ 4      p\)        R VP'                  R. 4       4       4      pVP'                  R	/ 4      P'                  R
/ 4      P'                  RR4      pV'       d    \         P*                  ! V4      p\         P*                  ! V
4      pVP,                  VP,                  8  d-   \.        P0                  ! VP2                  VP4                  R7      h\6        P8                  ! \6        P:                  P<                  VP2                  VP4                  R7       \>        P@                  ! V4       VPA                  V	4        V! V 4       \         PH                  PK                  4        T	P'                  R/ 4      P'                  R\         PH                  ! T 4      4      p\L        P@                  ! T4       T'       d5   \        PN                  ! YPQ                  4       4      p\S        T TTTTR7       \T        P@                  ! \W        TR7      4       T! T 4       \X        PZ                  ! 4        R#   \.        PB                   d     ELi ; i  \.        PD                   d   pTPG                  4        ThRp?ii ; i)a+  
Common functionality to take a token and attach via contract backend
:raise ConnectivityError: On unexpected connectivity issues to contract
    server or inability to access identity doc from metadata service.
:raise ContractAPIError: On unexpected errors when talking to the contract
    server.
)+check_entitlement_apt_directives_are_uniquer,   )tz)contract_tokenattachment_dtmachineTokenInfocontractInfoc              3   x   "   T F0  pVP                  R 4      R8X  g   K  VP                  R 4      V3x  K2  	  R# 5i)typesupportN)get).0rX   s   & r(   	<genexpr>$attach_with_token.<locals>.<genexpr>   s6      =A55=I% 	v=s   ::resourceEntitlementsrh   affordances
onlySeriesN)releaseseries_codename	machineId)r!   r6   r"   r#   r7   r.   ).uaclient.entitlementsr`   r0   r-   r   secrets
add_secretr   get_machine_token_filer   r%   r&   nowtimezoneutcadd_contract_machiner   get_release_infoseriesri   dictget_distro_infoeolr   AttachFailureRestrictedReleaserp   rq   r   addNoticeLIMITED_TO_RELEASEr   r1   MissingSeriesInDistroInfoFile%EntitlementsAPTDirectivesAreNotUniquedeleteget_machine_idcache_clearr   get_enabled_by_default_servicesr	   rZ   r   r   r   start)r!   r\   r]   r7   r`   r-   machine_token_filer"   r#   new_machine_tokencurrent_seriesre   support_resourceonly_seriesallowed_releasecurrent_releaserX   
machine_idr6   s   &&&&               r(   attach_with_tokenr      s    E%%e,&==cB//4O##''8+<+<+@+@'AK'<< =  ,,.55N$(();R@DDL  !!"8"=  	Y+	]B		\4	   	=$44[AO %44^DO""_%8%88 ??+33$3$C$C 
 KK11'// / ? ?
 *//<./3C8
 %%'"&&'92>BBV**3/J *%!)!I!I002"
 	!#9+#	
 ~+FG	KKM] 77 	 	, ;; !!#s*    L  L) L&%L&)M>MMc                \    V ^8  d   QhR\         P                  R\        P                  RR/# )r    r!   cloudr^   N)r   r$   r   AutoAttachInstance)r'   s   "r(   r)   r)      s5     C C	C$$C 
	Cr*   c                B    VP                  V 4      p\        WVR7       R# )a@  
:raise ConnectivityError: On unexpected connectivity issues to contract
    server or inability to access identity doc from metadata service.
:raise ContractAPIError: On unexpected errors when talking to the contract
    server.
:raise NonAutoAttachImageError: If this cloud type does not have
    auto-attach support.
)r\   r]   N)acquire_pro_tokenr   )r!   r   r]   r\   s   &&& r(   auto_attachr      s     ##C(Ec\Br*   access_onlyr<    r7   
extra_argsc                    V ^8  d   QhR\         P                  R\        R\        R\        R\        R\        \
        \        ,          ,          /# )r    r!   r;   r   r<   r7   r   )r   r$   rM   r9   r   r   )r'   s   "r(   r)   r)      sQ      	
 	
   c#r*   c                  \         P                  ! V VVVVR7      pV'       g>   \        P                  \        P
                  P                  VP                  R7      4       VP                  \        P                  ! 4       4      w  rxV'       dF   V'       g>   \        P                  \        P                  P                  VP                  R7      4       Wx3# )z
Constructs an entitlement based on the name provided. Passes kwargs onto
the entitlement constructor.
:raise EntitlementNotFoundError: If no entitlement with the given name is
    found, then raises this error.
)r!   r;   r<   r   r   )title)r	   entitlement_factoryrC   infor   ENABLING_TMPLr'   r   enabler   ProgressWrapperENABLED_TMPL)	r!   r;   r   r<   r7   r   entitlementrU   rV   s	   &&$$$$   r(   rA   rA      s     22K 

8))00{7H7H0IJ!(()<)<)>?OGv

8((//k6G6G/HI?r*   simulate_with_tokenshow_allc                f    V ^8  d   QhR\         P                  R\        \        ,          R\        /# )r    r!   r   r   )r   r$   r   rM   r9   )r'   s   "r(   r)   r)     s0      	 "# 	r*   c                   V'       d   \         P                  ! V VVR7      w  r4W43# \         P                  ! WR7      p^ pW43# )z.
Construct the current Pro status dictionary.
)r!   r\   r   r!   r   )r2   simulate_statusr   )r!   r   r   r   rR   s   &$$  r(   r   r     sK     //%
 ; !!c=;r*   c                (    V ^8  d   QhR\         RR/# )r    filenamer^   N)rM   )r'   s   "r(   r)   r)   0  s     B B3 B4 Br*   c                   . ROpRpRp \         P                  ! V4      w  r4V'       dr   . pVP                  R4       F2  p\        P                  ! W&4      '       g   K!  VP                  V4       K4  	  \         P                  ! V RP                  V4      4       R# R#   \        P                   dZ   p\        P                  R\        T4      4       \         P                  ! RP                  T 4      \        T4      4        Rp?R# Rp?ii ; i)zy
Helper which gets ubuntu_pro apparmor logs from the kernel from the last
day and writes them to the specified filename.
z7apparmor=\".*(profile=\"ubuntu_pro_|name=\"ubuntu_pro_)N
z!Failed to collect kernel logs:
%s{}-error)
journalctlz-bz-kz--since=1 day ago)r   subpsplitresearchrB   
write_filejoinr   ProcessExecutionErrorLOGwarningrM   r'   )r   cmdapparmor_rekernel_logs_apparmor_logskernel_linerX   s   &       r(   _write_apparmor_logs_to_filer   0  s     :CLKKBS)
 M*00699[66!((5  7 h		-(@A 	 ++ ?8#a&A*++H5s1v>>?s   B D2ADDc                `    V ^8  d   QhR\         R\        \        \        ,          ,          RR/# )r    r   return_codesr^   N)rM   r   r   int)r'   s   "r(   r)   r)   I  s-     
 

&.tCy&9
	
r*   c                H    \         P                  ! V P                  4       VR7      w  r4\         P                  ! VRP	                  W44      4       R#   \
        P                   d;   p\         P                  ! RP	                  T4      \        T4      4        Rp?R# Rp?ii ; i)zCHelper which runs a command and writes output or error to filename.)rcszstdout:
{}

stderr:
{}r   N)r   r   r   r   r'   r   r   rM   )r   r   r   outerrrX   s   &&&   r(   _write_command_output_to_filer   I  sz    
;;syy{= 	299#C	
 ++ ?*++H5s1v>>?s   (A B!'/BB!c                8    V ^8  d   QhR\         P                  /# )r    r!   )r   r$   )r'   s   "r(   r)   r)   W  s      &// r*   c                    a  S P                   ;'       g    \        S P                  \        P                  P
                  \        .V 3R  l\        P                   4       O# )c              3      <"   T FC  p\        V\        P                  P                  4      '       g   K/  V! S4      P                  x  KE  	  R # 5iN)
issubclassr	   repoRepoEntitlement	repo_file)rj   entitlement_clsr!   s   & r(   rk   #_get_state_files.<locals>.<genexpr>^  s;      

#C/<+<+<+L+LM +OC **#Cs
   ,AA)	cfg_pathr   log_filer   ua_filepathr   r	   ENTITLEMENT_CLASSESr/   s   fr(   _get_state_filesr   W  sP     	+++%%**	



#/#C#C


 
r*   c                D    V ^8  d   QhR\         P                  R\        /# )r    r!   
output_dir)r   r$   rM   )r'   s   "r(   r)   r)   f  s"     f ffoo f3 fr*   c                
   \        RRP                  V4      4       \        RP                  \        P                  4      RP                  V4      4       \        RRP                  V4      4       \        RRP                  V4      4       \        R	P                  R
P	                  \
         Uu. uF  pRV9   g   K  RP                  V4      NK  	  up4      4      RP                  V4      4       \
         F1  p\        RP                  V4      RP                  W4      ^ ^.R7       K3  	  \        V RR7      w  rE\        P                  ! RP                  V4      \        P                  ! V\        P                  R7      4       \        P                  ! 4       p\        P                  ! RP                  V4      \        P                  ! V4      4       \        V 4      p\        P                  ! 4       '       d   \         P"                  ! 4       R\$         M\         P&                  ! 4       .p\)        V4       F  w  r\*        P,                  P/                  V
4      '       d   \0        P3                  RV
4       KB   \        P4                  ! \        P6                  ! V
4      4      p\        P                  ! \*        P,                  P	                  VRP                  V	4      4      V4       K  	  V\<        P<                  ! \>        R,           4      ,            F  p\*        P,                  PA                  V4      '       g   K*   \        P6                  ! V4      p\        P4                  ! T4      p\        P                  ! 4       '       d   \        P                  ! Y4       \        P                  ! \*        P,                  P	                  T\*        P,                  PC                  T4      4      T4       K  	  \E        RP                  V4      4       \F         FA  p\*        P,                  PA                  V4      '       g   K*   \H        PJ                  ! W4       KC  	  R# u upi   \8         d-   p\0        P3                  RT
\;        T4      4        Rp?EKY  Rp?ii ; i  \8         d-   p\0        P3                  RT\;        T4      4        Rp?EK  Rp?ii ; i  \8         d,   p\0        P3                  RT\;        T4      4        Rp?K  Rp?ii ; i)z?
Write all relevant Ubuntu Pro logs to the specified directory
zcloud-idz{}/cloud-id.txtz	{} statusz{}/livepatch-status.txtzsystemctl list-timers --allz{}/systemd-timers.txtzujournalctl --boot=0 -o short-precise -u cloud-init-local.service -u cloud-init-config.service -u cloud-config.servicez{}/cloud-init-journal.txtzjournalctl -o short-precise {} z.servicez-u {}z{}/pro-journal.txtzsystemctl status {}z	{}/{}.txt)r   Fr   z{}/pro-status.json)clsz{}/environment_vars.jsonNz$Skipping symlinked user log file: %sz
user{}.logz&Failed to collect user log file: %s
%s*zFailed to load file: %s
%sz{}/apparmor_logs.txtzFailed to copy file: %s
%s)&r   r'   r   LIVEPATCH_CMDr   UA_SERVICESr   r   r   jsondumpsr   DatetimeAwareJSONEncoderget_pro_environmentr   we_are_currently_rootrN   get_all_user_log_filesUSER_LOG_COLLECTED_LIMITget_user_log_file	enumerateosr   islinkr   r   redact_sensitive_logs	load_filerH   rM   globr   isfilebasenamer   r   shutilcopy)r!   r   sr=   
pro_statusr   env_varsstate_filesuser_log_fileslog_file_idxr   contentrX   fs   &&            r(   collect_logsr   f  s    "%,,Z8 "9223!((4 "%&&z2 "&
 	$**:6 "	,44HH,7KKq:?""KK	

 	##J/ %!((1z3Q	
  sU3MJ
##J/

:4#@#@A '')H
"))*5

8
 #3'K %%'' 	&&()B*BC'')*  #,N";77>>(##KK>I		001A1A(1KLGZ)<)<\)JK #<" 499%7#%=>>>77>>! **1- 009G))++!!!-Z)9)9!)<=w ?( !!7!>!>z!JK 77>>!A* K LP  	KK98SV 	   91c!fE.  91c!fEsU   -	Q;Q8A.Q=R;SR' RRS! SST TT)zapt-news.servicezesm-cache.servicezua-timer.servicezua-timer.timerzua-auto-attach.pathzua-auto-attach.servicezua-reboot-cmds.servicezubuntu-advantage.service)F)Tr   );r&   r   r   loggingr   r   r   typingr   r   uaclientr   r   r   r   r	   r
   r   r   r   rN   r   r   r   r2   r   r   r   uaclient.defaultsr   r   r   r   uaclient.filesr   r   uaclient.files.state_filesr   r   r   r   r   get_event_loggerrC   	getLoggerreplace_top_level_logger_name__name__r   r   r   r4   rZ   r   r   rA   r   r   r   r    r*   r(   <module>r	     s       	 	  !	 	 	 $ - ( ( (  2  	%%'::8DE	  
,?D\~C" 	
   '+D *. 	,B2
fr*   