Commit c08b9743 authored by Janis Streib's avatar Janis Streib 🦉
Browse files

ADD: netdb_required wrapper and used it in macfinder

parent 779b3554
Pipeline #160232 passed with stages
in 12 minutes and 2 seconds
from . import macfinder
from net_suite.model import *
from net_suite import app
from net_suite.views import api_login_required, get_db_conn, db
from net_suite.views import api_netdb_required, get_db_conn, db
import requests
from flask import render_template, request, flash, jsonify, redirect, url_for
from flask import request, jsonify
import datetime
import re
import collections
......@@ -37,7 +37,7 @@ class MacFinderJob(DBObject):
@macfinder.route('/create_job', methods=['post'])
@api_login_required
@api_netdb_required
def create_job():
if not len(format_mac(request.json['mac'])) == 17:
return jsonify({'success': False, 'error': 'invalid_mac'}), 400
......@@ -73,7 +73,7 @@ def create_job():
@macfinder.route('/jobs')
@api_login_required
@api_netdb_required
def jobs():
s = request.environ['beaker.session']
session = requests.Session()
......@@ -84,7 +84,7 @@ def jobs():
@macfinder.route('/poll/<job_id>')
@api_login_required
@api_netdb_required
def poll(job_id):
s = request.environ['beaker.session']
session = requests.session()
......
......@@ -52,6 +52,17 @@ def api_login_required(f):
return decorated_function
@api_login_required
def api_netdb_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if 'login_token' not in request.environ['beaker.session'] or request.environ['login_token'] is None:
return jsonify({'error': 'Authentication required'}), 403
return f(*args, **kwargs)
return decorated_function
def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
......@@ -69,7 +80,8 @@ def main():
@app.route('/api/system/info')
def api_sysinfo():
return jsonify({'version': VERSION, 'version_name': app.config.get('VERSION_NAME', 'KEIN APFEL!'), 'mods': MODS, 'host_oper_mode': db.host_omdl, 'js_mods': app.config.get('JS_MODULES')})
return jsonify({'version': VERSION, 'version_name': app.config.get('VERSION_NAME', 'KEIN APFEL!'), 'mods': MODS,
'host_oper_mode': db.host_omdl, 'js_mods': app.config.get('JS_MODULES')})
@app.route('/api/session')
......@@ -108,5 +120,3 @@ def handle_generic(e):
if hasattr(e, 'details'):
return jsonify({'type': 'generic_error', 'error': e.details}), 500
return jsonify({'type': 'generic_error', 'error': str(e)}), 500
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment