
    "Қh                        d Z ddlZddlZddlmZmZmZ ddlmZ  ede	d          Z
dZd	Ze
                    d
dg          e
                    ddg          dd                        Ze
                    ddg          d             Ze
                    ddg          d             Ze
                    ddg          d             ZdS )z1
App Runner specific functionality and endpoints
    N)	Blueprintjsonifyrequest)	ZTSClient
app_runnerz/api/app_runner)
url_prefixz/var/run/athenz/service.key.pemz /var/run/athenz/service.cert.pemz	/env_varsGET)methodsz/env_vars/<key>c                    	 | rNt           j                            |           }|t          d| |dd          S t          dd|  dd          d	fS i }t           j                                        D ]
\  }}|||<   t          d|t          |          d
          S # t          $ r.}t          ddt          |           d          dfcY d}~S d}~ww xY w)z
    Get environment variables from the App Runner environment.
    If key is provided, returns the value for that specific key.
    If no key is provided, returns all environment variables.
    Nsuccess)keyvalue)statusdataerrorzEnvironment variable "z" not found)r   message  )r   r   countz2Failed to get App Runner environment information:   )osenvirongetr   itemslen	Exceptionstr)r   r   env_varskves         H/Users/user/workspace/sujinbaek/cqa-test-app/products/paas/app_runner.pyget_env_varsr"      sM    
 	JNN3''E (#2N2NOO   ")#LC#L#L#L     J$$&& 	 	DAqHQKK)XHVVWWW 	
 	
 	
%\TWXYTZTZ\\   
 	
 	
 	
 	
 	
 	
	
s)   7B B A
B 
C'#C
CCz/get_access_tokenc                     t           j                            dd          } | st          ddd          dfS 	 t	          j        t          t                    }|                    |           }t          d|j	        d	          d
fS # t          $ r.}t          ddt          |           d          dfcY d}~S d}~ww xY w)zI
    Retrieve the IAM access token for the specified product domain.
    product_domain FzNo product domain providedr   r     )domainT)r   access_token   z!Failed to retrieve access token: r   N)r   argsr   r   r   	with_cert_athenz_cert_path_athenz_key_pathget_access_tokenr)   r   r   )r$   clientresr    s       r!   r/   r/   ;   s   
 \%%&6;;N Y55QRRSSUXXX
$%68HII %%^%<<49IJJKKSPP 	
 	
 	
$K3q66KK   
 	
 	
 	
 	
 	
 	
	
s   AB 
B>#B93B>9B>z/send_requestc                  j   t           j                            dd          } | st          ddd          dfS 	 t	          j        | d          }|                                 t          d	d
|  dd          S # t          j        $ r+}t          dt          |          d          dfcY d}~S d}~ww xY w)zQ
    Send an HTTP GET request to the specified host and return the response.
    hostr%   FzNo host URL providedr&   r'      )timeoutTzConnected to z successfully.r   N)r   r+   r   r   requestsraise_for_statusRequestExceptionr   )r3   responser    s      r!   send_requestr:   X   s    
 <FB''D S55KLLMMsRRC<a000!!###)M)M)M)MNN
 
 	
 $ C C C5SVV<<==sBBBBBBBCs   ?A8 8B2 B-'B2-B2z/validate_volumePOSTc                     	 t           j        } |                     d          }|                     d          }|r|st          ddd          dfS t          j                            ||          }t          j                            |          r	 t          |dd	          5 }|	                                }d
d
d
           n# 1 swxY w Y   t          dd| d|d          dfS # t          $ r.}t          ddt          |           d          dfcY d
}~S d
}~ww xY wt          dd| dd          dfS # t          $ r+}t          dt          |          d          dfcY d
}~S d
}~ww xY w)z
    Validate if a file exists in the specified path for a given key.
    If the file exists, read and return its contents.
    r   pathFzMissing required parametersr&   r'   rzutf-8)encodingNTzFile exists at path 'z'.)r   r   contentr*   z#File exists but could not be read: r   zFile does not exist at path 'r   )r   jsonr   r   r   r=   joinexistsopenreadr   r   )r   r   r=   	file_pathfiler@   r    s          r!   validate_volumerH   k   sF   1C|hhuooxx 	$ 	E6STTUU  GLLs++	 7>>)$$ 	)S7;;; *t"iikkG* * * * * * * * * * * * * * * '+'Ly'L'L'L'.   	 	  	 	 	','USQRVV'U'U         	 $LyLLL   
 	
  C C C5SVV<<==sBBBBBBBCsr   AD: ?D: C' "C7C' CC' 
CC' '
D1#DDD: DD: :
E/ E*$E/*E/)N)__doc__r   r6   flaskr   r   r   yj.athenz.clientr   __name__bpr.   r-   router"   r/   r:   rH        r!   <module>rQ      sh    
			  - - - - - - - - - - & & & & & & Y|X2CDDD4 6  +w''
eW--&
 &
 &
 .- ('&
R 
w//
 
 0/
8 /E7++C C ,+C$ 
vh//6C 6C 0/6C 6C 6CrP   