Exemplo n.º 1
0
    def get(self):
        cli = Client(remote, pull_token())
        filters = {}

        for f in TOKEN_FILTERS:
            filters[f] = request.args.get(f)

        if current_app.config.get('dummy'):
            return jsonify_success()

        try:
            r = cli.tokens_search(filters)

        except AuthError:
            return jsonify_unauth()

        except Exception as e:
            logger.error(e)
            return jsonify_unknown()

        return jsonify_success(r)
Exemplo n.º 2
0
    def get(self):
        cli = Client(remote, pull_token())
        filters = {}

        for f in TOKEN_FILTERS:
            filters[f] = request.args.get(f)

        if current_app.config.get('dummy'):
            return jsonify_success()

        try:
            r = cli.tokens_search(filters)

        except AuthError:
            return jsonify_unauth()

        except Exception as e:
            logger.error(e)
            return jsonify_unknown()

        return jsonify_success(r)
Exemplo n.º 3
0
def login():
    if request.method == 'GET':
        return render_template('login.html')

    if request.method == 'POST':
        from cifsdk.client.zeromq import ZMQ as Client
        if request.form['token'] == '':
            return render_template('login.html')

        c = Client(remote, HTTPD_TOKEN)
        rv = c.tokens_search({'token': request.form['token']})
        if len(rv) == 0:
            return render_template('login.html', code=401)

        user = rv[0]

        if user['revoked']:
            return render_template('login.html', code=401)

        for e in ['username', 'token', 'admin', 'read', 'write', 'groups']:
            session[e] = user[e]

        return redirect(url_for('/u/search'))
Exemplo n.º 4
0
def tokens():
    cli = Client(remote, pull_token())
    if request.method == 'DELETE':
        try:
            r = cli.tokens_delete(request.data)
        except Exception as e:
            logger.error(e)
            response = jsonify({"message": "failed", "data": []})
            response.status_code = 503
        else:
            response = jsonify({'message': 'success', 'data': r})
            response.status_code = 200
    elif request.method == 'POST':
        if request.data:
            try:
                r = cli.tokens_create(request.data)
            except AuthError:
                response = jsonify({
                    'message': 'admin privs required',
                    'data': []
                })
                response.status_code = 401
            except Exception as e:
                logger.error(e)
                response = jsonify({'message': 'create failed', 'data': []})
                response.status_code = 503
            else:
                if r:
                    response = jsonify({'message': 'success', 'data': r})
                    response.status_code = 200
                else:
                    response = jsonify({
                        'message': 'admin privs required',
                        'data': []
                    })
                    response.status_code = 401
        else:
            response = jsonify({'message': 'create failed', 'data': []})
            response.status_code = 400
    elif request.method == 'PATCH':
        try:
            r = cli.tokens_edit(request.data)
        except AuthError:
            response = jsonify({'message': 'admin privs required', 'data': []})
            response.status_code = 401
        except Exception as e:
            logger.error(e)
            import traceback
            traceback.print_exc()
            response = jsonify({'message': 'create failed', 'data': []})
            response.status_code = 503
        else:
            if r:
                response = jsonify({'message': 'success', 'data': r})
                response.status_code = 200
            else:
                response = jsonify({
                    'message': 'admin privs required',
                    'data': []
                })
                response.status_code = 401
    else:
        filters = {}
        for f in TOKEN_FILTERS:
            filters[f] = request.args.get(f)

        try:
            r = cli.tokens_search(filters)
        except AuthError:
            response = jsonify({"message": "failed", "data": []})
            response.status_code = 401
        except Exception as e:
            logger.error(e)
            response = jsonify({"message": "failed", "data": []})
            response.status_code = 503
        else:
            response = jsonify({'message': 'success', 'data': r})
            response.status_code = 200

    return response
Exemplo n.º 5
0
def tokens():
    cli = Client(remote, pull_token())
    if request.method == 'DELETE':
        try:
            r = cli.tokens_delete(request.data)
        except Exception as e:
            logger.error(e)
            response = jsonify({
                "message": "failed",
                "data": []
            })
            response.status_code = 503
        else:
            response = jsonify({
                'message': 'success',
                'data': r
            })
            response.status_code = 200
    elif request.method == 'POST':
        if request.data:
            try:
                r = cli.tokens_create(request.data)
            except AuthError:
                response = jsonify({
                    'message': 'admin privs required',
                    'data': []
                })
                response.status_code = 401
            except Exception as e:
                logger.error(e)
                response = jsonify({
                    'message': 'create failed',
                    'data': []
                })
                response.status_code = 503
            else:
                if r:
                    response = jsonify({
                        'message': 'success',
                        'data': r
                    })
                    response.status_code = 200
                else:
                    response = jsonify({
                        'message': 'admin privs required',
                        'data': []
                    })
                    response.status_code = 401
        else:
            response = jsonify({
                'message': 'create failed',
                'data': []
            })
            response.status_code = 400
    elif request.method == 'PATCH':
        try:
            r = cli.tokens_edit(request.data)
        except AuthError:
            response = jsonify({
                'message': 'admin privs required',
                'data': []
            })
            response.status_code = 401
        except Exception as e:
            logger.error(e)
            import traceback
            traceback.print_exc()
            response = jsonify({
                'message': 'create failed',
                'data': []
            })
            response.status_code = 503
        else:
            if r:
                response = jsonify({
                    'message': 'success',
                    'data': r
                })
                response.status_code = 200
            else:
                response = jsonify({
                    'message': 'admin privs required',
                    'data': []
                })
                response.status_code = 401
    else:
        filters = {}
        for f in TOKEN_FILTERS:
            filters[f] = request.args.get(f)

        try:
            r = cli.tokens_search(filters)
        except AuthError:
            response = jsonify({
                "message": "failed",
                "data": []
            })
            response.status_code = 401
        except Exception as e:
            logger.error(e)
            response = jsonify({
                "message": "failed",
                "data": []
            })
            response.status_code = 503
        else:
            response = jsonify({
                'message': 'success',
                'data': r
            })
            response.status_code = 200

    return response