
    Ah
                         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mZ d dlZ	d dl
mZ  ej                  e      Zd Zd Zy)    N)Path)datetimetimezone)trigger_sync_hookc                    t        t        j                   d|  d      }|j                         st        j                  d|  d       yt        |d      5 }t        j                  |      }d d d        d   rWt        j                  |d         t        j                  t        j                        k  rt        j                  d	|  d
       y||d   vrt        j                  d|  d|        y|d   |   d   r_t        j                  |d   |   d         t        j                  t        j                        k  rt        j                  d|  d|        yd|d   |   d   vr |dv rt        j                  d|  d|        yd|d   |   d   vr |dv rt        j                  d|  d|        yy# 1 sw Y   NxY w)Nz/conf/users/key_z.jsonzAuthentication file for key z
 not foundFrexpiration_date)tzzSSH-key z is expiredreposzUser with SSH-key z" is not authorized to access repo z" has expired permissions for repo allow)zgit-upload-packz% is not authorized to pull from repo wzgit-receive-packz# is not authorized to push to repo T)r   configGIT_DIRexistsloggererroropenjsonloadr   fromisoformatnowr   utc)key_idrepocommandkey_filefdatas         ./actions.pyis_authorizedr!      s   v~~&&6vheDEH??3F8:FG	h	 yy| 8#9#9$?P:Q#RU]UaUaemeqeqUr#rxx{344= )&1STXSYZ[G}T,-(2H2HgW[I\]nIo2ps{ss  DL  DP  DP  tQ  3Q)&1STXSYZ[
$w-%g..7>S3S)&1VW[V\]^
$w-%g..7>T3T)&1TUYTZ[\/ s   F88Gc                    t         j                  j                  dd      j                         D cg c]  }|j	                  d       }}|st
        j                  d       y |^}}|t        j                  vrt
        j                  d|        y t        |      st
        j                  d       y |^}}t        j                   d| }	 t        | ||      sy 	 	 t        j                  ||g|z   d	
       |dv rt!        ||       y c c}w # t        $ r"}t
        j                  d|        Y d }~y d }~ww xY w# t        $ r+}t
        j                  d| d| d| d|        Y d }~y d }~ww xY w)NSSH_ORIGINAL_COMMAND 'zNo command providedzCommand is not authorized: zNo repo name providedz/repos/z Failed to authorize with error: <   )timeoutr   zCommand  z was executed with error: )osenvirongetsplitstripr   warningr   GIT_COMMANDSlenr   r!   	Exceptionr   
subprocessrunr   )r   argoriginal_commandr   argsrelative_repo_pathabsolute_repo_pathes           r    executer:   0   sy   24**..AWY[2\2b2b2de3		#ee,-%NGdf)))4WI>?t9./ $"NN+73E2FGV%7A Bf!34t;RH,,g'9: A f*  7s;<  f'!,>+?qF`ab`cdee
fs5   D
D ,D= 	D:D55D:=	E1!E,,E1)r2   loggingr   r)   pathlibr   r   r   config_loadr   	sync_hookr   	getLogger__name__r   r!   r:        r    <module>rC      s?       	   '  ' 
		8	$@!rB   