Esempio n. 1
0
File: base.py Progetto: vindeka/gate
def get_case_info(env, app, gate_source=None):
    """
    Get the info structure for an case, based on env and app.
    This is useful to middlewares.
    Note: This call bypasses auth. Success does not imply that the
          request has authorization to the account_info.
    """
    cache = cache_from_env(env)
    if not cache:
        return None
    (version, case, evidence, _) = \
        split_path(env['PATH_INFO'], 2, 4, True)
    cache_key = get_case_memcache_key(case)
    # Use a unique environment cache key per case.  If you copy this env
    # to make a new request, it won't accidentally reuse the old account info
    env_key = 'gate.%s' % cache_key
    if env_key not in env:
        case_info = cache.get(cache_key)
        if not case_info:
            resp = make_pre_authed_request(
                env, 'HEAD', '/%s/%s' % (version, case),
                gate_source=gate_source,
            ).get_response(app)
            case_info = headers_to_case_info(
                resp.headers, resp.status_int)
        env[env_key] = case_info
    return env[env_key]
Esempio n. 2
0
    def get_controller(self, path):
        """
        Get the controller to handle a request.

        :param path: path from request
        :returns: tuple of (controller class, path dictionary)

        :raises: ValueError (thrown by split_path) if given invalid path
        """
        version, case, evidence, obj = split_path(path, 1, 4, True)
        d = dict(version=version,
                 case_name=case,
                 evidence_name=evidence,
                 obj_name=obj)
        if obj and evidence and case:
            return ObjectController, d
        elif evidence and case:
            return ContainerController, d
        elif case and not container and not obj:
            return CaseController, d
Esempio n. 3
0
    def get_controller(self, path):
        """
        Get the controller to handle a request.

        :param path: path from request
        :returns: tuple of (controller class, path dictionary)

        :raises: ValueError (thrown by split_path) if given invalid path
        """
        version, case, evidence, obj = split_path(path, 1, 4, True)
        d = dict(version=version,
                 case_name=case,
                 evidence_name=evidence,
                 obj_name=obj)
        if obj and evidence and case:
            return ObjectController, d
        elif evidence and case:
            return ContainerController, d
        elif case and not container and not obj:
            return CaseController, d
        return None, d
Esempio n. 4
0
    def split_path(self, minsegs=1, maxsegs=None, rest_with_last=False):
        """
        Validate and split the Request's path.

        **Examples**::

            ['a'] = split_path('/a')
            ['a', None] = split_path('/a', 1, 2)
            ['a', 'c'] = split_path('/a/c', 1, 2)
            ['a', 'c', 'o/r'] = split_path('/a/c/o/r', 1, 3, True)

        :param path: HTTP Request path to be split
        :param minsegs: Minimum number of segments to be extracted
        :param maxsegs: Maximum number of segments to be extracted
        :param rest_with_last: If True, trailing data will be returned as part
                               of last segment.  If False, and there is
                               trailing data, raises ValueError.
        :returns: list of segments with a length of maxsegs (non-existant
                  segments will return as None)
        :raises: ValueError if given an invalid path
        """
        return split_path(
            self.environ.get('SCRIPT_NAME', '') + self.environ['PATH_INFO'],
            minsegs, maxsegs, rest_with_last)