Esempio n. 1
0
    def post(self):
        cli = Client(remote, pull_token())
        if not request.data:
            return jsonify_unknown('missing data', 400)

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

        try:
            r = cli.tokens_create(request.data)

        except AuthError:
            return jsonify_unauth()

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

        if not r:
            return jsonify_unknown('create failed', 400)

        return jsonify_success(r, code=201)
Esempio n. 2
0
    def post(self):
        cli = Client(remote, pull_token())
        if not request.data:
            return jsonify_unknown('missing data', 400)

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

        try:
            r = cli.tokens_create(request.data)

        except AuthError:
            return jsonify_unauth()

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

        if not r:
            return jsonify_unknown('create failed', 400)

        return jsonify_success(r, code=201)
Esempio n. 3
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
Esempio 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