# 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
                'example': 'Xfh3abXzLoezpwO9WT7oRw',
            },
            'permissions': {
                'description': 'The permissions the API key grants. The value '
                               'is an object with resources as keys and the '
                               'permissions as a values.',
                'example': {
                    'users': 'read',
                    'beverages': 'readwrite',
                },

                'type': 'dict',
                'keysrules': {'type': 'string',
                              'api_resources': True},
                'valuesrules': {'type': 'string',
                                'allowed': ['read', 'readwrite']},
                'required': True,
            }
        },
    }
}


def generate_tokens(items):
    for item in items:
        item['token'] = token_urlsafe()


def init_apikeys(app):
    """Register API Key resource and add auth hook."""

# 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

                'example': 'Xfh3abXzLoezpwO9WT7oRw',
            },
            'permissions': {
                'description': 'The permissions the API key grants. The value '
                               'is an object with resources as keys and the '
                               'permissions as a values.',
                'example': {
                    'users': 'read',
                    'beverages': 'readwrite',
                },

                'type': 'dict',
                'keysrules': {'type': 'string',
                              'api_resources': True},
                'valuesrules': {'type': 'string',
                                'allowed': ['read', 'readwrite']},
                'required': True,
            }
        },
    }
}


def generate_tokens(items):
    for item in items:
        item['token'] = token_urlsafe()


def init_apikeys(app):
    """Register API Key resource and add auth hook."""

    register_domain(app, apikeydomain)