当前位置: 首页>>代码示例>>Python>>正文


Python Response.headers["x-storage-url"]方法代码示例

本文整理汇总了Python中swift.common.swob.Response.headers["x-storage-url"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["x-storage-url"]方法的具体用法?Python Response.headers["x-storage-url"]怎么用?Python Response.headers["x-storage-url"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.swob.Response的用法示例。


在下文中一共展示了Response.headers["x-storage-url"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_get_token

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["x-storage-url"] [as 别名]

#.........这里部分代码省略.........
            GET <auth-prefix>/v1.0
                X-Auth-User: <act>:<usr>  or  X-Storage-User: <act>:<usr>
                X-Auth-Key: <key>         or  X-Storage-Pass: <key>

        On successful authentication, the response will have X-Auth-Token and
        X-Storage-Token set to the token to use with Swift and X-Storage-URL
        set to the URL to the default Swift cluster to use.

        :param req: The swob.Request to process.
        :returns: swob.Response, 2xx on success with data set as explained
                  above.
        """
        # Validate the request info
        try:
            pathsegs = split_path(req.path_info, 1, 3, True)
        except ValueError:
            self.logger.increment("errors")
            return HTTPNotFound(request=req)
        if pathsegs[0] == "v1" and pathsegs[2] == "auth":
            account = pathsegs[1]
            user = req.headers.get("x-storage-user")
            if not user:
                user = req.headers.get("x-auth-user")
                if not user or ":" not in user:
                    self.logger.increment("token_denied")
                    auth = 'Swift realm="%s"' % account
                    return HTTPUnauthorized(request=req, headers={"Www-Authenticate": auth})
                account2, user = user.split(":", 1)
                if account != account2:
                    self.logger.increment("token_denied")
                    auth = 'Swift realm="%s"' % account
                    return HTTPUnauthorized(request=req, headers={"Www-Authenticate": auth})
            key = req.headers.get("x-storage-pass")
            if not key:
                key = req.headers.get("x-auth-key")
        elif pathsegs[0] in ("auth", "v1.0"):
            user = req.headers.get("x-auth-user")
            if not user:
                user = req.headers.get("x-storage-user")
            if not user or ":" not in user:
                self.logger.increment("token_denied")
                auth = 'Swift realm="unknown"'
                return HTTPUnauthorized(request=req, headers={"Www-Authenticate": auth})
            account, user = user.split(":", 1)
            key = req.headers.get("x-auth-key")
            if not key:
                key = req.headers.get("x-storage-pass")
        else:
            return HTTPBadRequest(request=req)
        if not all((account, user, key)):
            self.logger.increment("token_denied")
            realm = account or "unknown"
            return HTTPUnauthorized(request=req, headers={"Www-Authenticate": 'Swift realm="%s"' % realm})
        # Authenticate user
        account_user = account + ":" + user
        if account_user not in self.users:
            self.logger.increment("token_denied")
            auth = 'Swift realm="%s"' % account
            return HTTPUnauthorized(request=req, headers={"Www-Authenticate": auth})
        if self.users[account_user]["key"] != key:
            self.logger.increment("token_denied")
            auth = 'Swift realm="unknown"'
            return HTTPUnauthorized(request=req, headers={"Www-Authenticate": auth})
        account_id = self.users[account_user]["url"].rsplit("/", 1)[-1]
        # Get memcache client
        memcache_client = cache_from_env(req.environ)
        if not memcache_client:
            raise Exception("Memcache required")
        # See if a token already exists and hasn't expired
        token = None
        memcache_user_key = "%s/user/%s" % (self.reseller_prefix, account_user)
        candidate_token = memcache_client.get(memcache_user_key)
        if candidate_token:
            memcache_token_key = "%s/token/%s" % (self.reseller_prefix, candidate_token)
            cached_auth_data = memcache_client.get(memcache_token_key)
            if cached_auth_data:
                expires, old_groups = cached_auth_data
                old_groups = old_groups.split(",")
                new_groups = self._get_user_groups(account, account_user, account_id)

                if expires > time() and set(old_groups) == set(new_groups.split(",")):
                    token = candidate_token
        # Create a new token if one didn't exist
        if not token:
            # Generate new token
            token = "%stk%s" % (self.reseller_prefix, uuid4().hex)
            expires = time() + self.token_life
            groups = self._get_user_groups(account, account_user, account_id)
            # Save token
            memcache_token_key = "%s/token/%s" % (self.reseller_prefix, token)
            memcache_client.set(memcache_token_key, (expires, groups), time=float(expires - time()))
            # Record the token with the user info for future use.
            memcache_user_key = "%s/user/%s" % (self.reseller_prefix, account_user)
            memcache_client.set(memcache_user_key, token, time=float(expires - time()))
        resp = Response(request=req, headers={"x-auth-token": token, "x-storage-token": token})
        url = self.users[account_user]["url"].replace("$HOST", resp.host_url)
        if self.storage_url_scheme != "default":
            url = self.storage_url_scheme + ":" + url.split(":", 1)[1]
        resp.headers["x-storage-url"] = url
        return resp
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:104,代码来源:tempauth.py


注:本文中的swift.common.swob.Response.headers["x-storage-url"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。