Exemplo n.º 1
0
 def test_build_api_user(self):
     meta = {'usage': 'individual CV', 'email': '', 'notes': '', 'api_limit': '', 'api_key_owner': ''}
     (new_api_doc, new_api_key) = api_user.build_api_user("SFU", 1000, **meta)
     print new_api_doc
     expected = self.sample_user_api_doc
     assert_equals(new_api_doc["current_key"], new_api_key)
     assert_equals(new_api_doc["meta"], expected["meta"])
Exemplo n.º 2
0
def key():
    """ Generate a new api key and store api key info in a db doc """
    meta = request.json

    password = meta["password"]
    del(meta["password"])
    if password != os.getenv("API_KEY"):
        abort(403)

    prefix = meta["prefix"]
    del(meta["prefix"])

    max_registered_items = meta["max_registered_items"]
    del(meta["max_registered_items"])

    (api_user_doc, new_api_key) = api_user.build_api_user(prefix, max_registered_items, **meta)
    mydao.db.save(api_user_doc)

    resp = make_response(json.dumps({"api_key":new_api_key}, indent=4), 200)
    resp.mimetype = "application/json"
    return resp