[med-svn] [Git][med-team/biomaj3-daemon][upstream] New upstream version 3.0.22
Andreas Tille
gitlab at salsa.debian.org
Sun Jan 17 08:41:27 GMT 2021
Andreas Tille pushed to branch upstream at Debian Med / biomaj3-daemon
Commits:
500e1c66 by Andreas Tille at 2021-01-17T09:29:04+01:00
New upstream version 3.0.22
- - - - -
8 changed files:
- .travis.yml
- CHANGES.txt
- README.md
- biomaj_daemon/daemon/biomaj_daemon_web.py
- biomaj_daemon/daemon/daemon_service.py
- biomaj_daemon/daemon/utils.py
- requirements.txt
- setup.py
Changes:
=====================================
.travis.yml
=====================================
@@ -1,13 +1,16 @@
language: python
sudo: false
python:
-- '2.7'
-- '3.4'
-- '3.5'
- '3.6'
+- '3.7'
+- '3.8'
branches:
except:
- "/^feature.*$/"
+addons:
+ apt:
+ packages:
+ - libgnutls-dev
install:
- pip install flake8
- pip install -r requirements.txt
=====================================
CHANGES.txt
=====================================
@@ -1,3 +1,10 @@
+3.0.22:
+ Add /api/daemon/expose endpoint for traefik auth requests
+ to allow/deny access to /db web access
+3.0.21:
+ Add support for repair option
+ Add cors support
+ Fix /status/ko
3.0.20:
Add some checks on options
Add data-list and data-import options
=====================================
README.md
=====================================
@@ -1,5 +1,7 @@
# About
+[](https://badge.fury.io/py/biomaj-daemon)
+
Microservice to manage biomaj, acts as a frontend to receive biomaj-cli commands and execute operations
Needs mongo and redis
=====================================
biomaj_daemon/daemon/biomaj_daemon_web.py
=====================================
@@ -4,12 +4,14 @@ import yaml
import logging
from collections import deque
import copy
+import base64
from flask import Flask
from flask import jsonify
from flask import request
from flask import abort
from flask import Response
+from flask_cors import CORS
import requests
@@ -75,6 +77,7 @@ SchemaVersion.migrate_pendings()
SchemaVersion.set_version()
app = Flask(__name__)
+CORS(app)
biomaj_metric = Counter("biomaj_daemon_total", "Bank total update execution.", ['bank', 'action', 'updated'])
biomaj_error_metric = Counter("biomaj_daemon_errors", "Bank total update errors.", ['bank', 'action'])
@@ -156,7 +159,8 @@ OPTIONS_PARAMS = {
'history': False,
'historyLimit': 20,
'datalist': False,
- 'dataimport': False
+ 'dataimport': False,
+ 'repair': False
}
@@ -678,7 +682,7 @@ def biomaj_daemon_bank_update_status(bank):
@app.route('/api/daemon/status/ko', methods=['GET'])
-def biomaj_daemon_bank_status_ko(bank):
+def biomaj_daemon_bank_status_ko():
(http_code, options, error) = daemon_api_auth(request)
if error:
abort(http_code, error)
@@ -795,6 +799,31 @@ def biomaj_daemon_bank_update_directory(bank):
abort(500, str(e))
+ at app.route('/api/daemon/bank/<bank>/repair', methods=['PUT'])
+def biomaj_daemon_bank_repair(bank):
+ (http_code, options, error) = daemon_api_auth(request)
+ if error:
+ abort(http_code, error)
+ if not options.user:
+ abort(401, 'This action requires authentication with api key')
+ options.repair = True
+ options.bank = bank
+ params = request.get_json()
+ if params is None:
+ params = {}
+ if 'release' in params:
+ options.release = params['release']
+ try:
+ (res, msg) = biomaj_client_action(options, config)
+ if res:
+ if isinstance(msg, dict):
+ return jsonify(msg)
+ else:
+ return jsonify({'msg': msg})
+ except Exception as e:
+ abort(500, str(e))
+
+
@app.route('/api/daemon/bank/<bank>', methods=['POST'])
def biomaj_daemon_bank_update(bank):
(http_code, options, error) = daemon_api_auth(request)
@@ -1079,6 +1108,46 @@ def add_metrics():
return jsonify({'msg': 'OK'})
+ at app.route('/api/daemon/expose', methods=['GET'])
+def expose():
+ do_expose = True
+ try:
+ do_expose_cfg = BiomajConfig.global_config.get('GENERAL', 'expose')
+ if do_expose_cfg == "false" or do_expose_cfg == "0":
+ do_expose = False
+
+ except Exception:
+ do_expose = True
+ if not do_expose:
+ abort(403)
+ uri = request.headers['X-Forwarded-Uri']
+ if uri == '/db' or uri == '/db/':
+ return jsonify({'msg': 'access allowed'})
+ elts = uri.split('/')
+ requested_bank = elts[2]
+ user = None
+ options = Options({})
+ bank = Bank(requested_bank, options=Options({}), no_log=True)
+ if bank.bank['properties']['visibility'] == 'public':
+ return jsonify({'msg': 'access allowed'})
+
+ if not request.headers.get('Authorization', None):
+ abort(403)
+ encoded_uname_pass = request.headers.get('Authorization').split()[-1]
+ uname_pass = base64.b64decode(encoded_uname_pass)
+ apikey = uname_pass.split(':')[-1]
+ proxy = Utils.get_service_endpoint(config, 'user')
+ r = requests.get(proxy + '/api/user/info/apikey/' + apikey)
+ if not r.status_code == 200:
+ abort(404, {'message': 'Invalid API Key or connection issue'})
+ user = r.json()['user']
+ options = Options({'user': user['id']})
+ bank = Bank(requested_bank, options=options, no_log=True)
+ if not bank.is_owner():
+ abort(403)
+ return jsonify({'msg': 'access allowed'})
+
+
if __name__ == "__main__":
context = None
if config['tls']['cert']:
=====================================
biomaj_daemon/daemon/daemon_service.py
=====================================
@@ -204,6 +204,15 @@ class DaemonService(object):
elif options.removepending:
bmaj = Bank(options.bank, options, no_log=True)
bmaj.remove_pending(options.release)
+ elif options.repair:
+ action = 'repair'
+ self.__start_action(options.bank, action)
+ bmaj = Bank(options.bank, options)
+ self.logger.debug('Log file: ' + bmaj.config.log_file)
+ is_ok = bmaj.repair()
+ is_updated = bmaj.session.get('update')
+ Notify.notifyBankAction(bmaj)
+ self.__end_action()
except Exception as e:
self.logger.exception('Exception: ' + str(e))
is_ok = False
=====================================
biomaj_daemon/daemon/utils.py
=====================================
@@ -422,6 +422,13 @@ def biomaj_bank_update_request(options, config):
return biomaj_send_message(options, config)
+def biomaj_bank_repair_request(options, config):
+ '''
+ Send bank repair request to rabbitmq
+ '''
+ return biomaj_send_message(options, config)
+
+
def biomaj_whatsup(options, config):
redis_client = None
whatsup = []
@@ -498,6 +505,43 @@ def biomaj_send_message(options, config):
return (True, None)
+def biomaj_bank_repair(options, config):
+ '''
+ Repair a bank
+ '''
+ if not options.bank:
+ return (False, "Bank name is missing")
+ banks = options.bank.split(',')
+ gres = True
+ msg = ''
+ for bank in banks:
+ options.bank = bank
+ no_log = True
+ if not options.proxy:
+ no_log = False
+ # logging.debug('Options: '+str(options.__dict__))
+ bmaj = Bank(bank, options=options, no_log=no_log)
+ check_status = bmaj.check()
+ if not check_status:
+ msg += 'Skip bank ' + options.bank + ': wrong config\n'
+ gres = False
+ continue
+ else:
+ msg += 'Bank repair request sent for ' + options.bank + '\n'
+ if not options.proxy:
+ res = bmaj.repair()
+ Notify.notifyBankAction(bmaj)
+ else:
+ res = biomaj_bank_repair_request(options, config)
+ if not res:
+ msg += 'Failed to send repair request for ' + options.bank + '\n'
+ gres = False
+
+ if not gres:
+ return (False, msg)
+ return (True, msg)
+
+
def biomaj_bank_update(options, config):
'''
Update a bank
@@ -953,4 +997,7 @@ def biomaj_client_action(options, config=None):
if options.dataimport:
return biomaj_data_import(options, config)
+ if options.repair:
+ return biomaj_bank_repair(options, config)
+
return (False, "no option match")
=====================================
requirements.txt
=====================================
@@ -7,4 +7,5 @@ python-consul
prometheus_client>=0.0.18
requests
biomaj-core>=3.0.16
-biomaj>=3.1.7
+biomaj>=3.1.14
+flask-cors
=====================================
setup.py
=====================================
@@ -21,7 +21,7 @@ config = {
'url': 'http://biomaj.genouest.org',
'download_url': 'http://biomaj.genouest.org',
'author_email': 'olivier.sallou at irisa.fr',
- 'version': '3.0.20',
+ 'version': '3.0.22',
'classifiers': [
# How mature is this project? Common values are
# 3 - Alpha
@@ -51,7 +51,8 @@ config = {
'flask',
'python-consul',
'prometheus_client>=0.0.18',
- 'requests'
+ 'requests',
+ 'flask-cors'
],
'tests_require': ['nose', 'mock'],
'test_suite': 'nose.collector',
View it on GitLab: https://salsa.debian.org/med-team/biomaj3-daemon/-/commit/500e1c6631f25b83fd97074c9acdb79cfba5eb63
--
View it on GitLab: https://salsa.debian.org/med-team/biomaj3-daemon/-/commit/500e1c6631f25b83fd97074c9acdb79cfba5eb63
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20210117/f9927a3b/attachment-0001.html>
More information about the debian-med-commit
mailing list