From c0dab87815d8ec39121f4f1a83b84463a407d70b Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 16 Aug 2024 19:25:29 +0200 Subject: [PATCH] more compact code --- cdci_data_analysis/flask_app/app.py | 102 +++++++++++++++------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/cdci_data_analysis/flask_app/app.py b/cdci_data_analysis/flask_app/app.py index 1a70bdf7..41136b1d 100644 --- a/cdci_data_analysis/flask_app/app.py +++ b/cdci_data_analysis/flask_app/app.py @@ -601,8 +601,11 @@ def get(self, path): @app.route('/resolve_name', methods=['GET']) def resolve_name(): - logger.info("request.args: %s ", request.args) - token = request.args.get('token', None) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) + + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -613,7 +616,7 @@ def resolve_name(): if output_code is not None: return make_response(output, output_code) - name = request.args.get('name', None) + name = par_dic.get('name', None) name_resolver_url = app_config.name_resolver_url entities_portal_url = app_config.entities_portal_url @@ -627,8 +630,11 @@ def resolve_name(): @app.route('/get_revnum', methods=['GET']) def get_revnum(): - logger.info("request.args: %s ", request.args) - token = request.args.get('token', None) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) + + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -639,7 +645,7 @@ def get_revnum(): if output_code is not None: return make_response(output, output_code) - time_to_convert = request.args.get('time_to_convert', None) + time_to_convert = par_dic.get('time_to_convert', None) converttime_revnum_service_url = app_config.converttime_revnum_service_url @@ -650,8 +656,11 @@ def get_revnum(): @app.route('/get_list_terms', methods=['GET']) def get_list_terms(): - logger.info("request.args: %s ", request.args) - token = request.args.get('token', None) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) + + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -665,8 +674,8 @@ def get_list_terms(): sentry_dsn = sentry.sentry_url - group = request.args.get('group', None) - parent = request.args.get('parent', None) + group = par_dic.get('group', None) + parent = par_dic.get('parent', None) list_terms = drupal_helper.get_list_terms(disp_conf=app_config, group=group, @@ -681,8 +690,11 @@ def get_list_terms(): @app.route('/get_parents_term', methods=['GET']) def get_parents_term(): - logger.info("request.args: %s ", request.args) - token = request.args.get('token', None) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) + + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -696,8 +708,8 @@ def get_parents_term(): sentry_dsn = sentry.sentry_url - group = request.args.get('group', None) - term = request.args.get('term', None) + group = par_dic.get('group', None) + term = par_dic.get('term', None) list_parents = drupal_helper.get_parents_term(disp_conf=app_config, term=term, @@ -712,9 +724,12 @@ def get_parents_term(): @app.route('/get_observation_attachments', methods=['GET']) def get_observation_attachments(): + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.args: %s ", request.args) - token = request.args.get('token', None) + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -726,9 +741,6 @@ def get_observation_attachments(): return make_response(output, output_code) decoded_token = output - par_dic = request.values.to_dict() - par_dic.pop('token') - sentry_dsn = sentry.sentry_url gallery_secret_key = app_config.product_gallery_secret_key @@ -752,10 +764,12 @@ def get_observation_attachments(): @app.route('/get_all_revs', methods=['GET']) def get_all_revs(): - logger.info("request.args: %s ", request.args) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = request.args.get('token', None) + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -767,9 +781,6 @@ def get_all_revs(): return make_response(output, output_code) decoded_token = output - par_dic = request.values.to_dict() - par_dic.pop('token') - sentry_dsn = sentry.sentry_url gallery_secret_key = app_config.product_gallery_secret_key @@ -792,10 +803,12 @@ def get_all_revs(): @app.route('/get_all_astro_entities', methods=['GET']) def get_all_astro_entities(): - logger.info("request.args: %s ", request.args) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = request.args.get('token', None) + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -807,9 +820,6 @@ def get_all_astro_entities(): return make_response(output, output_code) decoded_token = output - par_dic = request.values.to_dict() - par_dic.pop('token') - sentry_dsn = sentry.sentry_url gallery_secret_key = app_config.product_gallery_secret_key @@ -831,7 +841,9 @@ def get_all_astro_entities(): @app.route('/get_astro_entity_info_by_source_name', methods=['GET']) def get_astro_entity_info_by_source_name(): - logger.info("request.args: %s ", request.args) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) app_config = app.config.get('conf') @@ -839,7 +851,7 @@ def get_astro_entity_info_by_source_name(): sentry_dsn = sentry.sentry_url product_gallery_url = app_config.product_gallery_url - src_name = request.args.get('src_name', None) + src_name = par_dic.get('src_name', None) source_entity_info = drupal_helper.get_source_astrophysical_entity_info_by_source_and_alternative_name(product_gallery_url, gallery_jwt_token=None, @@ -866,10 +878,11 @@ def get_astro_entity_info_by_source_name(): @app.route('/get_data_product_list_with_conditions', methods=['GET']) def get_data_product_list_with_conditions(): - logger.info("request.args: %s ", request.args) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - par_dic = request.values.to_dict() token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -893,8 +906,6 @@ def get_data_product_list_with_conditions(): # update the token gallery_jwt_token = drupal_helper.generate_gallery_jwt_token(gallery_secret_key, user_id=user_id_product_creator) - # src_name = par_dic.pop('src_name', None) - output_get = drupal_helper.get_data_product_list_by_source_name_with_conditions(product_gallery_url=product_gallery_url, gallery_jwt_token=gallery_jwt_token, sentry_dsn=sentry_dsn, @@ -907,10 +918,12 @@ def get_data_product_list_with_conditions(): # TODO to refactor using get_data_product_list_with_conditions @app.route('/get_data_product_list_by_source_name', methods=['GET']) def get_data_product_list_by_source_name(): - logger.info("request.args: %s ", request.args) + par_dic = request.values.to_dict() + sanitized_par_dic = sanitize_dict_before_log(par_dic) + logger.info("request.args: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = request.args.get('token', None) + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -922,8 +935,6 @@ def get_data_product_list_by_source_name(): return make_response(output, output_code) decoded_token = output - par_dic = request.values.to_dict() - par_dic.pop('token') sentry_dsn = sentry.sentry_url @@ -955,8 +966,7 @@ def post_astro_entity_to_gallery(): logger.info("request.values: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = par_dic.get('token', None) - par_dic.pop('token') + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -983,8 +993,7 @@ def post_observation_to_gallery(): par_dic = request.values.to_dict() sanitized_par_dic = sanitize_dict_before_log(par_dic) - token = par_dic.get('token', None) - par_dic.pop('token') + token = par_dic.pop('token', None) logger.info("request.values: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) @@ -1017,8 +1026,7 @@ def post_product_to_gallery(): logger.info("request.values: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = par_dic.get('token', None) - par_dic.pop('token') + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -1047,8 +1055,7 @@ def delete_product_to_gallery(): logger.info("request.values: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = par_dic.get('token', None) - par_dic.pop('token') + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key @@ -1077,8 +1084,7 @@ def post_revolution_processing_log_to_gallery(): logger.info("request.values: %s ", sanitized_par_dic) logger.info("request.files: %s ", request.files) - token = par_dic.get('token', None) - par_dic.pop('token') + token = par_dic.pop('token', None) app_config = app.config.get('conf') secret_key = app_config.secret_key