Skip to content

Commit

Permalink
response type added
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Oct 24, 2023
1 parent 9dd3c7a commit b0033fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions beacon/request/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bson import json_util
from beacon import conf
import yaml
import base64

from beacon.request import ontologies
from beacon.request.model import Granularity, RequestParams
Expand Down Expand Up @@ -66,6 +67,9 @@ async def wrapper(request: Request):
except Exception:
specific_datasets = []
access_token = access_token[7:] # cut out 7 characters: len('Bearer ')




authorized_datasets, authenticated = await resolve_token(access_token, search_datasets)
LOG.debug(authorized_datasets)
Expand Down Expand Up @@ -178,6 +182,24 @@ async def wrapper(request: Request):


qparams = RequestParams(**json_body).from_request(request)

if access_token is not None:
tokenSplit = access_token.split(".")
payload_token = json.loads((base64.b64decode(tokenSplit[1])).decode("utf-8"))
token_username = payload_token['preferred_username']
with open("/beacon/beacon/request/response_type.yml", 'r') as response_type_file:
response_type_dict = yaml.safe_load(response_type_file)

response_type = response_type_dict[token_username]
if response_type is not None:
for response_typed in response_type:
LOG.debug(response_typed)
if response_typed == 'boolean':
qparams.query.requested_granularity = Granularity.BOOLEAN
elif response_typed == 'count':
qparams.query.requested_granularity = Granularity.COUNT
elif response_typed == 'record':
qparams.query.requested_granularity = Granularity.RECORD


entry_id = request.match_info.get('id', None)
Expand All @@ -200,6 +222,8 @@ async def wrapper(request: Request):
finish_record = limit*skip + limit

response_converted = records

LOG.debug(qparams.query.requested_granularity)

if qparams.query.requested_granularity == Granularity.BOOLEAN:
response = build_beacon_boolean_response(response_converted, count, qparams, lambda x, y: x, entity_schema)
Expand Down Expand Up @@ -242,6 +266,11 @@ async def wrapper(request: Request):
except Exception:
specific_datasets = []
access_token = access_token[7:] # cut out 7 characters: len('Bearer ')


tokenSplit = access_token.split(".")
payload_token = json.loads((base64.b64decode(tokenSplit[1])).decode("utf-8"))
LOG.debug(payload_token)

authorized_datasets, authenticated = await resolve_token(access_token, search_datasets)
LOG.debug(authorized_datasets)
Expand Down
2 changes: 2 additions & 0 deletions beacon/request/response_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
new_user:
- record

0 comments on commit b0033fb

Please sign in to comment.