<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
B
    Y                 @   sr   d Z ddlm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 edZdd	 ZG d
d de	ZdS )z
raven.contrib.awslambda
~~~~~~~~~~~~~~~~~~~~

Raven wrapper for AWS Lambda handlers.

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
    )absolute_importN)FunctionType)Client)HTTPTransportzsentry.errors.clientc               C   s   dddddddS )NZAWS_LAMBDA_FUNCTION_NAMEZAWS_LAMBDA_FUNCTION_VERSIONZAWS_LAMBDA_FUNCTION_MEMORY_SIZEZAWS_LAMBDA_LOG_GROUP_NAMEZAWS_LAMBDA_LOG_STREAM_NAMEZ
AWS_REGION)lambdaversionZmemory_sizeZ	log_groupZ
log_streamZregion r   r   r   Q/opt/alt/python37/lib/python3.7/site-packages/raven/contrib/awslambda/__init__.pyget_default_tags   s    r
   c                   sf   e Zd ZdZ fddZ fddZ fddZdd	d
Zedd Z	edd Z
edd Z  ZS )LambdaClienta  
    Raven decorator for AWS Lambda.

    By default, the lambda integration will capture unhandled exceptions and instrument logging.

    Usage:

    >>> from raven.contrib.awslambda import LambdaClient
    >>>
    >>>
    >>> client = LambdaClient()
    >>>
    >>> @client.capture_exceptions
    >>> def handler(event, context):
    >>>    ...
    >>>    raise Exception('I will be sent to sentry!')

    c                s*   | dt}tt| j|d|i| d S )N	transport)getr   superr   __init__)selfargskwargsr   )	__class__r   r	   r   8   s    zLambdaClient.__init__c                s   d|kri  |d< }n|d }| dd }| dd }| |}|rN|| |rz| |}|rj|| | |||d< tt| j||S )Ndataeventcontextextra)r   _get_user_interfaceupdate_get_http_interface_get_extra_datar   r   capture)r   r   r   r   r   r   Z	user_infoZ	http_info)r   r   r	   r   <   s    



zLambdaClient.capturec                sn   t t| j||}x.t  D ] \}}|d |tj| qW |dtjd |dtjd |S )NZtagsreleaseZSENTRY_RELEASEenvironmentZSENTRY_ENVIRONMENT)	r   r   	build_msgr
   items
setdefaultosenvironr   )r   r   r   r   optiondefault)r   r   r	   r   M   s    zLambdaClient.build_msgNc                sB   t tstjjdS  p"tf t fdd}|S )a  
        Wrap a function or code block in try/except and automatically call
        ``.captureException`` if it raises an exception, then the exception
        is reraised.

        By default, it will capture ``Exception``

        >>> @client.capture_exceptions
        >>> def foo():
        >>>     raise Exception()

        >>> with client.capture_exceptions():
        >>>    raise Exception()

        You can also specify exceptions to be caught specifically

        >>> @client.capture_exceptions((IOError, LookupError))
        >>> def bar():
        >>>     ...

        ``kwargs`` are passed through to ``.captureException``.
        )
exceptionsc                sN   y| |f||S   k
rH   j f | |d| j   Y nX d S )N)r   r   )ZcaptureExceptionr   clear)r   r   r   r   )r&   fr   r   r	   wrappedt   s    
z0LambdaClient.capture_exceptions.<locals>.wrapped)
isinstancer   	functoolspartialcapture_exceptions	Exceptionwraps)r   r(   r&   r)   r   )r&   r(   r   r	   r-   V   s
    

zLambdaClient.capture_exceptionsc             C   sr   |  drn| d d }|rn| dd p0| dd | dd | dd | dd | dd | dd	}d|iS d S )
NZrequestContextidentityZcognitoIdentityIduserZsourceIpZcognitoIdentityPoolIdZcognitoAuthenticationTypeZ	userAgent)idusernameZ
ip_addressZcognito_identity_pool_idZcognito_authentication_typeZ
user_agent)r   )r   r0   r1   r   r   r	   r   ~   s    




z LambdaClient._get_user_interfacec             C   sN   |  drJ|  drJ|  d|  d|  dd |  dd p<g d}d|iS d S )NpathZ
httpMethodZqueryStringParametersheaders)urlmethodZquery_stringr5   request)r   )r   r8   r   r   r	   r      s    
z LambdaClient._get_http_interfacec             C   sZ   | |j t|d}|jrV|jjj|jjj|jjj|jjj|jjj|jj	|jj
d|d< |S )N)r   aws_request_idr   )zclient.installation_idzclient.app_titlezclient.app_version_namezclient.app_version_codezclient.app_package_namecustomenvclient_context)r9   varsr<   ZclientZinstallation_idZ	app_titleZapp_version_nameZapp_version_codeZapp_package_namer:   r;   )r   r   Zextra_contextr   r   r	   r      s    zLambdaClient._get_extra_data)NN)__name__
__module____qualname____doc__r   r   r   r-   staticmethodr   r   r   __classcell__r   r   )r   r	   r   $   s   	
(r   )rA   
__future__r   r"   loggingr+   typesr   Z
raven.baser   Zraven.transport.httpr   	getLoggerloggerr
   r   r   r   r   r	   <module>	   s   
