Пример #1
0
def get_api_key(request, id):
    if request.method == 'GET':
        key = ApiKey.get_by_id(id)
        return render_json_response(key.to_json())

    if request.method == 'PUT':
        model = simplejson.loads(request.data)
        key = ApiKey.get_by_id(id)
        if not key:
            data = {'api_success': False, 'api_msg': 'ApiKey %s not found' % id}
            return render_json_response(data)
        key.title = model['email']
        key.is_writer = model['is_writer']
        key.put()
        data = {'api_success': True, 'api_msg': 'ApiKey %s updated' % id}
        return render_json_response(data)

    if request.method == 'DELETE':
        key = ApiKey.get_by_id(id)
        if not key:
            data = {'api_success': False, 'api_msg': 'ApiKey %s not found' % id}
            return render_json_response(data)
        key.key.delete()
        data = {'api_success': True, 'api_msg': 'ApiKey %s deleted' % id}
        return render_json_response(data)
Пример #2
0
def create_api_key(request):
    model = simplejson.loads(request.data)
    key = ApiKey(
        email=model['email'],
        is_writer=model['is_writer'])
    key.put()
    data = key.to_json()
    data['api_success'] = True
    return render_json_response(data)
Пример #3
0
 def wrapper(*args, **kwargs):
     api_key = args[0].values.get('public_api_key', False)
     if not api_key:
         api_key = args[0].values.get('private_api_key', False)
     if not api_key:
         res = {'api':{'success': False,
                 'msg': 'Invalid public API key',
                 'function': func.__name__}}
         return render_json_response(res)
     customer = ApiKey.query(ApiKey.public_api_key == api_key).get()
     if not customer:
         customer = ApiKey.query(ApiKey.private_api_key == api_key).get()
         if not customer:
             res = {'api':{'success': False,
                 'msg': 'Oops, you do not have read permission',
                 'function': func.__name__}}
             return render_json_response(res)
     return func(*args, **kwargs)
Пример #4
0
 def checking_right(*args, **kwargs):
     api_key = args[0].values.get('private_api_key', False)
     if not api_key:
         return render_json_response({
             'api_success': False,
             'api_msg': 'Invalid private API key',
             'api_function': func.__name__
         })
     customer = ApiKey.query(ApiKey.private_api_key == api_key).get()
     if not customer or not customer.is_writer:
         return render_json_response({
             'api_success': False,
             'api_msg': 'Oops, you do not have write permission',
             'api_function': func.__name__
         })
     return func(*args, **kwargs)
Пример #5
0
 def wrapper(*args, **kwargs):
     try:
         api_key = args[0].values.get('public_api_key', False)
         if not api_key:
             res = {'api_success': False,
                     'api_msg': 'Invalid public API key',
                     'api_function': func.__name__}
             return render_json_response(res)
         customer = ApiKey.query(ApiKey.public_api_key == api_key).get()
         if not customer:
             res = {'api_success': False,
                 'api_msg': 'Oops, you do not have read permission',
                 'api_function': func.__name__}
             return render_json_response(res)
         return func(*args, **kwargs)
     except Exception, e:
         res = {'api_success': False,
                'api_msg': str(e),
                'api_function': func.__name__}
         logging.error(res)
         return render_json_response(res)
Пример #6
0
def get_api_keys(request):
    api_keys = ApiKey.query()
    return render_json_response([key.to_json() for key in api_keys])