# Path: aodh/api/controllers/v2/base.py
# class ClientSideError(wsme.exc.ClientSideError):
# class ProjectNotAuthorized(ClientSideError):
# class AdvEnum(wtypes.wsproperty):
# class Base(wtypes.DynamicBase):
# class Query(Base):
# class AlarmNotFound(ClientSideError):
# class AlarmRule(Base):
#     def __init__(self, error, status_code=400):
#     def __init__(self, id, aspect='project'):
#     def __init__(self, name, *args, **kwargs):
#     def _get(self, parent):
#     def _set(self, parent, value):
#     def from_db_model(cls, m):
#     def from_db_and_links(cls, m, links):
#     def as_dict(self, db_model):
#     def as_dict_from_keys(self, keys):
#     def to_dict(self):
#     def get_op(self):
#     def set_op(self, value):
#     def __repr__(self):
#     def sample(cls):
#     def as_dict(self):
#     def get_value(self, forced_type=None):
#     def __init__(self, alarm, auth_project):
#     def validate_alarm(alarm):
#     def create_hook(alarm):
#     def update_hook(alarm):
# 
# Path: aodh/api/rbac.py
# def target_from_segregation_rule(headers, enforcer):
# def enforce(policy_name, headers, enforcer, target):
# def get_limited_to(headers, enforcer):
# def get_limited_to_project(headers, enforcer):
# def is_admin(headers):


from oslo_log import log
from pecan import rest
from wsme import types as wtypes
from aodh.api.controllers.v2 import base
from aodh.api import rbac
import pecan
import wsme
import wsmeext.pecan as wsme_pecan
#    limitations under the License.


LOG = log.getLogger(__name__)
ALLOWED_RESOURCES = ('alarms',)


class Quota(base.Base):
    resource = wtypes.wsattr(wtypes.Enum(str, *ALLOWED_RESOURCES),
                             mandatory=True)
    limit = wsme.wsattr(wtypes.IntegerType(minimum=-1), mandatory=True)


class Quotas(base.Base):
    project_id = wsme.wsattr(wtypes.text, mandatory=True)
    quotas = [Quota]


class QuotasController(rest.RestController):
    """Quota API controller."""

    @wsme_pecan.wsexpose(Quotas, str, ignore_extra_args=True)
    def get_all(self, project_id=None):
        """Get resource quotas of a project.

        - If no project given, get requested user's quota.
        - Admin user can get resource quotas of any project.
        """
        request_project = pecan.request.headers.get('X-Project-Id')
        project_id = project_id if project_id else request_project

# Path: aodh/api/controllers/v2/base.py
# class ClientSideError(wsme.exc.ClientSideError):
# class ProjectNotAuthorized(ClientSideError):
# class AdvEnum(wtypes.wsproperty):
# class Base(wtypes.DynamicBase):
# class Query(Base):
# class AlarmNotFound(ClientSideError):
# class AlarmRule(Base):
#     def __init__(self, error, status_code=400):
#     def __init__(self, id, aspect='project'):
#     def __init__(self, name, *args, **kwargs):
#     def _get(self, parent):
#     def _set(self, parent, value):
#     def from_db_model(cls, m):
#     def from_db_and_links(cls, m, links):
#     def as_dict(self, db_model):
#     def as_dict_from_keys(self, keys):
#     def to_dict(self):
#     def get_op(self):
#     def set_op(self, value):
#     def __repr__(self):
#     def sample(cls):
#     def as_dict(self):
#     def get_value(self, forced_type=None):
#     def __init__(self, alarm, auth_project):
#     def validate_alarm(alarm):
#     def create_hook(alarm):
#     def update_hook(alarm):
# 
# Path: aodh/api/rbac.py
# def target_from_segregation_rule(headers, enforcer):
# def enforce(policy_name, headers, enforcer, target):
# def get_limited_to(headers, enforcer):
# def get_limited_to_project(headers, enforcer):
# def is_admin(headers):


# Path: aodh/api/controllers/v2/quotas.py
from oslo_log import log
from pecan import rest
from wsme import types as wtypes
from aodh.api.controllers.v2 import base
from aodh.api import rbac
import pecan
import wsme
import wsmeext.pecan as wsme_pecan

#    limitations under the License.


LOG = log.getLogger(__name__)
ALLOWED_RESOURCES = ('alarms',)


class Quota(base.Base):
    resource = wtypes.wsattr(wtypes.Enum(str, *ALLOWED_RESOURCES),
                             mandatory=True)
    limit = wsme.wsattr(wtypes.IntegerType(minimum=-1), mandatory=True)


class Quotas(base.Base):
    project_id = wsme.wsattr(wtypes.text, mandatory=True)
    quotas = [Quota]


class QuotasController(rest.RestController):
    """Quota API controller."""

    @wsme_pecan.wsexpose(Quotas, str, ignore_extra_args=True)
    def get_all(self, project_id=None):
        """Get resource quotas of a project.

        - If no project given, get requested user's quota.
        - Admin user can get resource quotas of any project.
        """
        request_project = pecan.request.headers.get('X-Project-Id')
        project_id = project_id if project_id else request_project

        is_admin = rbac.is_admin(pecan.request.headers)