"Fossies" - the Fresh Open Source Software Archive

Member "monasca-events-api-2.0.0/monasca_events_api/app/core/request.py" (14 Oct 2020, 1928 Bytes) of package /linux/misc/openstack/monasca-events-api-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "request.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.2.0_vs_0.3.0.

    1 # Copyright 2018 FUJITSU LIMITED
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 import falcon
   16 from monasca_common.policy import policy_engine as policy
   17 from oslo_log import log
   18 
   19 from monasca_events_api.app.core import request_contex
   20 from monasca_events_api.app.core import validation
   21 from monasca_events_api import policies
   22 
   23 LOG = log.getLogger(__name__)
   24 policy.POLICIES = policies
   25 
   26 
   27 class Request(falcon.Request):
   28     """Variation of falcon. Request with context.
   29 
   30     Following class enhances :py:class:`falcon.Request` with
   31     :py:class:`context.CustomRequestContext`
   32     """
   33 
   34     def __init__(self, env, options=None):
   35         """Init an Request class."""
   36         super(Request, self).__init__(env, options)
   37         self.context = \
   38             request_contex.RequestContext.from_environ(self.env)
   39         self.is_admin = policy.check_is_admin(self.context)
   40         self.project_id = self.context.project_id
   41 
   42     def validate(self, content_types):
   43         """Performs common request validation
   44 
   45         Validation checklist (in that order):
   46 
   47         * :py:func:`validation.validate_content_type`
   48 
   49         :param content_types: allowed content-types handler supports
   50         :type content_types: list
   51         :raises Exception: if any of the validation fails
   52 
   53         """
   54         validation.validate_content_type(self, content_types)
   55 
   56     def can(self, action, target=None):
   57         return self.context.can(action, target)