当前位置: 首页>>代码示例>>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']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_get_token

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

#.........这里部分代码省略.........
        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')
                    return HTTPUnauthorized(request=req, headers={'Www-Authenticate':
                                             'Swift realm="%s"' % account})
                account2, user = user.split(':', 1)
                if account != account2:
                    self.logger.increment('token_denied')
                    return HTTPUnauthorized(request=req, headers=
                                            {'Www-Authenticate':
                                             'Swift realm="%s"' % account})
            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:
                self.logger.increment('token_denied')
                return HTTPUnauthorized(request=req, headers=
                                        {'Www-Authenticate':
                                         'Swift realm="unknown"'})
            account = user
        else:
            return HTTPBadRequest(request=req)
        if not all((account, user)):
            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
        if account_user in self.admins:
            key = req.headers.get('x-auth-key')
            if not key:
                key = req.headers.get('x-storage-pass')
            if self.admins[account_user]['passwd'] != key:
                self.logger.increment('token_denied')
                return HTTPUnauthorized(request=req, headers=
                                    {'Www-Authenticate':
                                     'Swift realm="unknown"'})
        elif account_user not in self.users and account_user not in self.admins:
            self.logger.increment('token_denied')
            return HTTPUnauthorized(request=req, headers=
                                    {'Www-Authenticate': 'Swift realm="%s"' % account})
        # 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_account = old_groups
                new_account = account_user
                if expires > time() and set(old_account) == set(new_account):
                    token = candidate_token
        if not token:
            # Generate new token
            token = '%stk%s' % (self.reseller_prefix, uuid4().hex)
            expires = time() + self.token_life
            # Save token
            # groups = self._get_user_groups(account, account_user,account_id)
            memcache_token_key = '%s/token/%s' % (self.reseller_prefix, token)
            memcache_client.set(memcache_token_key, (expires, account),
                                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})
        if account_user in self.admins:
            url = self.admins[account_user]['url'].replace('$HOST', resp.host_url)
        else:
            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
        # resp.headers['x-cache'] = cached_auth_data add this line will be 500 error when you apply token the first time.
        return resp
开发者ID:hbhdytf,项目名称:mac,代码行数:104,代码来源:tempauth.py

示例2: handle_get_token

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers['x-storage-url'] [as 别名]
    def handle_get_token(self, req):
        """
        Handles the various `request for token and service end point(s)` calls.
        There are various formats to support the various auth servers in the
        past. Examples::

            GET <auth-prefix>/v1/<act>/auth
                X-Auth-User: <act>:<usr>  or  X-Storage-User: <usr>
                X-Auth-Key: <key>         or  X-Storage-Pass: <key>
            GET <auth-prefix>/auth
                X-Auth-User: <act>:<usr>  or  X-Storage-User: <act>:<usr>
                X-Auth-Key: <key>         or  X-Storage-Pass: <key>
            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
        self.logger.info('CheckPoint HGT 1')
        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':
            ## 
            self.logger.info('CheckPoint HGT 2')
            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')
                    return HTTPUnauthorized(request=req, headers=
                                            {'Www-Authenticate':
                                             'Swift realm="%s"' % account})
                account2, user = user.split(':', 1)
                if account != account2:
                    self.logger.increment('token_denied')
                    return HTTPUnauthorized(request=req, headers=
                                            {'Www-Authenticate':
                                             'Swift realm="%s"' % account})
            key = req.headers.get('x-storage-pass')
            if not key:
                key = req.headers.get('x-auth-key')
        elif pathsegs[0] in ('auth', 'v1.0'):
            self.logger.info('CheckPoint HGT 3')
            user = req.headers.get('x-auth-user')
            if not user:
                user = req.headers.get('x-storage-user')
            if not user:
                self.logger.increment('token_denied')
                return HTTPUnauthorized(request=req, headers=
                                        {'Www-Authenticate':
                                         'Swift realm="unknown"'})
            #account, user = user.split(':', 1)
            key = req.headers.get('x-auth-key')
            if not key:
                key = req.headers.get('x-storage-pass')

            self.logger.info('User = ' + user)
            self.logger.info('Key = ' +key)
        else:
            return HTTPBadRequest(request=req)
        if not all((user, key)):
            self.logger.increment('token_denied')
            realm = account or 'unknown'
            return HTTPUnauthorized(request=req, headers={'Www-Authenticate':
                                                          'Swift realm="%s"' %
                                                          realm})
        # Authenticate user

        #######################################################################################
        ######## CHECK IN MEMCACHE ############################################################
        #######################################################################################
        account_user = user
        memcache_client = cache_from_env(req.environ)
        if not memcache_client:
            raise Exception('Memcache required')

        memcache_user_key = '%s/user/%s/key/%s' % (self.reseller_prefix, user, key)
        candidate_token = memcache_client.get(memcache_user_key)
        if candidate_token:
            self.logger.info('Candidate token found in memcache. Content is :' + candidate_token)
            try:
                token, tenant, expiry = candidate_token.split('&')
                if all((token, tenant, expiry)):
                    if float(expiry) > time():
                        resp = Response(request=req, headers={'x-auth-token': token, 'x-storage-token': token})
                        resp.headers['x-storage-url'] = 'http://controller:8080/v1/AUTH_'+tenant
                        return resp
            except ValueError:
                self.logger.info('Error parsing')
#.........这里部分代码省略.........
开发者ID:FINESCE,项目名称:HybridCloudDataManagement,代码行数:103,代码来源:customauth.py

示例3: handle_get_token

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

#.........这里部分代码省略.........
                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, minsegs=1, maxsegs=3,
                                  rest_with_last=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')
                    return HTTPUnauthorized(request=req)
                account2, user = user.split(':', 1)
                if account != account2:
                    self.logger.increment('token_denied')
                    return HTTPUnauthorized(request=req)
            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')
                return HTTPUnauthorized(request=req)
            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')
            return HTTPUnauthorized(request=req)
        # Authenticate user
        account_user = account + ':' + user
        if account_user not in self.users:
            self.logger.increment('token_denied')
            return HTTPUnauthorized(request=req)
        if self.users[account_user]['key'] != key:
            self.logger.increment('token_denied')
            return HTTPUnauthorized(request=req)
        # 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, groups = cached_auth_data
                if expires > time():
                    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 = [account, account_user]
            groups.extend(self.users[account_user]['groups'])
            if '.admin' in groups:
                groups.remove('.admin')
                account_id = self.users[account_user]['url'].rsplit('/', 1)[-1]
                groups.append(account_id)
            groups = ','.join(groups)
            # Save token
            memcache_token_key = '%s/token/%s' % (self.reseller_prefix, token)
            memcache_client.set(memcache_token_key, (expires, groups),
                                timeout=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,
                                timeout=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:,项目名称:,代码行数:104,代码来源:

示例4: cache_from_env

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers['x-storage-url'] [as 别名]
        memcache_client = cache_from_env(req.environ)
        if not memcache_client:
            raise Exception('Memcache required')

        expires = time() + seconds
        memcache_user_key = '%s/user/%s/key/%s' % (self.reseller_prefix, account_user, key)
        memcache_token_key = '%s/token/%s' % (self.reseller_prefix, token_definitive)
        memcache_token_value = '%s&%s&%s' % (token_definitive, tenant, expires)
        memcache_user_value = '%s&%s&%s' % (user, tenant, expires)
        memcache_client.set(memcache_token_key, memcache_user_value)
        memcache_client.set(memcache_user_key, memcache_token_value)


        resp = Response(request=req, headers={
            'x-auth-token': token_definitive, 'x-storage-token': token_definitive})
        resp.headers['x-storage-url'] = 'http://controller:8080/v1/AUTH_'+tenant
        return resp
##############################################################################################

        # 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/key/%s' % (self.reseller_prefix, account_user,key)
        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)
开发者ID:FINESCE,项目名称:HybridCloudDataManagement,代码行数:33,代码来源:customauth.py

示例5: handle_get_token

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

#.........这里部分代码省略.........
        print('account_user = %s ' % account_user)



        # my codes are here  ********************************************

        account_user_url = '$HOST/v1/%s%s' % (self.reseller_prefix, account)

        if(account + ':' + user not in self.users):
            values = ['.admin']
            self.users[account + ':' + user] = {
                    'key': key, 'url': account_user_url, 'groups': values}

        print('self.users = %s'%self.users)
        # **************************************************

        # if account_user not in self.users:
        #     self.logger.increment('token_denied')
        #     print('++++++++++++++++++end ( handle_get_token )+++++++++++++++++++ in /middleware/tempauth.py')
        #     return HTTPUnauthorized(request=req, headers=
        #                             {'Www-Authenticate':
        #                              'Swift realm="%s"' % account})
        # if self.users[account_user]['key'] != key:
        #     self.logger.increment('token_denied')
        #     print('++++++++++++++++++end ( handle_get_token )+++++++++++++++++++ in /middleware/tempauth.py')
        #     return HTTPUnauthorized(request=req, headers=
        #                             {'Www-Authenticate':
        #                              'Swift realm="unknown"'})

        #print('self.users[account_user][url] = %s '%self.users[account_user]['url'])


        # ***************************************************************************


        account_id = account_user_url.rsplit('/',1)[-1]
        #account_id = self.users[account_user]['url'].rsplit('/', 1)[-1]
        print('account_id = %s '%account_id)

        # Get memcache client
        memcache_client = cache_from_env(req.environ)
        print('memcache_client = %s '%memcache_client)
        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)
        print('memcached_user_key =%s and candidate_token = %s '%(memcache_user_key,candidate_token))

        if candidate_token:
            print('if candidate token')
            memcache_token_key = \
                '%s/token/%s' % (self.reseller_prefix, candidate_token)
            cached_auth_data = memcache_client.get(memcache_token_key)
            print('memcache_token_key = %s , cached_auth_data = %s '%(memcache_token_key,cached_auth_data))
            if cached_auth_data:
                print('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)
                print('old_groups = %s , new_groups = %s '%(old_groups,new_groups))

                if expires > time() and \
                        set(old_groups) == set(new_groups.split(',')):
                    token = candidate_token
        # Create a new token if one didn't exist

        print('token = %s'%token)
        if not token:
            print('if not token, so generating new token')
            # Generate new token
            token = '%stk%s' % (self.reseller_prefix, uuid4().hex)
            print('new generated token = %s '% token )
            expires = time() + self.token_life
            groups = self._get_user_groups(account, account_user, account_id)
            print('expires = %s and groups = %s '%(expires,groups))
            # 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)
        url = account_user_url.replace('$HOST', resp.host_url)

        print('url = %s '% url)
        if self.storage_url_scheme != 'default':
            url = self.storage_url_scheme + ':' + url.split(':', 1)[1]
        resp.headers['x-storage-url'] = url
        print('resp = %s '%resp)
        print('++++++++++++++++++end ( handle_get_token )+++++++++++++++++++ in /middleware/tempauth.py')
        return resp
开发者ID:jannatunnoor,项目名称:test_swift,代码行数:104,代码来源:tempauth.py


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