+
    g#                         ^ RI 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 ^ RIHt Rs ! R R4      tRR	 R
 lltR# )    N)datetime)AnyDictOptional)defaults
exceptionssystemutil)PublicMachineTokenData)UAFilec                     a  ] tR t^t o ]P
                  R3V 3R lR lltV 3R lR ltR tV 3R lR lt	]
R	 4       t]
R
 4       t]
V 3R lR l4       tR t]
V 3R lR l4       tR#V 3R lR llt]R#V 3R lR ll4       t]
V 3R lR l4       t]
R 4       t]
V 3R lR l4       t]
V 3R lR l4       t]
V 3R lR l4       t]
V 3R lR l4       t]
R 4       t]
R  4       t]
R! 4       tR"tV tR# )$MachineTokenFileNc                6   < V ^8  d   QhRS[ RS[S[ ,          /# )   	directorymachine_token_overlay_path)strr   )format__classdict__s   ">/usr/lib/python3/dist-packages/uaclient/files/machine_token.py__annotate__MachineTokenFile.__annotate__   s#     . .. %-SM.    c                    \         P                  p\        W1R ,           \         P                  ,           4      V n        \        W1R4      V n        W n        RV n        RV n        RV n	        R# )/FN)
r   MACHINE_TOKEN_FILEr   PRIVATE_SUBDIRprivate_filepublic_filer   _machine_token_entitlements_contract_expiry_datetime)selfr   r   	file_names   &&& r   __init__MachineTokenFile.__init__   s]    
 //	"3)@)@@
 ")>*D'"!)-&r   c                    < V ^8  d   QhRS[ /# )r   private_content)dict)r   r   s   "r   r   r      s     0 0T 0r   c                   \         P                  ! 4       '       d   \        P                  ! V\         P                  R7      pV P
                  P                  V4       \        P                  ! V4      P                  RR7      p\        P                  ! V\         P                  R7      pV P                  P                  V4       RV n        RV n        RV n        R# \        P                  ! 4       h)z8Update the machine_token file for both pub/private filesclsF)	keep_noneN)r
   we_are_currently_rootjsondumpsDatetimeAwareJSONEncoderr   writer   	from_dictto_dictr   r    r!   r"   r   NonRootUserError)r#   r(   private_content_strpublic_contentpublic_content_strs   &&   r   r2   MachineTokenFile.write   s    %%''"&**T%B%B# ##$78 4==gg&  "&D$A$A" ""#56"&D!%D-1D*--//r   c                    \         P                  ! 4       '       dL   V P                  P                  4        V P                  P                  4        RV n        RV n        RV n        R# \        P                  ! 4       h)z!Delete both pub and private filesN)
r
   r.   r   deleter   r    r!   r"   r   r5   r#   s   &r   r;   MachineTokenFile.delete4   s\    %%''##%$$&"&D!%D-1D*--//r   c                0   < V ^8  d   QhRS[ S[,          /# r   return)r   r)   )r   r   s   "r   r   r   @   s      htn r   c                   \         P                  ! 4       '       d   V P                  pMV P                  pVP	                  4       pV'       g   R #  \
        P                  ! V\         P                  R7      pV#   \         d     T# i ; i)Nr+   )	r
   r.   r   r   readr/   loadsDatetimeAwareJSONDecoder	Exception)r#   file_handlercontents   &  r   rB   MachineTokenFile.read@   sv    %%'',,L++L##%	jjd.K.KLG   		s   &A8 8BBc                    \         P                  ! 4       '       d5   V P                  P                  ;'       d    V P                  P                  # V P                  P                  # N)r
   r.   r   
is_presentr   r<   s   &r   rK   MachineTokenFile.is_presentN   sI    %%''##..OO43D3D3O3OO##...r   c                   V P                   '       gl   V P                  4       pV'       dN   V P                  '       d<   V P                  V P                  4      pV'       d   \        P
                  ! VVR7       Wn         V P                   # )zAReturn the machine-token if cached in the machine token response.)	base_dictoverlay_dict)r    rB   r   parse_machine_token_overlayr
   depth_first_merge_overlay_dict)r#   rG   machine_token_overlays   &  r   machine_tokenMachineTokenFile.machine_tokenU   sp     """iikG4:::(,(H(H33)% )77")%: #*"""r   c                0   < V ^8  d   QhRS[ S[,          /# r?   r   r   )r   r   s   "r   r   r   h   s      x} r   c                    V P                   '       d<   V P                   P                  R / 4      P                  R/ 4      P                  R4      # R# )machineTokenInfocontractInfonameNrS   getr<   s   &r   contract_nameMachineTokenFile.contract_nameg   sD    ""&&'92>^R(V r   c                z    \         P                  ! V4      p\        P                  ! V\        P
                  R 7      # )r+   )r	   	load_filer/   rC   r
   rD   )r#   r   machine_token_overlay_contents   && r   rP   ,MachineTokenFile.parse_machine_token_overlayr   s5    (.(8(8&)
% zz)--
 	
r   c                6   < V ^8  d   QhRS[ S[S[3,          /# r?   )r   r   r   )r   r   s   "r   r   r   |   s      c3h r   c                p    \        V P                  4      '       d   V P                  R ,          R,          # / # )rX   accountInfoboolrS   r<   s   &r   accountMachineTokenFile.account{   s/    ""##%%&89-HH	r   c                0   < V ^8  d   QhRS[ S[,          /# )r   seriesrV   )r   r   s   "r   r   r      s     	" 	"8C= 	"r   c                    V P                   '       d   V P                   # V P                  '       g   / # V P                  V P                  V4      V n         V P                   # )z9Return configured entitlements keyed by entitlement named)r!   rS   get_entitlements_from_token)r#   rk   s   &&r   entitlementsMachineTokenFile.entitlements   sW    %%%!!!I!==
 !!!r   c                L   < V ^8  d   QhRS[ S[S[3,          RS[S[,          /# )r   rS   rk   )r   r   r   r   )r   r   s   "r   r   r      s)     # #CH~#/7}#r   c                   ^ RI Hp V '       g   / # / pV P                  R/ 4      P                  R4      pV'       g   / # \        R V P                  R. 4       4       4      p\        R VP                  R. 4       4       4      pVP	                  4        F(  w  rxRV/p	Wu9   d   VV,          V	R	&   V! WR
7       WV&   K*  	  V# )zuReturn a dictionary of entitlements keyed by entitlement name.

Return an empty dict if no entitlements are present.
)apply_contract_overridesrX   rY   c              3   f   "   T F'  pVP                  R 4      VP                  R4      3x  K)  	  R# 5i)typetokenNr\   .0es   & r   	<genexpr>?MachineTokenFile.get_entitlements_from_token.<locals>.<genexpr>   s,      
< UU6]AEE'N+<s   /1resourceTokensc              3   H   "   T F  pVP                  R 4      V3x  K  	  R# 5i)rt   Nrv   rw   s   & r   rz   r{      s$      
A UU6]AAs    "resourceEntitlementsentitlementresourceToken)rk   )uaclient.contractrr   r\   r)   items)
rS   rk   rr   rn   rY   tokens_by_nameent_by_nameentitlement_name	ent_valueentitlement_cfgs
   &&        r   rm   ,MachineTokenFile.get_entitlements_from_token   s     	?I$(();R@DD
 I 
"&&'7<
 
  
!%%&<bA
 
 ,7+<+<+>',i8O13A$40 %_D-<)* ,? r   c                0   < V ^8  d   QhRS[ S[,          /# r?   )r   r   )r   r   s   "r   r   r      s     	. 	.(8*< 	.r   c                    V P                   '       gT   V P                  '       dB   V P                  P                  R/ 4      P                  R/ 4      P                  RR4      V n         V P                   # )z6Return a datetime of the attached contract expiration.rX   rY   effectiveToN)r"   is_attachedrS   r\   r<   s   &r   contract_expiry_datetime)MachineTokenFile.contract_expiry_datetime   s`     ---$2B2B2B""&&'92>^R(]D) * ---r   c                ,    \        V P                  4      # )z<Report whether this machine configuration is attached to UA.rf   r<   s   &r   r   MachineTokenFile.is_attached   s     D&&''r   c                0   < V ^8  d   QhRS[ S[,          /# r?   )r   int)r   r   s   "r   r   r      s     
 
# 
r   c                    V P                   f   R# V P                   P                  4       \        P                  ! 4       P                  4       ,
          pVP                  # )zReport num days until contract expiration based on effectiveTo

:return: A positive int representing the number of days the attached
    contract remains in effect. Return a negative int for the number
    of days beyond contract's effectiveTo date.
N)r   dater   utcnowdays)r#   deltas   & r   contract_remaining_days(MachineTokenFile.contract_remaining_days   sF     ((0--224x7H7M7M7OOzzr   c                   < V ^8  d   QhRR/# r   r@   zOptional[str] )r   r   s   "r   r   r      s       r   c                    V P                   '       d,   V P                   P                  R / 4      P                  R4      # R# )activityInfoactivityTokenNr[   r<   s   &r   activity_tokenMachineTokenFile.activity_token   s<    %%))."=AA  r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s      _ r   c                    V P                   '       d,   V P                   P                  R / 4      P                  R4      # R# )r   
activityIDNr[   r<   s   &r   activity_idMachineTokenFile.activity_id   s5    %%))."=AA,OOr   c                   < V ^8  d   QhRR/# )r   r@   zOptional[int]r   )r   r   s   "r   r   r      s       r   c                    V P                   '       d,   V P                   P                  R / 4      P                  R4      # R# )r   activityPingIntervalNr[   r<   s   &r   activity_ping_interval'MachineTokenFile.activity_ping_interval   s<    %%))."=AA&  r   c                    V P                   '       d<   V P                   P                  R / 4      P                  R/ 4      P                  R4      # R# )rX   rY   idNr[   r<   s   &r   contract_idMachineTokenFile.contract_id   sD    ""&&'92>^R(T
 r   c                b    V P                   '       d   V P                   P                  R . 4      # R# )r|   Nr[   r<   s   &r   resource_tokens MachineTokenFile.resource_tokens   s+    %%))*:B??r   c                    V P                  4       P                  R / 4      P                  R/ 4      P                  R/ 4      P                  RR4      pV# )supportr   affordances
onlySeriesN)rn   r\   )r#   only_seriess   & r   r   MachineTokenFile.only_series   sM     SBS#S#St$ 	 r   )r"   r!   r    r   r   r   rJ   )__name__
__module____qualname____firstlineno__r   DEFAULT_DATA_DIRr%   r2   r;   rB   propertyrK   rS   r]   rP   rh   rn   staticmethodrm   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__)r   s   @r   r   r      sc     "2248. .0 00
0  / / # #"  
  
	" 	" # # #J 	. 	. ( ( 
 
    
        r   r   c                $    V ^8  d   QhR\         /# r?   )r   )r   s   "r   r   r     s      (8 r   c                     ^ RI Hp \        '       g@   V '       g   V! 4       p \        V P                  V P
                  P                  R4      R7      s\        # )r   )UAConfigrR   )r   r   )uaclient.configr   _machine_token_filer   data_dirfeaturesr\   )cfgr   s   & r   get_machine_token_filer     sF    ( *C.ll'*||'7'7'(
 r   rJ   )r/   r   typingr   r   r   uaclientr   r   r	   r
   uaclient.contract_data_typesr   uaclient.files.filesr   r   r   r   r   r   r   <module>r      s:      & & 7 7 ? ' t tn r   