Skip to content

Commit

Permalink
Merge pull request #238 from EGA-archive/develop
Browse files Browse the repository at this point in the history
last changes adding introspection and GDI changes
  • Loading branch information
costero-e authored Oct 30, 2023
2 parents b4f1828 + cf58289 commit 7ec65de
Show file tree
Hide file tree
Showing 17 changed files with 205,927 additions and 209,895 deletions.
2 changes: 1 addition & 1 deletion beacon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
#
# Permissions server configuration
#
permissions_url = 'http://beacon-permissions'
permissions_url = 'http://beacon-permissions:5051/'
#permissions_url = 'http://localhost:5051/'

#
Expand Down
30 changes: 30 additions & 0 deletions beacon/db/extract_filtering_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,44 @@
import numpy as np
from utils import get_filtering_documents

import sys
import os


current = os.path.dirname(os.path.realpath(__file__))


parent = os.path.dirname(current)


sys.path.append(parent)


import conf


ONTOLOGY_REGEX = re.compile(r"([_A-Za-z0-9]+):([_A-Za-z0-9^\-]+)")

client = MongoClient(
#"mongodb://127.0.0.1:27017/"
"mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source,
)
)

'''
client = MongoClient(
client = MongoClient(
#"mongodb://127.0.0.1:27017/"
"mongodb://root:example@mongo:27017/beacon?authSource=admin"
)
'''

class MyProgressBar:
def __init__(self):
Expand Down
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 jwt

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:
decoded = jwt.decode(access_token, options={"verify_signature": False})
LOG.debug(decoded)
token_username = decoded['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 ')


decoded = jwt.decode(access_token, options={"verify_signature": False})
LOG.debug(decoded)
token_username = decoded['preferred_username']

authorized_datasets, authenticated = await resolve_token(access_token, search_datasets)
LOG.debug(authorized_datasets)
Expand Down
3 changes: 1 addition & 2 deletions beacon/request/public_datasets.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
public_datasets:
- CINECA_synthetic_cohort_EUROPE_UK1
- AV_Dataset
- AV_Dataset
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
2 changes: 1 addition & 1 deletion beacon/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def resolve_token(token, requested_datasets_ids):
# * return _all_ the datasets the user has access to, in case the datasets list is empty
async with ClientSession() as session:
async with session.post(
'http://beacon-permissions:5051/',
permissions_url,
headers={'Authorization': 'Bearer ' + token,
'Accept': 'application/json'},
json={'datasets': requested_datasets_ids}, # will set the Content-Type to application/json
Expand Down
2 changes: 1 addition & 1 deletion deploy/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#
# Permissions server configuration
#
permissions_url = 'http://beacon-permissions'
permissions_url = 'http://beacon-permissions:5051/'

#
# IdP endpoints (OpenID Connect/Oauth2)
Expand Down
Loading

0 comments on commit 7ec65de

Please sign in to comment.