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

last changes adding introspection and GDI changes #238

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
response type added
costero-e committed Oct 24, 2023
commit b0033fb29512dd66b923630dac853aa7f46575a2
29 changes: 29 additions & 0 deletions beacon/request/handlers.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
@@ -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)
@@ -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)
@@ -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)
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