
    d                        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mZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZ d dlmZmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 dZ1dZ2dZ3dZ4dZ5dZ6dZ7 G d de8      Z9 G d de      Z: G d de8      Z; G d de8      Z< G d  d!e8      Z= G d" d#e8      Z> G d$ d%      Z? G d& d'e8      Z@ G d( d)e8      ZAy)*    N)conf)logger)AgentGlobals)set_properties)	add_eventWALAEventOperation)ProtocolErrorResourceGoneError)ustr)ExtensionsGoalStateFactory)VmSettingsParseErrorGoalStateSource)VmSettingsNotSupportedVmSettingsSupportStopped)CertCertListRemoteAccessUserRemoteAccessUsersListExtHandlerPackageExtHandlerPackageList)fileutil)GoalStateHistorySHARED_CONF_FILE_NAME)	CryptUtil)	parse_docfindallfindfindtext	getattribgettextz"http://{0}/machine/?comp=goalstatezCertificates.xmlzCertificates.p7mzCertificates.pemzTransportCert.pemzTransportPrivate.pem   c                   J    e Zd ZdZdZdZdZdZdZdZ	eez  ez  ez  ez  e	z  Z
y)	GoalStatePropertieszJ
    Enum for defining the properties that we fetch in the goal state
                       N)__name__
__module____qualname____doc__
RoleConfig
HostingEnvSharedConfigExtensionsGoalStateCertificatesRemoteAccessInfoAll     L/usr/lib/python3/dist-packages/azurelinuxagent/common/protocol/goal_state.pyr#   r#   3   sI     JJLL
z
!L
03F
F
UXh
hCr6   r#   c                   $     e Zd ZdZd fd	Z xZS )GoalStateInconsistentErrorzX
    Indicates an inconsistency in the goal state (e.g. missing tenant certificate)
    c                 .    t         t        |   ||       y N)superr9   __init__)selfmsginner	__class__s      r7   r=   z#GoalStateInconsistentError.__init__D   s    ($8eDr6   r;   )r*   r+   r,   r-   r=   __classcell__)rA   s   @r7   r9   r9   @   s    E Er6   r9   c                   ,   e Zd Zej                  dfdZed        Zed        Zed        Z	ed        Z
ed        Zed        Zed	        Zed
        Zed        Zd Zd Zd Zed        ZddZd Zd Zd Zd Zd Zed        Zedd       Zd Zy)	GoalStateFc                    	 || _         d| _        d| _        || _        t	        j
                  t        j                        | _        || j                  _        d| _        d| _	        d| _
        d| _        d| _        d| _        t               | _        d| _        d| _        | j%                  |       y# t&        $ r  t(        $ r}t'        d|      d}~ww xY w)aC  
        Fetches the goal state using the given wire client.

        Fetching the goal state involves several HTTP requests to the WireServer and the HostGAPlugin. There is an initial request to WireServer's goalstate API,
        which response includes the incarnation, role instance, container ID, role config, and URIs to the rest of the goal state (ExtensionsConfig, Certificates,
        Remote Access users, etc.). Additional requests are done using those URIs (all of them point to APIs in the WireServer). Additionally, there is a
        request to the HostGAPlugin for the vmSettings, which determines the goal state for extensions when using the Fast Track pipeline.

        To reduce the number of requests, when possible, create a single instance of GoalState and use the update() method to keep it up to date.
        N)silentError fetching goal stater?   r@   )_wire_client_history_extensions_goal_state_goal_state_propertiesr   LoggerDEFAULT_LOGGERrF   _incarnation_role_instance_id_role_config_name_container_id_hosting_env_shared_confEmptyCertificates_certs
_certs_uri_remote_accessupdater	   	Exception)r>   wire_clientgoal_state_propertiesrF   	exceptions        r7   r=   zGoalState.__init__I   s    	R +D DM*.D'*?D' --(=(=>DK!'DKK !%D%)D"%)D"!%D $D $D+-DK"DO"&DKKvK& 	 	R$?yQQ	Rs   B.B1 1CCCc                     | j                   S r;   )rO   r>   s    r7   incarnationzGoalState.incarnationo   s       r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz+ContainerId is not in goal state properties)rL   r#   r.   r	   rR   r_   s    r7   container_idzGoalState.container_ids   s/    **-@-K-KK MNN%%%r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz.RoleInstanceId is not in goal state properties)rL   r#   r.   r	   rP   r_   s    r7   role_instance_idzGoalState.role_instance_idz   s/    **-@-K-KK PQQ)))r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz*RoleConfig is not in goal state properties)rL   r#   r.   r	   rQ   r_   s    r7   role_config_namezGoalState.role_config_name   s/    **-@-K-KK LMM)))r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz3ExtensionsGoalState is not in goal state properties)rL   r#   r1   r	   rK   r_   s    r7   extensions_goal_statezGoalState.extensions_goal_state   s/    **-@-T-TT UVV...r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz,Certificates is not in goal state properties)rL   r#   r2   r	   rV   r_   s    r7   certszGoalState.certs   s-    **-@-M-MM NOO;;r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz2HostingEnvironment is not in goal state properties)rL   r#   r/   r	   rS   r_   s    r7   hosting_envzGoalState.hosting_env   s/    **-@-K-KK TUU$$$r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz,SharedConfig is not in goal state properties)rL   r#   r0   r	   rT   r_   s    r7   shared_confzGoalState.shared_conf   s/    **-@-M-MM NOO$$$r6   c                 j    | j                   t        j                  z  st        d      | j                  S )Nz0RemoteAccessInfo is not in goal state properties)rL   r#   r3   r	   rX   r_   s    r7   remote_accesszGoalState.remote_access   s/    **-@-Q-QQ RSS&&&r6   c                 F    | j                  ddj                  |      |      S )
        This is a convenience method that wraps WireClient.fetch_manifest(), but adds the required 'use_verify_header' parameter and saves
        the manifest to the history folder.
        agentzwaagent.{0})_fetch_manifestformat)r>   family_nameuriss      r7   fetch_agent_manifestzGoalState.fetch_agent_manifest   s%    
 ##G]-A-A+-NPTUUr6   c                 (    | j                  d||      S )rr   	extension)rt   )r>   extension_namerw   s      r7   fetch_extension_manifestz"GoalState.fetch_extension_manifest   s    
 ##KFFr6   c           	      D   	 | j                   j                  t        j                  k(  }| j                  j                  ||      }| j                  j                  ||       t        |      S # t        $ r)}t        dj                  |t        |                  d }~ww xY w)N)use_verify_headerz+Failed to retrieve {0} manifest. Error: {1})rh   sourcer   	FastTrackrI   fetch_manifestrJ   save_manifestExtensionManifestrZ   r	   ru   r   )r>   manifest_typenamerw   is_fast_trackxml_textes          r7   rt   zGoalState._fetch_manifest   s    	n 66==AZAZZM((77P]7^HMM''h7$X.. 	n M T TUbdhijdk lmm	ns   A*A- -	B6$BBc                 .    t         j                  |        y)z
        Updates the container ID and role config name that are send in the headers of HTTP requests to the HostGAPlugin
        N)rD   _fetch_goal_state)r[   s    r7   update_host_plugin_headersz$GoalState.update_host_plugin_headers   s     	##K0r6   c                    || j                   _        	 | j                  d       y# t        $ r\}| j                   j	                  dt        |             | j                  d       | j                   j                  d       Y d}~yd}~ww xY w)zs
        Updates the current GoalState instance fetching values from the WireServer/HostGAPlugin as needed
        Fforce_updatez0Detected an inconsistency in the goal state: {0}TzThe goal state is consistentN)r   rF   _updater9   warnr   info)r>   rF   r   s      r7   rY   zGoalState.update   ss     $	=LLeL,) 	=KKOQUVWQXYLLdL+KK;<<	=s   & 	BABBc                    t         j                   j                         }|r| j                  j                  d       t        j                  | j                        \  }}}|xs || j                  k7  }|rGdj                  |      }| j                  j                  |       t        t        j                  |       d\  }}	| j                  t        j                  z  r%	 t        j                  | j                  |      \  }}	|	r| j                  j                  d       dj                  |j"                  |j$                  |j&                        }| j                  j                  |       t        t        j                  |       |\|j&                  t(        j*                  k(  r?|	r8d}| j                  j                  |       t        t        j                  |       d\  }}	|s|	sy |d	j                  |      nd
j                  ||j$                        }t-        ||      | _        |r| j.                  j1                  |       |	r)| j.                  j3                  |j5                                d }|r| j7                  ||      }|r |	r|j8                  |j8                  kD  r|n|}n|r|}n|}| j:                  #|j8                  | j:                  j8                  k\  r|| _        | j:                  j&                  t(        j<                  k(  r| j?                          y y # t        $ r}
| j!                  ||||
       Y d }
~
y d }
~
ww xY w)Nz$Refreshing goal state and vmSettingszIFetched a new incarnation for the WireServer goal state [incarnation {0}]opmessageNFr    zOFetched new vmSettings [HostGAPlugin correlation ID: {0} eTag: {1} source: {2}]z7The vmSettings originated via Fabric; will ignore them.z{0}z{0}-{1}) datetimeutcnowr   r   rD   r   rI   rO   ru   r   r   rL   r#   r1   _fetch_vm_settingsr   _restore_wire_server_goal_statehostga_plugin_correlation_idetagr   r   Fabricr   rJ   save_goal_statesave_vm_settingsget_redacted_text"_fetch_full_wire_server_goal_statecreated_on_timestamprK   r   _check_certificates)r>   r   	timestampr`   r   xml_docgoal_state_updatedr   vm_settingsvm_settings_updatedr]   tagextensions_configmost_recents                 r7   r   zGoalState._update   s    %%,,.	KKCD)2)D)DTEVEV)W&Xw)M[D<M<M-MahhituGKKW%+55wG+6((&&)<)P)PP3<3O3OPTPaPap|3O3}00
 KKR gnnoz  pX  pX  Ze  Zj  Zj  lw  l~  l~  GKKW%+55wG"{'9'9_=S=S'S"S  )/997K/:,K, "*= ,7+>ell;'IDTDTU`bmbrbrDs(C8MM))(3MM**;+H+H+JK
 ! $ G GU\ ]
 "5)4)I)IL]LrLr)r+  yJK+K%K&&.+2R2RVZVqVq  WG  WG  3G*5D' &&--1J1JJ$$& Ku , 44[(GU^_s   $L 	M(MMc                    | j                   t        j                  z  r'| j                  | j	                  | j                         | j
                  j                  D ]{  }|j                  D ]j  j                  | j                  j                  }t        fd|D              r;dj                  j                  |j                        }t        |       } y )Nc              3   B   K   | ]  }j                   |d    k(    yw)
thumbprintN)certificateThumbprint).0csettingss     r7   	<genexpr>z0GoalState._check_certificates.<locals>.<genexpr>2  s!     cQR899Q|_Lcs   z<Certificate {0} needed by {1} is missing from the goal state)rL   r#   r2   rW   _download_certificatesrh   
extensionsr   protectedSettingsrj   summaryanyru   r   r   r9   )r>   rz   certificatesr   r   s       @r7   r   zGoalState._check_certificates(  s    &&)<)I)IIdooNi''833>> 	>I%.. >--5#zz11cVbcc\ccdl  eC  eC  EN  ES  ES  TG4W==>	>r6   c                 ~   | j                   j                  || j                   j                               }t        || j                        }|j
                  D ]I  }dj                  |      }| j                  j                  |       t        t        j                  |       K t        |j                        dkD  rJ| j                  j                  |j                         t        t        j                  |j                         | j                  j                  t!        j"                  |j
                               |S )NzDownloaded certificate {0}r   r   )rI   fetch_configget_header_for_certr2   r   r   ru   r   r   r   rD   lenwarningsr   rJ   save_certificatesjsondumps)r>   	certs_urir   rj   r   r   s         r7   r   z GoalState._download_certificates6  s    $$11)T=N=N=b=b=deXt{{3 	HA299!<GKKW%+55wG	H u~~"KKU^^,+55u~~N''

5==(ABr6   c                 h   d}| j                   j                  |       t        t        j                  |       t        t        j                  j                         |      | _        | j                  j                  |       | j                  ||      | _        | j                  j                  |j                  k  rxd| j                  _        dj                  | j                  j                  |j                        }| j                   j                  |       t        t        j                  |       y y )NzXThe HGAP stopped supporting vmSettings; will fetched the goal state from the WireServer.r   TzxFetched a Fabric goal state older than the most recent FastTrack goal state; will skip it.
Fabric:    {0}
FastTrack: {1})r   r   r   r   
VmSettingsr   r   r   rJ   r   r   rK   r   r   is_outdatedru   )r>   r`   r   r   !vm_settings_support_stopped_errorr?   s         r7   r   z)GoalState._restore_wire_server_goal_stateD  s    h'22C@():):)A)A)C[Q%%h/&*&M&Mk[b&c#&&;;>_>i>ii6:D''3 O  V  V--BBDeDoDoqCKKS!+66D jr6   c                 <    | j                   j                  ||       y r;   )rJ   save)r>   data	file_names      r7   save_to_historyzGoalState.save_to_historyR  s    4+r6   c                    t         j                  | j                               }d}t        dt              D ]^  }| j                  || j                               }t        |      }t        |d      }t        |d      }|r n2t        j                  d       ` t        dj                  |            t        |d      }t        |d	      }t        |d
      }	t        |	d      }
t        j                  |       | j                  ||
       |||fS )z
        Issues an HTTP request for the goal state (WireServer) and returns a tuple containing the response as text and as an XML Document
        unknownr   IncarnationRoleInstanceg      ?z=Fetched goal state without a RoleInstance [incarnation {inc}])inc	ContainerContainerIdConfiguration
ConfigName)GOAL_STATE_URIru   get_endpointrange_GET_GOAL_STATE_MAX_ATTEMPTSr   
get_headerr   r   r   timesleepr	   r   update_container_idupdate_host_plugin)r[   urir`   _r   r   role_instance	containerrb   role_configrf   s              r7   r   zGoalState._fetch_goal_stateU  s   
 ##K$<$<$>?  q67 
	yA"//[5K5K5MNH)G"7M:K .9MJJsO
	y   _ f fkv f wxx +.		=9=/:#K>((6&&|5EFHg--r6   c                 @   d\  }}t        j                         r)	 	 | j                         j                  |      \  }}||fS ||fS # t        $ r; t
        j                  |        | j                         j                  |      \  }}Y Kw xY w# t        $ r  t        $ r Y ||fS t        $ rp}t        j                  |j                        sKt        t        j                  j                         |j                        j                  |j                           d}~ww xY w)z
        Issues an HTTP request (HostGAPlugin) for the vm settings and returns the response as an ExtensionsGoalState.
        r   r   N)r   get_enable_fast_trackget_host_pluginfetch_vm_settingsr
   rD   r   r   r   r   r   
tag_existsr   r   r   r   vm_settings_text)r[   r   r   r   r]   s        r7   r   zGoalState._fetch_vm_settingsx  s/   
 ,9((%%'B7B7R7R7T7f7f  uA7f  8B4K!4  ///{/// ) B88E7B7R7R7T7f7f  uA7f  8B4K!4B
 , )  /// ( '229>>B$X%6%6%=%=%?Paabkb|b|}	s7   #A ABB 
BB D%D-A+DDc                 	   	 | j                   j                  d       dj                  |      }| j                   j                  |       t        t        j
                  |       d}d}d}t        j                  | j                  z  rHt        |d      }t        |d      }t        |d      }t        |d      }t        |d	      }	t        |	d
      }t        |d      }
t        j                  | j                  z  r|
t        j                  |      }n~| j                  j                  |
| j                  j!                               }t        j"                  ||| j                        }| j$                  j'                  |j)                                d}t        j*                  | j                  z  rft        |d      }| j                  j                  || j                  j!                               }t+        |      }| j$                  j-                  |       d}t        j.                  | j                  z  rt        |d      }| j                  j                  || j                  j!                               }t/        |      }| j$                  j1                  |       t2        j4                  j7                  t9        j:                         t<              }	 t?        j@                  ||       tG               }t        |d      }t        jH                  | j                  z  r|| jK                  |      }d}t        jL                  | j                  z  rht        	d      }|Z| j                  j                  || j                  jO                               }tQ        |      }| j$                  jS                  |       || _*        || _+        || _,        || _-        || _.        || _/        || _0        || _1        || _2        |d}| j                   j                  |       t        t        j
                  |       S # tB        $ r0}t        jD                  dj                  ||             Y d}~zd}~ww xY w# tB        $ r7}| j                   jE                  dtg        |             ti        d|      d}~ww xY w# d}| j                   j                  |       t        t        j
                  |       w xY w)z
        Issues HTTP requests (to the WireServer) for each of the URIs in the goal state (ExtensionsConfig, Certificate, Remote Access users, etc)
        and populates the corresponding properties.

        Returns the value of ExtensionsConfig.
        r   z>Fetching full goal state from the WireServer [incarnation {0}]r   Nr   
InstanceIdr   r   r   r   ExtensionsConfigHostingEnvironmentConfigr0   zFailed to save {0}: {1}r2   r3   zFetch goal state completedz#Fetching the goal state failed: {0}rG   rH   )5r   r   ru   r   r   rD   r#   r.   rL   r   r   r1   r   create_emptyrI   r   r   create_from_extensions_configrJ   save_extensions_configr   r/   save_hosting_envr0   save_shared_confospathjoinr   get_lib_dirr   r   
write_filerZ   r   rU   r2   r   r3   r   RemoteAccesssave_remote_accessrO   rP   rQ   rR   rS   rT   rV   rW   rX   r   r	   )r>   r`   r   r   rd   rf   rb   r   r   r   extensions_config_urir   r   rl   hosting_env_urishared_configshared_conf_urishared_config_filer   rj   r   rp   remote_access_urir]   s                           r7   r   z,GoalState._fetch_full_wire_server_goal_state  s)   L	HKKR V]]^ijGKKW%+55wG##L"--0K0KK $Wn =#+M<#H "=/B#+K#F  +6	'	=A$,W6H$I!';;d>Y>YY^s^{$>$K$KK$X!,,99:OQUQbQbQmQmQop$>$\$\]hjrtx  uF  uF  %G!445F5X5X5Z[K"--0K0KK"*74N"O,,99/4K\K\KgKgKij(2..x8 M"//$2M2MM"*7N"C,,99/4K\K\KgKgKij ,X 6..x8%'WW\\$2B2B2DF[%\"T''(:HE &'E .9I#0043N3NNT]Ti33I> M"33d6Q6QQ$,Y8J$K!$0#00==>OQUQbQbQvQvQxyH$0$:MMM44X> +D%5D"%5D"!-D +D -DDK'DO"/D$ 3GKKW%+55wGE ! TKK 9 @ @PQ RSST8  	RKKBDOT$?yQQ	R 3GKKW%+55wGsO   KQ' P+ %DQ' +	Q$4%QQ' Q$$Q' '	R'02R""R''R* *:S$N)F)r*   r+   r,   r#   r4   r=   propertyr`   rb   rd   rf   rh   rj   rl   rn   rp   rx   r|   rt   staticmethodr   rY   r   r   r   r   r   r   r   r   r5   r6   r7   rD   rD   H   s@   :M:Q:QZ_ $RL ! ! & & * * * * / /   % % % % ' 'VGn 1 1=O'b>E,  .  .D 0 06SHr6   rD   c                       e Zd Zd Zy)r/   c                     || _         t        |      }t        |d      }t        |d      | _        t        |d      }t        |d      | _        t        |d      }t        |d      | _        y )Nr   instanceRoler   
Deployment)r   r   r   r   vm_name	role_namedeployment_name)r>   r   r   r`   role
deployments         r7   r=   zHostingEnv.__init__  sb     H%7M2 j9GV$"40'<0
(V<r6   Nr*   r+   r,   r=   r5   r6   r7   r/   r/     s    =r6   r/   c                       e Zd Zd Zy)r0   c                     || _         y r;   )r   r>   r   s     r7   r=   zSharedConfig.__init__  s	     r6   Nr  r5   r6   r7   r0   r0     s    !r6   r0   c                   "    e Zd Zd Zed        Zy)r2   c           	      V	   t               | _        g | _        g | _        t        j
                  j                  t        j                         t              }t        j                  ||       t        |      }t        |d      }|y t        |d      }|rC|dk7  r>dj                  |      }|j                  |       t!        t"        j$                  |       y t'        t        j(                               }t        j
                  j                  t        j                         t*              }	dj                  |	|	|      }
t        j                  |	|
       t        j
                  j                  t        j                         t,              }t        j
                  j                  t        j                         t.              }t        j
                  j                  t        j                         t0              }|j3                  |	|||       g }d}d}i }i }d}g }t5        |      5 }|j7                         D ]\  }|j9                  |       t;        j<                  d	|      rd
}.t;        j<                  d|      rd
}Gt;        j<                  d|      r7t>        jA                  |d|      }|jC                  |      }|||<   g }|dz  }d}t;        j<                  d|      st>        jA                  |d|      }|jE                  |      }|jG                  |      }|||<   dj                  |      }|j9                  d |d       t	        jH                  |t        j
                  j                  t        j                         |             g }|dz  }d}_ 	 d d d        |D ]  }||   }|r]||   }dj                  |      }t	        jH                  |t        j
                  j                  t        j                         |             g| j                  j9                  d        |jK                         D ]'  \  }}||v }| j                  j9                  ||d       ) |D ]>  }tM               }tO        d||       | j                  jP                  j9                  |       @ y # 1 sw Y   xY w)NDataFormatPkcs7BlobWithPfxContentsz9The Format is not Pkcs7BlobWithPfxContents. Format is {0}r   zMIME-Version:1.0
Content-Disposition: attachment; filename="{0}"
Content-Type: application/x-pkcs7-mime; name="{1}"
Content-Transfer-Encoding: base64

{2}Fr   z[-]+BEGIN.*KEY[-]+Tz[-]+BEGIN.*CERTIFICATE[-]+z[-]+END.*KEY[-]+prvr$   z[-]+END.*CERTIFICATE[-]+crtz{0}.crt)r   r   z{0}.prvz2Found NO matching cert/thumbprint for private key!)r   hasPrivateKeyrj   ))r   	cert_listr   r   r   r   r   r   r   CERTS_FILE_NAMEr   r   r   r   ru   r   r   r   rD   r   get_openssl_cmdP7M_FILE_NAMETRANSPORT_PRV_FILE_NAMETRANSPORT_CERT_FILE_NAMEPEM_FILE_NAMEdecrypt_p7mopen	readlinesappendrematchr2   _write_to_tmp_fileget_pubkey_from_prvget_pubkey_from_crtget_thumbprint_from_crtrenameitemsr   r   r   ) r>   r   	my_logger
local_filer   r   certificate_formatr   	cryptutilp7m_filep7mtrans_prv_filetrans_cert_filepem_filebuf	begin_crt	begin_prvprvsthumbprintsindexv1_cert_listpemlinetmp_filepubr   r  pubkeyr  has_private_keyv1_certcerts                                    r7   r=   zCertificates.__init__  s   ! WW\\$"2"2"4oF
J1 H%(< &gx8"48R"RQXXYklGNN7#+55wGd2245	77<< 0 0 2MB
 fXx6 	 	Hc*d&6&6&8:QR'',,t'7'7'9;ST77<< 0 0 2MBhR 		(^ 	&s &

4 88148 $IXX;TB $IXX148+>>ueSQH#77AC (DICQJE %IXX94@+>>ueSQH#77AC!*!B!B8!LJ'1K$#**:6C '' $&0)  IIhT5E5E5G(MNCQJE %I7&	&>  		[F$V,J<&&z2		(BGGLL1A1A1CS$IJ $$%YZ		[ #."3"3"5 	^FJ$nOLLzO \]	^ $ 	5G6D7D'2NN''..t4	5]	& 	&s    B;RB5RR(c                     t         j                  j                  t        j                         dj                  | |            }t        j                  |dj                  |             |S )Nz{0}.{1}r   )r   r   r   r   r   ru   r   r   )r9  suffixr4  r   s       r7   r%  zCertificates._write_to_tmp_file_  sJ    GGLL!1!1!3Y5E5EeV5TU	Irwws|4r6   N)r*   r+   r,   r=   r  r%  r5   r6   r7   r2   r2     s    a5F  r6   r2   c                       e Zd Zd Zy)rU   c                 >    t               | _        g | _        g | _        y r;   )r   r  r   r   r_   s    r7   r=   zEmptyCertificates.__init__f  s    !r6   Nr  r5   r6   r7   rU   rU   e  s    r6   rU   c                   &    e Zd ZdZd Zed        Zy)r   z;
    Object containing information about user accounts
    c                    || _         d | _        d | _        t               | _        | j                   t        | j                         dk(  ry t        | j                         }t        |d      | _        t        |d      | _        t        |d      }t        |d      }|D ]<  }t        j                  |      }| j                  j                  j                  |       > y )Nr   Versionr   UsersUser)r   versionr`   r   	user_listr   r   r   r   r   r   _parse_userusersr"  )r>   r   r   user_collectionrO  userremote_access_users          r7   r=   zRemoteAccess.__init__|  s     .0== C$6!$;DMM*3#G];w00 	<D!-!9!9$!?NN  ''(:;	<r6   c                 h    t        | d      }t        | d      }t        | d      }t        |||      }|S )NNamePassword
Expiration)r   r   )rQ  r   encrypted_password
expirationrR  s        r7   rN  zRemoteAccess._parse_user  s=    f%%dJ7dL1
-d4F
S!!r6   N)r*   r+   r,   r-   r=   r  rN  r5   r6   r7   r   r   k  s      <& " "r6   r   c                       e Zd Zd Zd Zd Zy)r   c                     |t        d      t        j                  d       t               | _        | j                  |       y )NzExtensionManifest is NonezLoad ExtensionManifest.xml)
ValueErrorr   verboser   pkg_list_parser  s     r7   r=   zExtensionManifest.__init__  s7    89934-/Hr6   c                     t        |      }| j                  t        t        |d      d      d       | j                  t        t        |d      d      d       y )NPluginsPluginFInternalPluginsT)r   _handle_packagesr   r   )r>   r   r   s      r7   r^  zExtensionManifest._parse  s`    H%gd7+4'6&.0 $	% 	gd7+<'>&.0 #	$r6   c                    |D ]  }t        |d      }t        |d      }|d}|j                         dk(  }t        |d      }t        |d      }|D cg c]  }t	        |       }}t               }	||	_        ||	_        |D ]  }
|	j                  j                  |
        ||	_
        | j                  j                  j                  |	        y c c}w )NrI  DisallowMajorVersionUpgrader   trueUrisUri)r   lowerr   r   r    r   rL  disallow_major_upgraderw   r"  
isinternalr]  versions)r>   packagesrk  packagerL  rj  rw   uri_listxpkgr   s              r7   rc  z"ExtensionManifest._handle_packages  s     	/Gw	2G%-g.K&M"%-)+&%;%A%A%Cv%M"(DtU+H,45q
5H5#%C!CK)?C& %$% (CNMM""))#.'	/ 6s   CN)r*   r+   r,   r=   r^  rc  r5   r6   r7   r   r     s    	$/r6   r   )Br   r   r#  r   r   azurelinuxagent.commonr   r   #azurelinuxagent.common.AgentGlobalsr   #azurelinuxagent.common.datacontractr   azurelinuxagent.common.eventr   r    azurelinuxagent.common.exceptionr	   r
   azurelinuxagent.common.futurer   =azurelinuxagent.common.protocol.extensions_goal_state_factoryr   5azurelinuxagent.common.protocol.extensions_goal_stater   r   *azurelinuxagent.common.protocol.hostpluginr   r   'azurelinuxagent.common.protocol.restapir   r   r   r   r   r   azurelinuxagent.common.utilsr   $azurelinuxagent.common.utils.archiver   r   &azurelinuxagent.common.utils.cryptutilr   %azurelinuxagent.common.utils.textutilr   r   r   r   r   r    r   r  r  r  r  r  r   objectr#   r9   rD   r/   r0   r2   rU   r   r   r5   r6   r7   <module>r     s   $  	 	   ' ) < > F M . d g g V  V 1 X < h h 6$"". 0   
i& 
iE E_H _HD	= 	=!6 !
h6 hT *"6 *"Z'/ '/r6   