Skip to content

Commit

Permalink
1.3.7
Browse files Browse the repository at this point in the history
... authorization stub etc.; see changes doc
  • Loading branch information
mbaudis committed Dec 18, 2023
1 parent be19a12 commit 75dbebf
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 146 deletions.
2 changes: 2 additions & 0 deletions bycon/beaconServer/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def beacon():
byc.update({"request_entity_path_id": e_p_id})
r_p_id = byc.get("request_entity_path_id", "info")

prdbug(byc, f'beacon.py - request_entity_path_id: {r_p_id}')

# check for rewrites
if r_p_id in r_w:
uri = environ.get('REQUEST_URI')
Expand Down
4 changes: 4 additions & 0 deletions bycon/config/authorizations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
anonymous:
default: boolean
local:
default: record
78 changes: 38 additions & 40 deletions bycon/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
byc_root_pars:
args: {}
debug_mode: false
empty_query_all_count: false
error_response: {}
errors: []
filters: []
form_data: {}
granularity_levels:
none: 0
boolean: 1
count: 2
record: 3
pagination:
skip: 0
limit: 0
include_handovers: false
method: ''
output: ''
queries: {}
query_meta: {}
request_path_root: beacon
request_entity_path_id:
request_entity_path_id_value: false
response_entity_path_id:
request_entity_id: genomicVariant
response_entity_id: genomicVariant
response_entity:
is_entry_type: True
collection: variants
response_schema: beaconResultsetsResponse
beacon_schema:
entity_type: genomicVariant
schema: https://progenetix.org/services/schemas/genomicVariant/
service_response: {}
service_config: {}
test_mode: false
test_mode_count: 5

args:
request_path_root: beacon
request_entity_path_id:
request_entity_path_id_value: false
response_entity_path_id:
request_entity_id: genomicVariant
response_entity_id: genomicVariant
response_entity:
is_entry_type: True
collection: variants
response_schema: beaconResultsetsResponse
beacon_schema:
entity_type: genomicVariant
schema: https://progenetix.org/services/schemas/genomicVariant/
service_response: {}
error_response: {}
service_config: {}
filters: []
method: ''
output: ''
form_data: {}
queries: {}
query_meta: {}
include_handovers: false
empty_query_all_count: false
test_mode: false
test_mode_count: 5
check_args: true
debug_mode: false
download_mode: false
errors: []
filtering_terms_coll: collations

genomes_path:
- rsrc
Expand All @@ -44,18 +50,10 @@ filter_flags:
precision: exact
include_descendant_terms: true

resource_urls:
ncbi_geosoft: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?form=text&acc=
ncbi_geoweb: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=
europepmc_pmid: https://europepmc.org/article/MED/
cellosaurus_web: https://web.expasy.org/cellosaurus/

################################################################################
# MongoDB configs
################################################################################

filtering_terms_coll: collations

# special database, auto-generated ######
housekeeping_db: _byconHousekeepingDB
beacon_info_coll: beaconinfo
Expand Down
34 changes: 17 additions & 17 deletions bycon/lib/args_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

from humps import decamelize


################################################################################

def get_bycon_args(byc):
if byc.get("check_args", False) is False:
if byc.get("check_args", True) is False:
return

# Serves as "we've been here before" marker - before the env check.
Expand Down Expand Up @@ -65,6 +64,7 @@ def args_update_form(byc):
else:
byc["form_data"].update({p_d: arg_vars[p]})


################################################################################

def filters_from_args(byc):
Expand Down Expand Up @@ -99,19 +99,19 @@ def set_collation_types(byc):
def set_processing_modes(byc):
byc.update({"update_mode": False})

try:
if byc["test_mode"] is True:
byc.update({"update_mode": False})
print("¡¡¡ TEST MODE - no db update !!!")
return
except:
pass

try:
if byc["args"].update:
byc.update({"update_mode": True})
print("¡¡¡ UPDATE MODE - may overwrite entries !!!")
except:
pass
tm = byc.get("test_mode", False)
env = byc.get("env", "server")

if not "local" in env:
return

if byc["test_mode"] is True:
print("¡¡¡ TEST MODE - no db update !!!")
return

if byc["args"].update:
byc.update({"update_mode": True})
print("¡¡¡ UPDATE MODE - may overwrite entries !!!")



################################################################################
55 changes: 38 additions & 17 deletions bycon/lib/beacon_response_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def __init__(self, byc: dict):
self.byc = byc
self.test_mode = byc.get("test_mode", False)
self.beacon_defaults = byc.get("beacon_defaults", {})
self.authorized_granularities = byc.get("authorized_granularities", {})
self.user_name = byc.get("user_name", "anonymous")
self.entity_defaults = self.beacon_defaults.get("entity_defaults", {"info":{}})
self.form_data = byc.get("form_data", {})
self.service_config = self.byc.get("service_config", {})
self.response_schema = byc["response_schema"]
self.requested_granularity = self.form_data.get("requested_granularity", "record")
self.returned_granularity = self.form_data.get("returned_granularity", "record")
self.include_handovers = self.form_data.get("include_handovers", False)
self.beacon_schema = self.byc["response_entity"].get("beacon_schema", "___none___")
self.record_queries = {}
Expand All @@ -86,6 +88,7 @@ def __init__(self, byc: dict):
# -------------------------------------------------------------------------#

def resultsetResponse(self):
prdbug(self.byc, f'... resultsetResponse start, schema {self.response_schema}')
if not "beaconResultsetsResponse" in self.response_schema:
return

Expand All @@ -94,16 +97,7 @@ def resultsetResponse(self):

self.data_response["response"].update({"result_sets": self.result_sets})
self.__resultset_response_update_summaries()
if not "record" in self.requested_granularity:
# TODO /CUSTOM: This non-standard modification removes the results
# but keeps the resultSets nstructure (handovers ...)
if self.include_handovers is True:
for rs in self.data_response["response"]["result_sets"]:
rs.pop("results", None)
else:
self.data_response.pop("response", None)
if "boolean" in self.requested_granularity:
self.data_response["response_summary"].pop("num_total_results", None)
self.__resultSetResponse_force_granularities()

b_h_o = self.data_response.get("beacon_handovers", [])
if len(b_h_o) < 1:
Expand All @@ -118,6 +112,7 @@ def resultsetResponse(self):
self.__meta_add_received_request_summary_parameters()
self.__meta_add_parameters()
self.__meta_clean_parameters()
self.__response_clean_parameters()
self.result_sets_end = datetime.datetime.now()
self.result_sets_duration = self.result_sets_end - self.result_sets_start
prdbug(self.byc, f'... data response duration was {self.result_sets_duration.total_seconds()} seconds')
Expand All @@ -140,6 +135,7 @@ def collectionsResponse(self):
self.__meta_add_received_request_summary_parameters()
self.__meta_add_parameters()
self.__meta_clean_parameters()
self.__response_clean_parameters()
return self.data_response


Expand All @@ -157,6 +153,7 @@ def filteringTermsResponse(self):
self.__meta_add_received_request_summary_parameters()
self.__meta_add_parameters()
self.__meta_clean_parameters()
self.__response_clean_parameters()
return self.data_response


Expand Down Expand Up @@ -191,6 +188,30 @@ def __check_switch_to_error_response(self):
self.data_response = self.error_response


# -------------------------------------------------------------------------#

def __resultSetResponse_force_granularities(self):
prdbug(self.byc, f'authorized_granularities: {self.authorized_granularities}')
for rs in self.data_response["response"]["result_sets"]:
rs_granularity = self.authorized_granularities.get(rs["id"], "boolean")
prdbug(self.byc, f'rs_granularity ({rs["id"]}): {rs_granularity}')
if not "record" in rs_granularity:
# TODO /CUSTOM: This non-standard modification removes the results
# but keeps the resultSets structure (handovers ...)
rs.pop("results", None)
if "boolean" in rs_granularity:
rs.pop("results_count", None)
if "boolean" in self.returned_granularity:
self.data_response["response_summary"].pop("num_total_results", None)


# -------------------------------------------------------------------------#

def __response_clean_parameters(self):
r_m = self.data_response.get("response", {})
r_m.pop("$schema", None)


# -------------------------------------------------------------------------#

def __meta_clean_parameters(self):
Expand Down Expand Up @@ -221,8 +242,8 @@ def __meta_add_parameters(self):
form = self.form_data
# TODO: this is hacky; need a separate setting of the returned granularity
# since the server may decide so...
if self.requested_granularity and "returned_granularity" in r_m:
r_m.update({"returned_granularity": form.get("requested_granularity")})
# if self.requested_granularity and "returned_granularity" in r_m:
# r_m.update({"returned_granularity": form.get("requested_granularity")})

service_meta = self.service_config.get("meta", {})
for rrs_k, rrs_v in service_meta.items():
Expand All @@ -246,7 +267,7 @@ def __meta_add_received_request_summary_parameters(self):
"requested_schemas": [self.beacon_schema]
})

for name in ["dataset_ids", "test_mode"]:
for name in ["dataset_ids", "test_mode", "pagination"]:
value = self.byc.get(name)
if not value:
continue
Expand Down Expand Up @@ -442,6 +463,7 @@ def __return_filtering_terms(self):

return


# -------------------------------------------------------------------------#

def __return_filter_resources(self):
Expand Down Expand Up @@ -596,7 +618,6 @@ def populatedResultSets(self):
self.__retrieve_variants_data()
self.__populate_result_sets()
self.__result_sets_save_handovers()

return self.result_sets, self.record_queries


Expand Down Expand Up @@ -640,8 +661,8 @@ def __get_handover_access_key(self):
def __result_sets_save_handovers(self):

ho_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
ho_db = ho_client[ self.byc["config"]["housekeeping_db"] ]
ho_coll = ho_db[ self.byc["config"][ "handover_coll" ] ]
ho_db = ho_client[ self.byc["housekeeping_db"] ]
ho_coll = ho_db[ self.byc["handover_coll"] ]

for ds_id, d_s in self.datasets_results.items():
if not d_s:
Expand Down
1 change: 0 additions & 1 deletion bycon/lib/cgi_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def parse_POST(byc):
"query_meta": jbod.get("meta", {})
})


################################################################################

def parse_GET(byc):
Expand Down
15 changes: 8 additions & 7 deletions bycon/lib/dataset_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def ds_id_from_accessid(byc):
# test of existence...

accessid = byc["form_data"].get("accessid", False)
ho_db = byc["config"].get("housekeeping_db", False)
ho_collname = byc["config"].get("handover_coll", False)
ho_db = byc.get("housekeeping_db", False)
ho_collname = byc.get("handover_coll", False)

if any(x is False for x in [accessid, ho_db, ho_collname]):
return False
Expand Down Expand Up @@ -89,12 +89,13 @@ def ds_ids_from_args(byc):
if "args" not in byc or byc["args"] is None:
return False

if byc["args"].datasetIds:
ds_ids = re.split(",", byc["args"].datasetIds)
byc.update({"dataset_ids": ds_ids})
return True
dsid_s = byc["args"].get("datasetIds")
if not dsid_s:
return False

return False
ds_ids = re.split(",", dsid_s)
byc.update({"dataset_ids": ds_ids})
return True


################################################################################
Expand Down
6 changes: 3 additions & 3 deletions bycon/lib/genome_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def set_genome_rsrc_path(byc):
if genome in g_map.keys():
genome = g_map[ genome ]

byc.update({"genome_rsrc_path": path.join( pkg_path, *byc["config"]["genomes_path"], genome ) })
byc.update({"genome_rsrc_path": path.join( pkg_path, *byc["genomes_path"], genome ) })


################################################################################
Expand Down Expand Up @@ -130,11 +130,11 @@ def retrieve_gene_id_coordinates(gene_id, precision, byc):
mongo_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
db_names = list(mongo_client.list_database_names())

services_db = byc["config"].get("services_db", "___none___")
services_db = byc.get("services_db", "___none___")
if services_db not in db_names:
return [], f"services db `{services_db}` does not exist"

genes_coll = byc["config"].get("genes_coll")
genes_coll = byc.get("genes_coll")
if not genes_coll:
return [], "no `genes_coll` parameter in `config.yaml`"

Expand Down
4 changes: 2 additions & 2 deletions bycon/lib/handover_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def query_results_save_handovers(byc):
def dataset_results_save_handovers(ds_id, byc):

ho_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
ho_db = ho_client[ byc["config"]["housekeeping_db"] ]
ho_coll = ho_db[ byc["config"][ "handover_coll" ] ]
ho_db = ho_client[ byc["housekeeping_db"] ]
ho_coll = ho_db[ byc[ "handover_coll" ] ]

for h_o_k in byc["dataset_results"][ds_id].keys():

Expand Down
6 changes: 3 additions & 3 deletions bycon/lib/parse_filters_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def parse_filters(byc):
def get_global_filter_flags(byc):

ff = {
"logic": byc[ "config" ][ "filter_flags" ][ "logic" ],
"precision": byc[ "config" ][ "filter_flags" ][ "precision" ],
"descendants": byc[ "config" ][ "filter_flags" ][ "include_descendant_terms" ]
"logic": byc["filter_flags"]["logic"],
"precision": byc["filter_flags"]["precision"],
"descendants": byc["filter_flags"]["include_descendant_terms"]
}

if "form_data" in byc:
Expand Down
Loading

0 comments on commit 75dbebf

Please sign in to comment.