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


Python oss2.Service方法代码示例

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


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

示例1: __init__

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def __init__(self):
        self.access_key_id = self._get_config('OSS_ACCESS_KEY_ID')
        self.access_key_secret = self._get_config('OSS_ACCESS_KEY_SECRET')
        self.end_point = _normalize_endpoint(self._get_config('OSS_END_POINT').strip())
        self.bucket_name = self._get_config('OSS_BUCKET_NAME')
        self.cname = self._get_config('OSS_CNAME')

        self.auth = Auth(self.access_key_id, self.access_key_secret)
        self.service = Service(self.auth, self.end_point)

        try:
            if self.bucket_name not in self._list_bucket(self.service):
                # create bucket if not exists
                self.bucket = self._create_bucket(self.auth)
            else:
                # change bucket acl if not consists
                self.bucket = self._check_bucket_acl(self._get_bucket(self.auth))
        except AccessDenied:
            # 当启用了RAM访问策略,是不允许list和create bucket的
            self.bucket = self._get_bucket(self.auth) 
开发者ID:007gzs,项目名称:dingtalk-django-example,代码行数:22,代码来源:storage.py

示例2: oss_check

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def oss_check(self, bucket_name, default_endpoint, access_key_id, access_key_secret):
        if bucket_name in self.bucket_endpoints:
            endpoint = self.bucket_endpoints[bucket_name]
            try:
                bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name, connect_timeout=5.0, app_name=defaults.app_name)
                res = bucket.get_bucket_acl()
            except oss2.exceptions.OssError as e:
                raise AuthenticationFailed("access bucket:%s using specified \
                        endpoint:%s failed. request_id:%s, status:%s, code:%s, message:%s" % (bucket_name, endpoint, e.request_id, unicode(e.status), e.code, e.message))
            return endpoint 
        try:
            service = oss2.Service(oss2.Auth(access_key_id, access_key_secret), default_endpoint, app_name=defaults.app_name)
            res = service.list_buckets(prefix=bucket_name)
        except oss2.exceptions.AccessDenied as e:
            raise AuthenticationFailed("can't list buckets, check your access_key.request_id:%s, status:%s, code:%s, message:%s"% (e.request_id, unicode(e.status), e.code, e.message))
        except oss2.exceptions.OssError as e:
            raise AuthenticationFailed("list buckets error. request_id:%s, status:%s, code:%s, message:%s" % (e.request_id, unicode(e.status), e.code, e.message))

        bucket_list = res.buckets
        for bucket in bucket_list:
            if bucket.name == bucket_name:
                endpoint = self.get_endpoint(bucket_name, bucket.location.decode('utf-8'), access_key_id, access_key_secret)
                return endpoint
        raise AuthenticationFailed("can't find the bucket %s when list buckets." % bucket_name) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:26,代码来源:oss_authorizers.py

示例3: __init__

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def __init__(self, access_key_id=None, access_key_secret=None, end_point=None, bucket_name=None, expire_time=None):
        self.access_key_id = access_key_id if access_key_id else _get_config('OSS_ACCESS_KEY_ID')
        self.access_key_secret = access_key_secret if access_key_secret else _get_config('OSS_ACCESS_KEY_SECRET')
        self.end_point = _normalize_endpoint(end_point if end_point else _get_config('OSS_ENDPOINT'))
        self.bucket_name = bucket_name if bucket_name else _get_config('OSS_BUCKET_NAME')
        self.expire_time = expire_time if expire_time else int(_get_config('OSS_EXPIRE_TIME', default=60*60*24*30))

        self.auth = Auth(self.access_key_id, self.access_key_secret)
        self.service = Service(self.auth, self.end_point)
        self.bucket = Bucket(self.auth, self.end_point, self.bucket_name)

        # try to get bucket acl to check bucket exist or not
        try:
            self.bucket_acl = self.bucket.get_bucket_acl().acl
        except oss2.exceptions.NoSuchBucket:
            raise SuspiciousOperation("Bucket '%s' does not exist." % self.bucket_name) 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:18,代码来源:backends.py

示例4: __init__

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def __init__(self):
        self.access_key_id = self._get_config('ACCESS_KEY_ID')
        self.access_key_secret = self._get_config('ACCESS_KEY_SECRET')
        self.end_point = _normalize_endpoint(self._get_config('END_POINT').strip())
        self.bucket_name = self._get_config('BUCKET_NAME')
        self.cname = self._get_config('ALIYUN_OSS_CNAME')

        self.auth = Auth(self.access_key_id, self.access_key_secret)
        self.service = Service(self.auth, self.end_point)

        try:
            if self.bucket_name not in self._list_bucket(self.service):
                # create bucket if not exists
                self.bucket = self._create_bucket(self.auth)
            else:
                # change bucket acl if not consists
                self.bucket = self._check_bucket_acl(self._get_bucket(self.auth))
        except AccessDenied:
            # 当启用了RAM访问策略,是不允许list和create bucket的
            self.bucket = self._get_bucket(self.auth) 
开发者ID:xiewenya,项目名称:django-aliyun-oss2-storage,代码行数:22,代码来源:backends.py

示例5: get_oss_client

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def get_oss_client(credentials, region=None):
    try:
        auth = oss2.Auth(credentials.credentials.access_key_id, credentials.credentials.access_key_secret)
        client = oss2.Service(auth,
                              endpoint='oss-{}.aliyuncs.com'.format(region) if region
                              else 'oss-cn-hangzhou.aliyuncs.com')
        return client

    except Exception as e:
        print_exception(e)
        return None 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:13,代码来源:utils.py

示例6: __init__

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def __init__(self, access_key_id, access_key_secret, host, bucket_name, keeps=None):
        """
        access_key_id:
        access_key_secret:
        host: 域名,如 http://oss-cn-hangzhou.aliyuncs.com
        bucket_name: 不需要在后台自动创建,也会自动创建好
        """
        super(OSSBackend, self).__init__(keeps)
        auth = oss2.Auth(access_key_id, access_key_secret)
        self.bucket = oss2.Bucket(auth, host, bucket_name)

        service = oss2.Service(auth, host)
        if bucket_name not in [b.name for b in oss2.BucketIterator(service)]:
            # 说明bucket不存在
            self.bucket.create_bucket() 
开发者ID:dantezhu,项目名称:yunbk,代码行数:17,代码来源:ali_oss.py

示例7: service

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def service():
    return oss2.Service(oss2.Auth('fake-access-key-id', 'fake-access-key-secret'),
                        'http://oss-cn-hangzhou.aliyuncs.com') 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:5,代码来源:common.py

示例8: test_bucket_iterator

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def test_bucket_iterator(self):
        service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT)
        self.assertTrue(OSS_BUCKET in (b.name for b in oss2.BucketIterator(service, max_keys=2))) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:5,代码来源:test_iterator.py

示例9: clean_and_delete_bucket_by_prefix

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def clean_and_delete_bucket_by_prefix(bucket_prefix):
    service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT)
    buckets = service.list_buckets(prefix=bucket_prefix).buckets
    for b in buckets:
        bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), b.extranet_endpoint, b.name)
        clean_and_delete_bucket(bucket) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:8,代码来源:common.py

示例10: test_user_agent

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def test_user_agent(self):
            app = 'fantastic-tool'

            assert_found = False
            def do_request(session_self, req, timeout):
                if assert_found:
                    self.assertTrue(req.headers['User-Agent'].find(app) >= 0)
                else:
                    self.assertTrue(req.headers['User-Agent'].find(app) < 0)

                raise oss2.exceptions.ClientError('intentional')

            from unittest.mock import patch
            with patch.object(oss2.Session, 'do_request', side_effect=do_request, autospec=True):
                # 不加 app_name
                assert_found = False
                self.assertRaises(oss2.exceptions.ClientError, self.bucket.get_bucket_acl)

                service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT)
                self.assertRaises(oss2.exceptions.ClientError, service.list_buckets)

                # 加app_name
                assert_found = True
                bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, OSS_BUCKET,
                                     app_name=app)
                self.assertRaises(oss2.exceptions.ClientError, bucket.get_bucket_acl)

                service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT,
                                       app_name=app)
                self.assertRaises(oss2.exceptions.ClientError, service.list_buckets) 
开发者ID:aliyun,项目名称:aliyun-oss-python-sdk,代码行数:32,代码来源:test_api_base.py

示例11: __init__

# 需要导入模块: import oss2 [as 别名]
# 或者: from oss2 import Service [as 别名]
def __init__(self, conf):
        self.conf = conf
        # Due to a bug in httplib we can't use https
        self.auth = oss2.Auth(conf.key_id, conf.key)
        self.service = oss2.Service(self.auth, conf.host)
        self.bucket = oss2.Bucket(self.auth, conf.host, conf.bucket_name) 
开发者ID:haiwen,项目名称:seafobj,代码行数:8,代码来源:alioss.py


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