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


Python base.get_account_info函数代码示例

本文整理汇总了Python中swift.proxy.controllers.base.get_account_info函数的典型用法代码示例。如果您正苦于以下问题:Python get_account_info函数的具体用法?Python get_account_info怎么用?Python get_account_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_account_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_account_info_cache

    def test_get_account_info_cache(self):
        # Works with fake apps that return ints in the headers
        cached = {'status': 404,
                  'bytes': 3333,
                  'total_object_count': 10}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        resp = get_account_info(req.environ, FakeApp())
        self.assertEqual(resp['bytes'], 3333)
        self.assertEqual(resp['total_object_count'], 10)
        self.assertEqual(resp['status'], 404)

        # Works with strings too, like you get when parsing HTTP headers
        # that came in through a socket from the account server
        cached = {'status': 404,
                  'bytes': '3333',
                  'container_count': '234',
                  'total_object_count': '10',
                  'meta': {}}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        resp = get_account_info(req.environ, FakeApp())
        self.assertEqual(resp['status'], 404)
        self.assertEqual(resp['bytes'], 3333)
        self.assertEqual(resp['container_count'], 234)
        self.assertEqual(resp['meta'], {})
        self.assertEqual(resp['total_object_count'], 10)
开发者ID:mahak,项目名称:swift,代码行数:27,代码来源:test_base.py

示例2: test_get_account_info_cache

    def test_get_account_info_cache(self):
        # The original test that we prefer to preserve
        cached = {'status': 404,
                  'bytes': 3333,
                  'total_object_count': 10}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        resp = get_account_info(req.environ, FakeApp())
        self.assertEqual(resp['bytes'], 3333)
        self.assertEqual(resp['total_object_count'], 10)
        self.assertEqual(resp['status'], 404)

        # Here is a more realistic test
        cached = {'status': 404,
                  'bytes': '3333',
                  'container_count': '234',
                  'total_object_count': '10',
                  'meta': {}}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        resp = get_account_info(req.environ, FakeApp())
        self.assertEqual(resp['status'], 404)
        self.assertEqual(resp['bytes'], '3333')
        self.assertEqual(resp['container_count'], 234)
        self.assertEqual(resp['meta'], {})
        self.assertEqual(resp['total_object_count'], '10')
开发者ID:bouncestorage,项目名称:swift,代码行数:26,代码来源:test_base.py

示例3: test_get_account_info_cache

    def test_get_account_info_cache(self):
        # The original test that we prefer to preserve
        cached = {'status': 404,
                  'bytes': 3333,
                  'total_object_count': 10}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        with patch('swift.proxy.controllers.base.'
                   '_prepare_pre_auth_info_request', FakeRequest):
            resp = get_account_info(req.environ, 'xxx')
        self.assertEquals(resp['bytes'], 3333)
        self.assertEquals(resp['total_object_count'], 10)
        self.assertEquals(resp['status'], 404)

        # Here is a more realistic test
        cached = {'status': 404,
                  'bytes': '3333',
                  'container_count': '234',
                  'total_object_count': '10',
                  'meta': {}}
        req = Request.blank("/v1/account/cont",
                            environ={'swift.cache': FakeCache(cached)})
        with patch('swift.proxy.controllers.base.'
                   '_prepare_pre_auth_info_request', FakeRequest):
            resp = get_account_info(req.environ, 'xxx')
        self.assertEquals(resp['status'], 404)
        self.assertEquals(resp['bytes'], '3333')
        self.assertEquals(resp['container_count'], 234)
        self.assertEquals(resp['meta'], {})
        self.assertEquals(resp['total_object_count'], '10')
开发者ID:10389030,项目名称:swift,代码行数:30,代码来源:test_base.py

示例4: test_get_account_info_infocache

 def test_get_account_info_infocache(self):
     app = FakeApp()
     ic = {}
     req = Request.blank("/v1/a", environ={'swift.cache': FakeCache(),
                                           'swift.infocache': ic})
     get_account_info(req.environ, app)
     got_infocaches = [e['swift.infocache'] for e in app.captured_envs]
     self.assertEqual(1, len(got_infocaches))
     self.assertIs(ic, got_infocaches[0])
开发者ID:mahak,项目名称:swift,代码行数:9,代码来源:test_base.py

示例5: _get_keys

    def _get_keys(self, env):
        """
        Returns the X-[Account|Container]-Meta-Temp-URL-Key[-2] header values
        for the account or container, or an empty list if none are set. Each
        value comes as a 2-tuple (key, scope), where scope is either
        CONTAINER_SCOPE or ACCOUNT_SCOPE.

        Returns 0-4 elements depending on how many keys are set in the
        account's or container's metadata.

        :param env: The WSGI environment for the request.
        :returns: [
            (X-Account-Meta-Temp-URL-Key str value, ACCOUNT_SCOPE) if set,
            (X-Account-Meta-Temp-URL-Key-2 str value, ACCOUNT_SCOPE if set,
            (X-Container-Meta-Temp-URL-Key str value, CONTAINER_SCOPE) if set,
            (X-Container-Meta-Temp-URL-Key-2 str value, CONTAINER_SCOPE if set,
        ]
        """
        account_info = get_account_info(env, self.app, swift_source='TU')
        account_keys = get_tempurl_keys_from_metadata(account_info['meta'])

        container_info = get_container_info(env, self.app, swift_source='TU')
        container_keys = get_tempurl_keys_from_metadata(
            container_info.get('meta', []))

        return ([(ak, ACCOUNT_SCOPE) for ak in account_keys] +
                [(ck, CONTAINER_SCOPE) for ck in container_keys])
开发者ID:nadeemsyed,项目名称:swift,代码行数:27,代码来源:tempurl.py

示例6: _get_keys

    def _get_keys(self, env):
        """
        Returns the X-[Account|Container]-Meta-Temp-URL-Key[-2] header values
        for the account or container, or an empty list if none are set.

        Returns 0-4 elements depending on how many keys are set in the
        account's or container's metadata.

        Also validate that the request
        path indicates a valid container; if not, no keys will be returned.

        :param env: The WSGI environment for the request.
        :returns: list of tempurl keys
        """
        parts = env["PATH_INFO"].split("/", 4)
        if len(parts) < 4 or parts[0] or parts[1] != "v1" or not parts[2] or not parts[3]:
            return []

        account_info = get_account_info(env, self.app, swift_source="FP")
        account_keys = get_tempurl_keys_from_metadata(account_info["meta"])

        container_info = get_container_info(env, self.app, swift_source="FP")
        container_keys = get_tempurl_keys_from_metadata(container_info.get("meta", []))

        return account_keys + container_keys
开发者ID:danieleguttadoro,项目名称:ovencswiftserver_onthefly,代码行数:25,代码来源:formpost.py

示例7: __call__

    def __call__(self, request):
       
        if request.method not in ("PUT","COPY"):
            return self.app

        try:
            split_path(request.path,2, 4, rest_with_last=True)
        except ValueError:
            return self.app

        new_quota = request.headers.get('X-Account-Meta-Quota-Bytes')
        if new_quota:
            if not new_quota.isdigit():
                return jresponse('-1', 'bad request', request, 400)
            return self.app

        account_info = get_account_info(request.environ, self.app)
        new_size = int(account_info['bytes']) + (request.content_length or 0)
        quota = int(account_info['meta'].get('quota-bytes', -1))

        if 0 <= quota < new_size:
            respbody='Your request is too large.'
            return jresponse('-1', respbody, request,413)

        return self.app
开发者ID:sun7shines,项目名称:Cloudfs,代码行数:25,代码来源:account_quotas.py

示例8: __call__

    def __call__(self, env, start_response):
        req = Request(env)
        # We want to check POST here
        # it can possibly have content_length > 0
        if not self.enforce_quota or req.method not in ("POST", "PUT", "COPY"):
            return self.app(env, start_response)
        account_info = get_account_info(req.environ, self.app,
                                        swift_source='litequota')
        if not account_info:
            return self.app(env, start_response)
        service_plan = assemble_from_partial(self.metadata_key,
                                             account_info['meta'])
        try:
            ver, account, container, obj = \
                req.split_path(2, 4, rest_with_last=True)
        except ValueError:
            return self.app(env, start_response)
        if not service_plan and req.method == 'PUT' and not obj:
            service_plan = self.set_serviceplan(req, account)
        if not service_plan:
            return self.app(env, start_response)
        try:
            service_plan = json.loads(service_plan)
        except ValueError:
            return self.app(env, start_response)

        if service_plan.get('storage', None):
            resp = self.apply_storage_quota(req, service_plan['storage'],
                                            account_info,
                                            ver, account, container, obj)
            if resp:
                return resp(env, start_response)
        return self.app(env, start_response)
开发者ID:pkit,项目名称:liteauth,代码行数:33,代码来源:litequota.py

示例9: test_get_account_info_no_cache

 def test_get_account_info_no_cache(self):
     app = FakeApp()
     req = Request.blank("/v1/AUTH_account",
                         environ={'swift.cache': FakeCache({})})
     resp = get_account_info(req.environ, app)
     self.assertEqual(resp['bytes'], 6666)
     self.assertEqual(resp['total_object_count'], 1000)
开发者ID:mahak,项目名称:swift,代码行数:7,代码来源:test_base.py

示例10: __call__

    def __call__(self, env, start_response):
        req = Request(env)

        # TOREMOVE: when merged
        # if we are doing a post to update the locked value then alow it.
        if req.method == 'POST':
            for header in req.headers:
                if header.lower() == "x-account-meta-%s" % \
                        self.locked_header.lower():
                    return self.app(env, start_response)

        # check if we are in a method we want to disallow.
        if not req.method in self.denied_methods:
            return self.app(env, start_response)

        account_info = get_account_info(env,
                                        self.app,
                                        swift_source="LCK")
        if not account_info:
            return self.app(env, start_response)

        if 'meta' in account_info and self.locked_header in \
           account_info['meta'] and config_true_value(
               account_info['meta'][self.locked_header]):
            self.logger.debug(
                "[account_access] account locked for %s" %
                (str(req.remote_user)))
            env['swift.authorize'] = self.deny
        return self.app(env, start_response)
开发者ID:reality535,项目名称:swift-account-locked,代码行数:29,代码来源:middleware.py

示例11: __call__

    def __call__(self, request):

        if request.method not in ("POST", "PUT"):
            return self.app

        try:
            request.split_path(2, 4, rest_with_last=True)
        except ValueError:
            return self.app

        new_quota = request.headers.get('X-Account-Meta-Quota-Bytes')

        if request.environ.get('reseller_request') is True:
            if new_quota and not new_quota.isdigit():
                return HTTPBadRequest()
            return self.app

        # deny quota set for non-reseller
        if new_quota is not None:
            return HTTPForbidden()

        account_info = get_account_info(request.environ, self.app)
        if not account_info or not account_info['bytes']:
            return self.app
        new_size = int(account_info['bytes']) + (request.content_length or 0)
        quota = int(account_info['meta'].get('quota-bytes', -1))

        if 0 <= quota < new_size:
            return HTTPRequestEntityTooLarge()

        return self.app
开发者ID:ChenZhengtongnju,项目名称:swift,代码行数:31,代码来源:account_quotas.py

示例12: __init__

    def __init__(self, request, conf, app, logger):
        super(StorletProxyHandler, self).__init__(
            request, conf, app, logger)
        self.storlet_container = conf.get('storlet_container')
        self.storlet_dependency = conf.get('storlet_dependency')
        self.storlet_containers = [self.storlet_container,
                                   self.storlet_dependency]

        if not self.is_storlet_request:
            # This is not storlet-related request, so pass it
            raise NotStorletRequest()

        # In proxy server, storlet handler validate if storlet enabled
        # at the account, anyway
        account_meta = get_account_info(self.request.environ,
                                        self.app)['meta']
        storlets_enabled = account_meta.get('storlet-enabled',
                                            'False')
        if not config_true_value(storlets_enabled):
            self.logger.debug('Account disabled for storlets')
            raise HTTPBadRequest('Account disabled for storlets',
                                 request=self.request)

        if self.is_storlet_object_update:
            # TODO(takashi): We have to validate metadata in COPY case
            self._validate_registration(self.request)
            raise NotStorletExecution()
        else:
            # if self.is_storlet_execution
            self._setup_gateway()
开发者ID:Nicolepcx,项目名称:storlets,代码行数:30,代码来源:storlet_handler.py

示例13: get_defaults

    def get_defaults(self, req, req_type, format_args):
        acct_sysmeta = get_account_info(req.environ, self.app)['sysmeta']
        if req_type == 'object':
            cont_sysmeta = get_container_info(req.environ, self.app)['sysmeta']
        else:
            cont_sysmeta = {}

        defaults = {}
        prefix = 'default-%s-' % req_type
        for src in (self.conf, acct_sysmeta, cont_sysmeta):
            for key, value in src.items():
                if not key.lower().startswith(prefix):
                    continue
                header_to_default = key[len(prefix):].lower()
                if header_to_default.startswith(BLACKLIST_PREFIXES):
                    continue
                if header_to_default in BLACKLIST:
                    continue
                if self.conf['use_formatting']:
                    try:
                        value = value.format(**format_args)
                    except KeyError:
                        # This user may not have specified the default;
                        # don't fail because of someone else
                        pass
                defaults[header_to_default] = value
        return defaults
开发者ID:tipabu,项目名称:swift_defaulter,代码行数:27,代码来源:defaulter.py

示例14: account_acls

    def account_acls(self, req):
        """
        Return a dict of ACL data from the account server via get_account_info.

        Auth systems may define their own format, serialization, structure,
        and capabilities implemented in the ACL headers and persisted in the
        sysmeta data.  However, auth systems are strongly encouraged to be
        interoperable with Tempauth.

        Account ACLs are set and retrieved via the header
           X-Account-Access-Control

        For header format and syntax, see:
         * :func:`swift.common.middleware.acl.parse_acl()`
         * :func:`swift.common.middleware.acl.format_acl()`
        """
        info = get_account_info(req.environ, self.app, swift_source='TA')
        try:
            acls = acls_from_account_info(info)
        except ValueError as e1:
            self.logger.warn("Invalid ACL stored in metadata: %r" % e1)
            return None
        except NotImplementedError as e2:
            self.logger.warn("ACL version exceeds middleware version: %r" % e2)
            return None
        return acls
开发者ID:hbhdytf,项目名称:mac,代码行数:26,代码来源:tempauth.py

示例15: POST

 def POST(self, env):
     """Handle posts dealing with metadata alteration"""
     req = Request(env)
     conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
     headers = req.params
     version, acc, con, obj = split_path(req.path, 1, 4, True)
     if not con:
         try:
             info = get_account_info(env, self.app)
             if info:
                 stor_policy = info['storage_policy']
                 headers['storage_policy'] = stor_policy
         except:
             pass
     else:
         try:
             info = get_container_info(env, self.app)
             if info:
                 stor_policy = info['storage_policy']
                 headers['storage_policy'] = stor_policy
         except:
             pass
     conn.request('POST', req.path, headers=headers)
     resp = conn.getresponse()
     #confirm response then pass along the request
     return self.app
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:26,代码来源:metadata.py


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