diff options
author | John Estabrook <jestabro@vyos.io> | 2020-05-06 17:43:33 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2020-05-06 19:12:32 -0500 |
commit | c4312498ebe0643061f1d06ad9655d49fb9d9af7 (patch) | |
tree | 96656e4c4cfff320e210db361f5c51e1f3294428 /src/services/vyos-http-api-server | |
parent | dbe9f73cc9180b5c0d06007476d7120cde51725d (diff) | |
download | vyos-1x-c4312498ebe0643061f1d06ad9655d49fb9d9af7.tar.gz vyos-1x-c4312498ebe0643061f1d06ad9655d49fb9d9af7.zip |
http api: T2395: replace bottle with flask as microframework
Diffstat (limited to 'src/services/vyos-http-api-server')
-rwxr-xr-x | src/services/vyos-http-api-server | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index 5cad67eb7..4a653bb66 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -26,7 +26,7 @@ import signal import vyos.config -import bottle +from flask import Flask, request from functools import wraps @@ -37,7 +37,7 @@ from vyos.config import VyOSError DEFAULT_CONFIG_FILE = '/etc/vyos/http-api.conf' CFG_GROUP = 'vyattacfg' -app = bottle.default_app() +app = Flask(__name__) # Giant lock! lock = threading.Lock() @@ -55,9 +55,8 @@ def check_auth(key_list, key): return id def error(code, msg): - bottle.response.status = code resp = {"success": False, "error": msg, "data": None} - return json.dumps(resp) + return json.dumps(resp), code def success(data): resp = {"success": True, "data": data, "error": None} @@ -66,7 +65,7 @@ def success(data): def get_command(f): @wraps(f) def decorated_function(*args, **kwargs): - cmd = bottle.request.forms.get("data") + cmd = request.form.get("data") if not cmd: return error(400, "Non-empty data field is required") try: @@ -80,7 +79,7 @@ def get_command(f): def auth_required(f): @wraps(f) def decorated_function(*args, **kwargs): - key = bottle.request.forms.get("key") + key = request.form.get("key") api_keys = app.config['vyos_keys'] id = check_auth(api_keys, key) if not id: @@ -89,7 +88,7 @@ def auth_required(f): return decorated_function -@app.route('/configure', method='POST') +@app.route('/configure', methods=['POST']) @get_command @auth_required def configure_op(commands): @@ -97,7 +96,7 @@ def configure_op(commands): env = session.get_session_env() config = vyos.config.Config(session_env=env) - strict_field = bottle.request.forms.get("strict") + strict_field = request.form.get("strict") if strict_field == "true": strict = True else: @@ -192,7 +191,7 @@ def configure_op(commands): else: return success(None) -@app.route('/retrieve', method='POST') +@app.route('/retrieve', methods=['POST']) @get_command @auth_required def retrieve_op(command): @@ -241,7 +240,7 @@ def retrieve_op(command): return success(res) -@app.route('/config-file', method='POST') +@app.route('/config-file', methods=['POST']) @get_command @auth_required def config_file_op(command): @@ -276,7 +275,7 @@ def config_file_op(command): return success(res) -@app.route('/image', method='POST') +@app.route('/image', methods=['POST']) @get_command @auth_required def image_op(command): @@ -311,7 +310,7 @@ def image_op(command): return success(res) -@app.route('/generate', method='POST') +@app.route('/generate', methods=['POST']) @get_command @auth_required def generate_op(command): @@ -339,7 +338,7 @@ def generate_op(command): return success(res) -@app.route('/show', method='POST') +@app.route('/show', methods=['POST']) @get_command @auth_required def show_op(command): @@ -396,4 +395,4 @@ if __name__ == '__main__': signal.signal(signal.SIGTERM, sig_handler) - bottle.run(app, host=server_config["listen_address"], port=server_config["port"], debug=True) + app.run(host=server_config["listen_address"], port=server_config["port"], debug=True) |