
    yjg                        d dl Z d dlmZmZmZmZm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 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  e j        e           Z! eddg          Z"e"#                    dej$                   edd           edd           e e                      efdede%dej&        dededej$        fd            Z'e"(                    deej$                            edd           e e                      efde%dededeej$                 fd            Z)e"*                    ddd            edd           edd!           e e                      efde%d"e%dededdf
d#            Z+e"(                    d$           edd           e e                      fde%deddfd%            Z,dS )&    N)	APIRouterBodyDependsPathResponse)Page)	apaginate)AsyncSession)schemas)settingswebhook)db)AuthenticationExceptionConflictException)	JWTParamsrequire_auth)	TestEventpublish_webhook_eventz#/workspaces/{workspace_id}/webhookswebhooks)prefixtags )response_model.zWorkspace ID)descriptionzWebhook endpoint parametersresponseworkspace_idr   
jwt_paramsr   returnc                 *  K   |j         s!|j        |j        |k    rt          d          	 t          j        |||           d{V }|j        rdnd| _        |j        S # t          $ r(}t          dt          j        j         d          |d}~ww xY w)z/
    Get or create a webhook endpoint URL.
    NUnauthorized access to resourcer         z%Maximum number of webhook endpoints (z) reached for this workspace.)adwr   crudget_or_create_webhook_endpointcreatedstatus_coderesource
ValueErrorr   r   WEBHOOKMAX_WORKSPACE_LIMIT)r   r   r   r   r   resultes          </DATA/AppData/hermes/projects/honcho/src/routers/webhooks.pyr'   r'      s       = IZ\5*,,:V:V%&GHHH	:g
 
 
 
 
 
 
 
 
 '-n=ss#   wH4D4Xwww
 
	s   3A   
B*#BBc                    K   |j         s!|j        |j        | k    rt          d          t          j        |            d{V }t          ||           d{V S )zG
    List all webhook endpoints, optionally filtered by workspace.
    Nr!   )r$   r%   r   r&   list_webhook_endpointsr	   )r   r   r   stmts       r0   r2   r2   7   sy       = IZ\5*,,:V:V%&GHHH,\::::::::D2t$$$$$$$$$    z/{endpoint_id}   )r   r)   zWebhook endpoint IDendpoint_idc                    K   |j         s!|j        |j        | k    rt          d          t          j        || |           d{V  dS )z-
    Delete a specific webhook endpoint.
    Nr!   )r$   r%   r   r&   delete_webhook_endpoint)r   r6   r   r   s       r0   r8   r8   G   sb       = IZ\5*,,:V:V%&GHHH

&r<
E
EEEEEEEEEEr4   z/testc                    K   |j         s!|j        |j        | k    rt          d          t          |           }t	          |           d{V  dS )z*
    Test publishing a webhook event.
    NzUnable to publish test webhook)r   )r$   r%   r   r   r   )r   r   events      r0   	test_emitr;   X   sk       = HZ\5*,,:V:V%&FGGG<000E

&
&&&&&&&&&&r4   )-loggingfastapir   r   r   r   r   fastapi_paginationr   !fastapi_pagination.ext.sqlalchemyr	   sqlalchemy.ext.asyncior
   srcr   
src.configr   src.crudr   r&   src.dependenciesr   src.exceptionsr   r   src.securityr   r   src.webhooks.eventsr   r   	getLogger__name__loggerrouterpostWebhookEndpointstrWebhookEndpointCreater'   getr2   deleter8   r;    r4   r0   <module>rS      s    < < < < < < < < < < < < < < # # # # # # 7 7 7 7 7 7 / / / / / /             $ $ $ $ $ $       E E E E E E E E 0 0 0 0 0 0 0 0       
 
	8	$	$	0

 
 
 R 788 Sn===-1T6. . . $GLLNN33  *  	    986 BtG$;<==Sn===#GLLNN33% %%% 	% 
'
!"	% % % >=% #FFSn===tC-BCCC#GLLNN33	F FFF F 		F
 
F F F GFF  GSn===#GLLNN33' ''' 
' ' ' ' ' 'r4   