Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix bool in query parameter #4690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
from typing import Any

from aiohttp import web
Expand All @@ -11,6 +12,7 @@
from models_library.wallets import WalletID
from pydantic import BaseModel, Extra, Field, NonNegativeInt
from servicelib.aiohttp.requests_validation import parse_request_query_parameters_as
from servicelib.aiohttp.typing_extension import Handler
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
from servicelib.request_keys import RQT_USERID_KEY
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
Expand All @@ -19,13 +21,26 @@
from .._meta import API_VTAG as VTAG
from ..login.decorators import login_required
from ..security.decorators import permission_required
from ..wallets.errors import WalletAccessForbiddenError
from . import _service_runs_api as api

#
# API components/schemas
#


def _handle_resource_usage_exceptions(handler: Handler):
@functools.wraps(handler)
async def wrapper(request: web.Request) -> web.StreamResponse:
try:
return await handler(request)

except WalletAccessForbiddenError as exc:
raise web.HTTPForbidden(reason=f"{exc}") from exc

return wrapper


class _RequestContext(BaseModel):
user_id: UserID = Field(..., alias=RQT_USERID_KEY) # type: ignore[pydantic-alias]
product_name: str = Field(..., alias=RQ_PRODUCT_KEY) # type: ignore[pydantic-alias]
Expand Down Expand Up @@ -57,6 +72,7 @@ class Config:
@routes.get(f"/{VTAG}/resource-usage/services", name="list_resource_usage_services")
@login_required
@permission_required("resource-usage.read")
@_handle_resource_usage_exceptions
async def list_resource_usage_services(request: web.Request):
req_ctx = _RequestContext.parse_obj(request)
query_params = parse_request_query_parameters_as(_ListServicesPathParams, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def list_service_runs_by_user_and_product_and_wallet(
"user_id": user_id,
"product_name": product_name,
"wallet_id": wallet_id,
"access_all_wallet_usage": access_all_wallet_usage,
"access_all_wallet_usage": f"{access_all_wallet_usage}".lower(),
"offset": offset,
"limit": limit,
}
Expand Down