# Path: amivapi/auth/auth.py
# class AdminOnlyAuth(AmivTokenAuth):
#     """Auth class to use if no access at all is given for non admins of a
#     resource."""
#     def create_user_lookup_filter(self, user):
#         """If this hook gets called, the user is not an admin for this resource.
#         Therefore no results should be given. To give a more precise error
#         message, we abort. Otherwise normal users would just see an empty list.
#         """
#         return None
# 
# Path: amivapi/utils.py
# def register_domain(app, domain):
#     """Add all resources in a domain to the app.
# 
#     The domain has to be deep-copied first because eve will modify it
#     (since it heavily relies on setdefault()), which can cause problems
#     especially in test environments, since the defaults don't get properly
#     erase sometimes.
# 
#     TODO: Make tests better maybe so this is no problem anymore?
# 
#     Args:
#         app (Eve object): The app to extend
#         domain (dict): The domain to be added to the app, will not be changed
#     """
#     domain_copy = deepcopy(domain)
# 
#     for resource, settings in domain_copy.items():
#         # Add default for the resource title:
#         # Capitalize like Eve does with item titles
#         settings.setdefault('resource_title', resource.capitalize())
# 
#         app.register_resource(resource, settings)
#         _better_schema_defaults(app, resource, settings)


from datetime import datetime as dt
from flask import abort, current_app, g
from amivapi.auth.auth import AdminOnlyAuth
from amivapi.utils import register_domain
    from secrets import token_urlsafe
    from amivapi.utils import token_urlsafe
                           {'$set': {'_updated': new_time}})

        if permission == 'read':
            g.resource_admin_readonly = True
        elif permission == 'readwrite':
            g.resource_admin = True
        elif g.get('auth_required'):
            abort(403, "The API key exists but does not grant the required "
                       "permissions.")


description = ("""
API keys can be used to give permissions to other applications.

When creating an API key, permissions have to be provided as an object with
the resources as keys and the respective permissions as values, e.g.

```
{
    "users": "read",
    "sessions": "readwrite"
}
```

(this would grant the API key rights to see all users and see
and modify/delete all sessions).

> **IMPORTANT: The most powerful permission**
>
> If you grant an API key `readwrite` permissions to API keys, this key will

# Path: amivapi/auth/auth.py
# class AdminOnlyAuth(AmivTokenAuth):
#     """Auth class to use if no access at all is given for non admins of a
#     resource."""
#     def create_user_lookup_filter(self, user):
#         """If this hook gets called, the user is not an admin for this resource.
#         Therefore no results should be given. To give a more precise error
#         message, we abort. Otherwise normal users would just see an empty list.
#         """
#         return None
# 
# Path: amivapi/utils.py
# def register_domain(app, domain):
#     """Add all resources in a domain to the app.
# 
#     The domain has to be deep-copied first because eve will modify it
#     (since it heavily relies on setdefault()), which can cause problems
#     especially in test environments, since the defaults don't get properly
#     erase sometimes.
# 
#     TODO: Make tests better maybe so this is no problem anymore?
# 
#     Args:
#         app (Eve object): The app to extend
#         domain (dict): The domain to be added to the app, will not be changed
#     """
#     domain_copy = deepcopy(domain)
# 
#     for resource, settings in domain_copy.items():
#         # Add default for the resource title:
#         # Capitalize like Eve does with item titles
#         settings.setdefault('resource_title', resource.capitalize())
# 
#         app.register_resource(resource, settings)
#         _better_schema_defaults(app, resource, settings)


# Path: amivapi/auth/apikeys.py
from datetime import datetime as dt
from flask import abort, current_app, g
from amivapi.auth.auth import AdminOnlyAuth
from amivapi.utils import register_domain
    from secrets import token_urlsafe
    from amivapi.utils import token_urlsafe

                           {'$set': {'_updated': new_time}})

        if permission == 'read':
            g.resource_admin_readonly = True
        elif permission == 'readwrite':
            g.resource_admin = True
        elif g.get('auth_required'):
            abort(403, "The API key exists but does not grant the required "
                       "permissions.")


description = ("""
API keys can be used to give permissions to other applications.

When creating an API key, permissions have to be provided as an object with
the resources as keys and the respective permissions as values, e.g.

```
{
    "users": "read",
    "sessions": "readwrite"
}
```

(this would grant the API key rights to see all users and see
and modify/delete all sessions).

> **IMPORTANT: The most powerful permission**
>
> If you grant an API key `readwrite` permissions to API keys, this key will

> be able to create new API keys with any permissions and also modify it's