This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from quantmind/master
v 2.2.0
- Loading branch information
Showing
17 changed files
with
52 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,6 @@ twine | |
agile-toolkit | ||
|
||
# additional features | ||
raven-aiohttp | ||
sentry-sdk | ||
python-dotenv | ||
openapi-spec-validator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Minimal OpenAPI asynchronous server application""" | ||
|
||
__version__ = "2.1.2" | ||
__version__ = "2.2.0" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,20 @@ | ||
from aiohttp import web | ||
|
||
from .exc import ImproperlyConfigured | ||
|
||
try: | ||
from raven import Client | ||
from raven.conf.remote import RemoteConfig | ||
from raven_aiohttp import AioHttpTransport | ||
except ImportError: # pragma: no cover | ||
AioHttpTransport = None | ||
|
||
|
||
def middleware(app, dsn, env="dev"): | ||
if not AioHttpTransport: # pragma: no cover | ||
raise ImproperlyConfigured("Sentry middleware requires raven_aiohttp") | ||
app["sentry"] = Sentry(dsn, env) | ||
app.on_shutdown.append(close) | ||
|
||
@web.middleware | ||
async def middleware_handler(request, handler): | ||
try: | ||
return await handler(request) | ||
except Exception: | ||
content = await request.content.read() | ||
data = { | ||
"request": { | ||
"url": str(request.url).split("?")[0], | ||
"method": request.method.lower(), | ||
"data": content, | ||
"query_string": request.url.query_string, | ||
"cookies": dict(request.cookies), | ||
"headers": dict(request.headers), | ||
}, | ||
"user": {"id": request.get("user_id")}, | ||
} | ||
app["sentry"].captureException(data=data) | ||
raise | ||
|
||
return middleware_handler | ||
|
||
|
||
async def close(app): | ||
await app["sentry"].close() | ||
|
||
|
||
class Sentry: | ||
def __init__(self, dsn, env): | ||
client = Client( | ||
transport=AioHttpTransport, ignore_exceptions=[web.HTTPException] | ||
) | ||
client.remote = RemoteConfig(transport=AioHttpTransport) | ||
client._transport_cache = {None: client.remote} | ||
client.set_dsn(dsn, AioHttpTransport) | ||
self.env = env | ||
self.client = client | ||
|
||
def captureException(self, data=None): | ||
if data is None: | ||
data = {} | ||
data["environment"] = self.env | ||
self.client.captureException(data=data) | ||
|
||
async def close(self): | ||
transport = self.client.remote.get_transport() | ||
if transport: | ||
await transport.close() | ||
import logging | ||
|
||
import sentry_sdk | ||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration | ||
from sentry_sdk.integrations.logging import LoggingIntegration | ||
|
||
|
||
def setup(app, dsn, env="dev", level=logging.ERROR, event_level=logging.ERROR): | ||
|
||
sentry_sdk.init( | ||
dsn=dsn, | ||
environment=env, | ||
integrations=[ | ||
LoggingIntegration( | ||
level=level, # Capture level and above as breadcrumbs | ||
event_level=event_level, # Send event_level and above as events | ||
), | ||
AioHttpIntegration(), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,6 @@ def requirements(name): | |
install_requires = requirements("dev/requirements.txt")[0] | ||
tests_require = requirements("dev/requirements-test.txt")[0] | ||
|
||
if sys.version_info < (3, 7): | ||
install_requires.append("dataclasses") | ||
|
||
|
||
if sys.version_info < (3, 8): | ||
install_requires.append("cached-property") | ||
|
@@ -52,7 +49,7 @@ def requirements(name): | |
author_email="[email protected]", | ||
maintainer_email="[email protected]", | ||
url="https://github.com/quantmind/aio-openapi", | ||
python_requires=">=3.6", | ||
python_requires=">=3.7", | ||
install_requires=install_requires, | ||
tests_require=tests_require, | ||
include_package_data=True, | ||
|
@@ -64,7 +61,6 @@ def requirements(name): | |
"Programming Language :: JavaScript", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters