예제 #1
0
def api_key(comment, remove, echo):
    if echo:
        for i in ApiKey.objects():
            print(i.apikey, i.comment)
    elif remove:
        for i in ApiKey.objects(apikey=apikey):
            i.delete()
    elif comment:
        key = uuid4().hex
        ApiKey(apikey=key, comment=comment).save()
        print(key)
    else:
        print("comment or print required")
def verify_api_key():
    db_key = ApiKey.get_key()

    if db_key is None:
        db_key = ask_api_key()
    api_key = db_key.key
    verified = db_key.verified

    if verified != True:
        while test_connection(api_key) != True:
            api_key = ask_api_key()
        ApiKey.update_key_to_valid()

    print('api-key verification complete')
    return api_key
예제 #3
0
파일: auth.py 프로젝트: geudrik/homestack
def map_api_key_to_user(key):
    """
    Take an input of an API key and return a User instance
    """

    key = key.strip()
    user = None

    # Attempt to get a user instance from an apikey row
    row = ApiKey.filter_by(api_key=key).first()
    if row:
        user = row.user

    return user
예제 #4
0
 def decorated_function(*args, **kwargs):
     print(request.headers)
     if 'Apikey' in request.headers:
         if ApiKey.objects(apikey=request.headers.get('Apikey')).first():
             return f(*args, **kwargs)
     return abort(403)
def ask_api_key():
    # https://stackoverflow.com/questions/4960208/python-2-7-getting-user-input-and-manipulating-as-string-without-quotations
    api_key = str(raw_input('Enter valid api-key: '))
    final_key = ApiKey.save_key(api_key)
    return final_key