
    7jS                    B   d Z ddlmZ ddlZddlmZmZ ddlmZ 	  ee	      j                  j                  dz  Zej                         r!ej                  d      j                         Znd	Zd
ZdZdZdZdZddZe G d d             ZddZddZy# e$ r d	ZY /w xY w)a~  Configuration loading and path management for the WolfPanel Agent.

Every filesystem location and runtime setting lives here so the rest of the
codebase never hard-codes a path. Production defaults follow the Linux layout
documented in the README. For local development (including non-Linux machines)
set WOLFPANEL_DEV_HOME to rebase every directory under a single writable folder.
    )annotationsN)	dataclassfield)PathVERSIONutf-8encodingz	0.1.0-dev)
pending_installpairing_waiting
registeredonlineofflineupdatingrollbackdegradedrevokeduninstalledz/etc/wolfpanelz/opt/wolfpanelz/var/lib/wolfpanelz/var/log/wolfpanelc            	        t         j                  j                  d      } | rt        |       }|dz  |dz  |dz  |dz  dS t        t         j                  j                  dt                    t        t         j                  j                  dt
                    t        t         j                  j                  d	t                    t        t         j                  j                  d
t                    dS )z;Resolve the four base directories, honouring dev overrides.WOLFPANEL_DEV_HOMEetcoptvarlog)r   r   r   r   WOLFPANEL_ETC_DIRWOLFPANEL_OPT_DIRWOLFPANEL_VAR_DIRWOLFPANEL_LOG_DIR)osenvirongetr   _DEFAULT_ETC_DEFAULT_OPT_DEFAULT_VAR_DEFAULT_LOG)dev_homebases     @/var/www/downloads.wolfpanel.net/public_html/agent/src/config.py_resolve_dirsr)   2   s    zz~~23HH~%<%<%<%<	
 	
 BJJNN#6EFBJJNN#6EFBJJNN#6EFBJJNN#6EF	     c                     e Zd ZU dZded<   ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Z	ded<    ed      Z
ded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Zded<    ed      Zded <   d$d!Zed%d"       Zy#)&Configz3Resolved agent configuration and all derived paths.strapi_urlrelease_channel	server_idagent_versionintheartbeat_intervalboolapi_mockr   etc_diropt_dirvar_dirlog_dirF)init	conf_filesecrets_diragent_token_fileagent_key_file	spool_dirjobs_dirdiscovery_dir	cache_dir	agent_logjobs_log
update_log )defaultstatus
last_errorc                   | j                   dz  | _        | j                   dz  | _        | j                  dz  | _        | j                  dz  | _        | j
                  dz  | _        | j
                  dz  | _        | j
                  dz  | _        | j
                  dz  | _	        | j                  d	z  | _        | j                  d
z  | _        | j                  dz  | _        y )N
agent.confsecretsagent.tokenz	agent.keyspooljobs	discoverycachez	agent.logzjobs.logz
update.log)r6   r;   r<   r=   r>   r8   r?   r@   rA   rB   r9   rC   rD   rE   selfs    r(   __post_init__zConfig.__post_init__e   s    4<<)3 $ 0 0= @"..</v-!\\K7/3z1,,5r*   c                "    d| j                    dS )z<URL of the channel's latest-version manifest (update check).z&https://downloads.wolfpanel.net/agent/z/latest.json)r/   rR   s    r(   manifest_urlzConfig.manifest_urlt   s     88L8L7M\ZZr*   N)returnNone)rW   r-   )__name__
__module____qualname____doc____annotations__r   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rH   rI   rT   propertyrV    r*   r(   r,   r,   E   s   =LNNMMMM 'It'5)K)".d. e,ND,'It'&Hd&U+M4+'It''It'&Hd&%(J(#FC#B'J'6 [ [r*   r,   c                p   i }| j                         s|S | j                  d      j                         D ]~  }|j                         }|r|j	                  d      sd|vr+|j                  d      \  }}}|j                         j                  d      j                  d      ||j                         <    |S )zDParse a simple KEY=VALUE env-style file. Missing file -> empty dict.r   r	   #="')is_file	read_text
splitlinesstrip
startswith	partition)pathvaluesrawlinekey_values          r(   _parse_conf_filerr   z   s    F<<>~~w~/::< Byy{ts+s$s+Q#kkm11#6<<SAsyy{B Mr*   c                   
 t               } t        | d   dz        
d
fd} |dd      } |dd      j                         dv } |d	d
      }| d   }|dz  dz  }|j                         } |d|r|rdnd      } |dd
      }	t	        | |dd      | |dt
              t         |dd            || d   | d   | d   | d   ||	      S )zBuild a Config from (in priority order) env vars, then the conf file.

    Environment variables always win so operators and tests can override the
    on-disk configuration without editing files.
    r   rK   c                d    t         j                  j                  | j                  | |            S )N)r   r    r!   )ro   rG   file_valuess     r(   r!   zload_config.<locals>.get   s#    zz~~c;??3#@AAr*   WOLFPANEL_API_URLzhttps://api.wolfpanel.netWOLFPANEL_API_MOCK0)1trueyesWOLFPANEL_SERVER_IDrF   rL   rM   WOLFPANEL_STATUSr   r   WOLFPANEL_LAST_ERRORWOLFPANEL_RELEASE_CHANNELstableWOLFPANEL_AGENT_VERSIONWOLFPANEL_HEARTBEAT_INTERVAL60r   r   r   )r.   r/   r0   r1   r3   r5   r6   r7   r8   r9   rH   rI   )ro   r-   rG   r-   rW   r-   )r)   rr   lowerre   r,   AGENT_VERSIONr2   )dirsr!   r.   r5   r0   r6   
token_file	has_tokenrH   rI   ru   s             @r(   load_configr      s    ?D"4;#=>KB %'BCG'-3359MMH)2.I5kG9$}4J""$I#iI\TefF+R0J7B3]Cs#A4HIUUUU r*   )rW   zdict[str, Path])rk   r   rW   zdict[str, str])rW   r,   )r\   
__future__r   r   dataclassesr   r   pathlibr   __file__parent_version_filere   rf   rh   r   	ExceptionLIFECYCLE_STATESr"   r#   r$   r%   r)   r,   rr   r   r_   r*   r(   <module>r      s    # 	 (  N))009<M%///AGGI#   ##& 1[ 1[ 1[h%c   M s   AB BB