udata-hydra-csvapi 0.4.3.dev3__py3-none-any.whl → 0.4.3.dev4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_tabular/core/cors.py +33 -17
- api_tabular/metrics/app.py +3 -2
- api_tabular/tabular/app.py +3 -2
- {udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/METADATA +1 -1
- {udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/RECORD +8 -8
- {udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/WHEEL +0 -0
- {udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/licenses/LICENSE +0 -0
- {udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/top_level.txt +0 -0
api_tabular/core/cors.py
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
from aiohttp import web
|
|
2
|
+
from aiohttp.web_urldispatcher import MatchInfoError
|
|
3
|
+
|
|
4
|
+
CORS_HEADERS = {
|
|
5
|
+
# Using "*" ensures the Nginx cache remains consistent for all origins
|
|
6
|
+
"Access-Control-Allow-Origin": "*",
|
|
7
|
+
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
|
8
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
|
|
9
|
+
"Access-Control-Expose-Headers": "*",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _accepts_method(match_info: web.UrlMappingMatchInfo, method: str) -> bool:
|
|
14
|
+
# No route registers OPTIONS, so an existing path resolves to a 405 listing its allowed methods
|
|
15
|
+
return (
|
|
16
|
+
isinstance(match_info, MatchInfoError)
|
|
17
|
+
and isinstance(match_info.http_exception, web.HTTPMethodNotAllowed)
|
|
18
|
+
and method in match_info.http_exception.allowed_methods
|
|
19
|
+
)
|
|
2
20
|
|
|
3
21
|
|
|
4
22
|
@web.middleware
|
|
5
|
-
async def
|
|
6
|
-
"""
|
|
7
|
-
Middleware to handle CORS and the OPTIONS preflight.
|
|
8
|
-
"""
|
|
23
|
+
async def _preflight_middleware(request: web.Request, handler):
|
|
24
|
+
"""Answer an OPTIONS preflight with a 204, only for a route accepting the requested method."""
|
|
9
25
|
if request.method == "OPTIONS":
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
requested_method = request.headers.get("Access-Control-Request-Method", "GET")
|
|
27
|
+
if _accepts_method(request.match_info, requested_method):
|
|
28
|
+
return web.Response(status=204)
|
|
29
|
+
return await handler(request)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def add_cors_headers(request: web.Request, response: web.StreamResponse) -> None:
|
|
33
|
+
# on_response_prepare also fires for raised HTTP errors, unhandled 500s and streamed responses
|
|
34
|
+
response.headers.update(CORS_HEADERS)
|
|
14
35
|
|
|
15
|
-
# Add CORS headers to the response
|
|
16
|
-
# Using "*" ensures the Nginx cache remains consistent for all origins
|
|
17
|
-
response.headers["Access-Control-Allow-Origin"] = "*"
|
|
18
|
-
response.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS"
|
|
19
|
-
response.headers["Access-Control-Allow-Headers"] = (
|
|
20
|
-
"Content-Type, Authorization, X-Requested-With"
|
|
21
|
-
)
|
|
22
|
-
response.headers["Access-Control-Expose-Headers"] = "*"
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
def setup_cors(app: web.Application) -> None:
|
|
38
|
+
"""Enable CORS on an app: answer OPTIONS preflights and add CORS headers to every response."""
|
|
39
|
+
app.middlewares.append(_preflight_middleware)
|
|
40
|
+
app.on_response_prepare.append(add_cors_headers)
|
api_tabular/metrics/app.py
CHANGED
|
@@ -7,7 +7,7 @@ from aiohttp import ClientSession, web
|
|
|
7
7
|
from aiohttp_swagger import setup_swagger
|
|
8
8
|
|
|
9
9
|
from api_tabular import config
|
|
10
|
-
from api_tabular.core.cors import
|
|
10
|
+
from api_tabular.core.cors import setup_cors
|
|
11
11
|
from api_tabular.core.data import stream_data
|
|
12
12
|
from api_tabular.core.error import QueryException, handle_exception
|
|
13
13
|
from api_tabular.core.health import check_health
|
|
@@ -108,7 +108,8 @@ async def app_factory():
|
|
|
108
108
|
async def on_cleanup(app):
|
|
109
109
|
await app["csession"].close()
|
|
110
110
|
|
|
111
|
-
app = web.Application(
|
|
111
|
+
app = web.Application()
|
|
112
|
+
setup_cors(app)
|
|
112
113
|
app.add_routes(routes)
|
|
113
114
|
app.on_startup.append(on_startup)
|
|
114
115
|
app.on_cleanup.append(on_cleanup)
|
api_tabular/tabular/app.py
CHANGED
|
@@ -7,7 +7,7 @@ from aiohttp import ClientSession, web
|
|
|
7
7
|
from aiohttp_swagger import setup_swagger
|
|
8
8
|
|
|
9
9
|
from api_tabular import config
|
|
10
|
-
from api_tabular.core.cors import
|
|
10
|
+
from api_tabular.core.cors import setup_cors
|
|
11
11
|
from api_tabular.core.health import check_health
|
|
12
12
|
from api_tabular.core.sentry import get_sentry_kwargs
|
|
13
13
|
from api_tabular.core.swagger import build_swagger_file
|
|
@@ -173,7 +173,8 @@ async def app_factory():
|
|
|
173
173
|
async def on_cleanup(app):
|
|
174
174
|
await app["csession"].close()
|
|
175
175
|
|
|
176
|
-
app = web.Application(
|
|
176
|
+
app = web.Application()
|
|
177
|
+
setup_cors(app)
|
|
177
178
|
app.add_routes(routes)
|
|
178
179
|
app.on_startup.append(on_startup)
|
|
179
180
|
app.on_cleanup.append(on_cleanup)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
api_tabular/__init__.py,sha256=sYG6CMz-twob-QLyfsPYRc6cWDtqWXvq_N5Dxk-U5qA,2263
|
|
2
2
|
api_tabular/config_default.toml,sha256=cX506NdqHW7gK_2aZjzLiz0Z4gMSl1tU_tI4i4BvuXs,421
|
|
3
3
|
api_tabular/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
api_tabular/core/cors.py,sha256=
|
|
4
|
+
api_tabular/core/cors.py,sha256=xX4qSbv06pVT-NrohQlysFPSR9z7Pj2THz18TCbvJ90,1707
|
|
5
5
|
api_tabular/core/data.py,sha256=5j-3d_el7LMoHpn6V__UdhYHD6GiJbwdH67jrnOYWZQ,1459
|
|
6
6
|
api_tabular/core/error.py,sha256=xRt6fkQfsiupv0tWWzdX0DJjAKbw1n0tRxFyt15VBLA,1062
|
|
7
7
|
api_tabular/core/health.py,sha256=NeFT1C00onvm3CbgesFAcN1N8bmelbQdEYFbmmftICQ,647
|
|
@@ -12,12 +12,12 @@ api_tabular/core/url.py,sha256=af7VKfrMtKMzlHrGgtLDLuRBim4qFv7xlt2PYxAyW2g,761
|
|
|
12
12
|
api_tabular/core/utils.py,sha256=Ghd9Un0HugFg4oEcEb5yB5FEop7tDSoX4OCzR8mcM-Y,1922
|
|
13
13
|
api_tabular/core/version.py,sha256=OKLg0l1CpDRHV2hsqVgtSihoo3tg0aMG6kzMILtQ-bY,250
|
|
14
14
|
api_tabular/metrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
api_tabular/metrics/app.py,sha256=
|
|
15
|
+
api_tabular/metrics/app.py,sha256=W2htxUO54bTfQLReJhEY3JtsbLWaefC71DmjV9SvUII,4291
|
|
16
16
|
api_tabular/tabular/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
api_tabular/tabular/app.py,sha256=
|
|
17
|
+
api_tabular/tabular/app.py,sha256=6lwujb2Pf_70QQlTKL8bhQTnhYinRyDlF_yTdit0pQw,6528
|
|
18
18
|
api_tabular/tabular/utils.py,sha256=BL2nl04-3imBQG-RZiYvVMjxoBORi4lwrKq8NiWecLY,4487
|
|
19
|
-
udata_hydra_csvapi-0.4.3.
|
|
20
|
-
udata_hydra_csvapi-0.4.3.
|
|
21
|
-
udata_hydra_csvapi-0.4.3.
|
|
22
|
-
udata_hydra_csvapi-0.4.3.
|
|
23
|
-
udata_hydra_csvapi-0.4.3.
|
|
19
|
+
udata_hydra_csvapi-0.4.3.dev4.dist-info/licenses/LICENSE,sha256=fb-HAYw94ffh--z1cZrWbpk6YKM0p9WFG7kdd0K7uGQ,1062
|
|
20
|
+
udata_hydra_csvapi-0.4.3.dev4.dist-info/METADATA,sha256=h571GAbAb6UrNwO_O4SZbMMmvpId-1FdiVM0s_NRyw8,21835
|
|
21
|
+
udata_hydra_csvapi-0.4.3.dev4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
22
|
+
udata_hydra_csvapi-0.4.3.dev4.dist-info/top_level.txt,sha256=MAaK09hxwPhIBBC0i1TdEBAgdu3W_gXnAZqk767gVak,12
|
|
23
|
+
udata_hydra_csvapi-0.4.3.dev4.dist-info/RECORD,,
|
|
File without changes
|
{udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{udata_hydra_csvapi-0.4.3.dev3.dist-info → udata_hydra_csvapi-0.4.3.dev4.dist-info}/top_level.txt
RENAMED
|
File without changes
|