Esempio n. 1
0
def apikey_list(user):
    form = new_apikey_form(request.form)
    if request.method == "POST" and form.validate():
        apikey = ApiKey(application=form.application.data, description=form.description.data, user=current_user)
        apikey.gen_key()
        rfk.database.session.add(apikey)
        rfk.database.session.commit()
        form.application.data = ""
        form.description.data = ""
        flash(gettext("Successfully added new apikey"), "success")
    apikeys = ApiKey.query.filter(ApiKey.user == current_user).all()
    return render_template("user/apikeys.html", apikeys=apikeys, form=form)
Esempio n. 2
0
def apikey_list(user):
    form = new_apikey_form(request.form)
    if request.method == 'POST' and form.validate():
        apikey = ApiKey(application=form.application.data,
                        description=form.description.data,
                        user=current_user)
        apikey.gen_key()
        rfk.database.session.add(apikey)
        rfk.database.session.commit()
        form.application.data = ''
        form.description.data = ''
        flash(lazy_gettext('Added Apikey'))
    apikeys = ApiKey.query.filter(ApiKey.user == current_user).all()
    return render_template('user/apikeys.html', apikeys=apikeys, form=form)
Esempio n. 3
0
    def decorated_function(*args, **kwargs):
        def raise_error(text):
            response = jsonify(wrapper(None, 403, text))
            response.status_code = 403
            return response

        if not "key" in request.args:
            return raise_error("api key missing")

        key = request.args.get("key")

        try:
            apikey = ApiKey.check_key(key)
            rfk.database.session.commit()
        except rexc.api.KeyInvalidException:
            return raise_error("api key invalid")
        except rexc.api.KeyDisabledException:
            return raise_error("api key disabled")
        except rexc.api.FastQueryException:
            return raise_error("throttling")
        except:
            return raise_error("unknown error")

        if required_permissions != None:
            for required_permission in required_permissions:
                if not apikey.flag & required_permission:
                    return raise_error(
                        "Flag %s (%i) required" % (ApiKey.FLAGS.name(required_permission), required_permission)
                    )

        g.apikey = apikey

        return f(*args, **kwargs)
Esempio n. 4
0
    def decorated_function(*args, **kwargs):

        def raise_error(text):
            response = jsonify(wrapper(None, 403, text))
            response.status_code = 403
            return response

        if not 'key' in request.args:
            return raise_error('api key missing')

        key = request.args.get('key')

        try:
            apikey = ApiKey.check_key(key)
            rfk.database.session.commit()
        except rexc.api.KeyInvalidException:
            return raise_error('api key invalid')
        except rexc.api.KeyDisabledException:
            return raise_error('api key disabled')
        except rexc.api.FastQueryException:
            return raise_error('throttling')
        except:
            return raise_error('unknown error')

        if required_permissions != None:
            for required_permission in required_permissions:
                if not apikey.flag & required_permission:
                    return raise_error(
                        'Flag %s (%i) required' % (ApiKey.FLAGS.name(required_permission), required_permission))

        g.apikey = apikey

        return f(*args, **kwargs)
Esempio n. 5
0
 def decorated_function(*args, **kwargs):
     
     def raise_error(text):
         response = jsonify(wrapper(None, 403, text))
         response.status_code = 403
         return response
     
     if not request.args.has_key('key'):
         return raise_error('api key missing')
         
     key = request.args.get('key')
     
     try:
         apikey = ApiKey.check_key(key)
     except rexc.api.KeyInvalidException:
         return raise_error('api key invalid')
     except rexc.api.KeyDisabledException:
         return raise_error('api key disabled')
     except rexc.api.FastQueryException:
         return raise_error('throttling')
     except:
         return raise_error('unknown error')
         
     if required_permissions != None:
         for required_permission in required_permissions:
             if not apikey.flag & required_permission:
                 return raise_error('Flag %s (%i) required' % (ApiKey.FLAGS.name(required_permission), required_permission))
     
     g.apikey = apikey
     
     return f(*args, **kwargs)
Esempio n. 6
0
    def setUp(self):
        rfk.init()
        rfk.database.init_db("sqlite://")

        app.template_folder = '../templates/'
        app.static_folder = '../static/'
        app.static_url_path = '/static'
        self.app = app.test_client()

        user_1 = User.add_user('teddydestodes', 'roflmaoblubb')
        user_2 = User.add_user('loom', 'bestes')

        key_1 = ApiKey(application='app_1', description='key_1', user=user_1)
        key_1.gen_key()
        self.key_1 = key_1.key
        key_2 = ApiKey(application='app_2', description='key_2', user=user_2, flag=ApiKey.FLAGS.DISABLED)
        key_2.gen_key()
        self.key_2 = key_2.key
        rfk.database.session.add(key_1, key_2)

        rfk.database.session.commit()
Esempio n. 7
0
    def setUp(self):
        rfk.init()
        rfk.database.init_db("sqlite://")

        app.template_folder = '../templates/'
        app.static_folder = '../static/'
        app.static_url_path = '/static'
        self.app = app.test_client()

        user_1 = User.add_user('teddydestodes', 'roflmaoblubb')
        user_2 = User.add_user('loom', 'bestes')

        key_1 = ApiKey(application='app_1', description='key_1', user=user_1)
        key_1.gen_key()
        self.key_1 = key_1.key
        key_2 = ApiKey(application='app_2', description='key_2', user=user_2, flag=ApiKey.FLAGS.DISABLED)
        key_2.gen_key()
        self.key_2 = key_2.key
        rfk.database.session.add(key_1, key_2)

        rfk.database.session.commit()