當前位置: 首頁>>代碼示例>>Python>>正文


Python oss2.Auth方法代碼示例

本文整理匯總了Python中oss2.Auth方法的典型用法代碼示例。如果您正苦於以下問題:Python oss2.Auth方法的具體用法?Python oss2.Auth怎麽用?Python oss2.Auth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oss2的用法示例。


在下文中一共展示了oss2.Auth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [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: upload_oss

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def upload_oss(kw, local_file, oss_path):
    """
    help function to upload a model to oss
    :param kw: OSS parameter
    :param local_file: local place of model
    :param oss_path: remote place of OSS
    :return: True if the procedure is success
    """
    if oss_path[-1] == '/':
        oss_path = '%s%s' % (oss_path, os.path.basename(local_file))

    auth = oss2.Auth(kw['access_id'], kw['access_key'])
    bucket = kw['access_bucket']
    bkt = oss2.Bucket(auth=auth, endpoint=kw['endpoint'], bucket_name=bucket)

    try:
        bkt.put_object_from_file(key=oss_path, filename=local_file)
        logger.info("upload %s to %s successfully!" %
                    (os.path.abspath(local_file), oss_path))
    except Exception():
        raise ValueError('upload %s to %s failed' %
                         (os.path.abspath(local_file), oss_path)) 
開發者ID:kubeflow,項目名稱:xgboost-operator,代碼行數:24,代碼來源:utils.py

示例3: read_model_from_oss

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def read_model_from_oss(kw):
    """
    helper function to read a model from oss
    :param kw: OSS parameter
    :return: XGBoost booster model
    """
    auth = oss2.Auth(kw['access_id'], kw['access_key'])
    bucket = kw['access_bucket']
    bkt = oss2.Bucket(auth=auth, endpoint=kw['endpoint'], bucket_name=bucket)
    oss_path = kw["path"]

    temp_model_fname = os.path.join(tempfile.mkdtemp(), 'local_model')
    try:
        bkt.get_object_to_file(key=oss_path, filename=temp_model_fname)
        logger.info("success to load model from oss %s", oss_path)
    except Exception as e:
        logging.error("fail to load model: " + e)
        raise Exception("fail to load model from oss %s", oss_path)

    bst = xgb.Booster({'nthread': 2})  # init model

    bst.load_model(temp_model_fname)

    return bst 
開發者ID:kubeflow,項目名稱:xgboost-operator,代碼行數:26,代碼來源:utils.py

示例4: test_failed_state

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def test_failed_state(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task-callback"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
       
        task_config = AsyncFetchTaskConfiguration('http://invalidUrl.com', object_name=object_name)

        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        time.sleep(5)

        result = bucket.get_async_fetch_task(task_id)

        self.assertEqual(task_id, result.task_id)
        self.assertEqual(ASYNC_FETCH_TASK_STATE_FAILED, result.task_state)
        self.assertNotEqual('', result.error_msg)

        bucket.delete_bucket() 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:test_async_fetch_task.py

示例5: test_ignore_same_key

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def test_ignore_same_key(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
        bucket.put_object(object_name, 'test-content')

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name, ignore_same_key=False)
        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        self.assertNotEqual('', task_id)

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name, ignore_same_key=True)
        self.assertRaises(oss2.exceptions.ObjectAlreadyExists, bucket.put_async_fetch_task, task_config)

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name)
        self.assertRaises(oss2.exceptions.ObjectAlreadyExists, bucket.put_async_fetch_task, task_config)

        bucket.delete_object(object_name) 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:test_async_fetch_task.py

示例6: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [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

示例7: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [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

示例8: get_oss_client

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [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

示例9: connectOSS

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def connectOSS(self):
        try:
            auth = oss2.Auth(self.AccessKeyId, self.AccessKeySecret)
            self.bucket = oss2.Bucket(auth, self.Endpoint, self.BucketName)
        except Exception as e:
            logger.getErrorLog('OSSCommand-upload-上傳OSS失敗,原因:%s' % (e))

    # 上傳 
開發者ID:miansen,項目名稱:article-spider,代碼行數:10,代碼來源:OSSCommand.py

示例10: get_oss_version

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def get_oss_version(project=None):
    versions = []
    try:
        if project:
            tt = time.strftime('%Y',time.localtime())
            auth = oss2.Auth(oss_id, oss_key)
            bucket = oss2.Bucket(auth, oss_url, 'ops')
            db_packages = db_op.k8s_packages
            packages = db_packages.query.with_entities(db_packages.package).filter(db_packages.deployment==project).all()
            if packages:
                package_name = packages[0][0].split('.')[0]
                for obj in oss2.ObjectIterator(bucket):
                    if obj.key.endswith('.war') or obj.key.endswith('.tar.gz') or obj.key.endswith('.jar'):
                        obj_name  = obj.key.split('/')[-1].replace('_','-')
                        project_name = project.replace('_','-')
                        if obj_name.startswith('%s-%s'%(package_name,tt)) or obj_name.startswith('%s-tag-%s'%(package_name,tt)) \
                                or obj_name.startswith('%s-%s'%(project_name,tt)):
                            try:
                                ver = obj_name.split(tt)[-1].split('.')[0]
                                version = '%s%s'%(tt,ver)
                                versions.append(version)
                            except:
                                pass
                versions = list(set(versions))
                versions.sort(reverse=True)
                if len(versions) >15:
                    versions = versions[:15]
    except Exception as e:
        logging.error(e)
    finally:
        db_op.DB.session.remove()
        return jsonify({project:versions}) 
開發者ID:wylok,項目名稱:sparrow,代碼行數:34,代碼來源:ajax_api.py

示例11: upload_to_oss

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def upload_to_oss(key: str, filename: str):
    auth = oss2.Auth(BUCKET_API_KEY, BUCKET_API_SECRET)
    bucket = oss2.Bucket(auth, BUCKET_API_ENDPOINT, BUCKET_NAME)
    bucket.put_object_from_file(key, filename) 
開發者ID:solarhell,項目名稱:fontObfuscator,代碼行數:6,代碼來源:upload.py

示例12: conn

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def conn(self):
        auth = oss2.Auth(self.key, self.secret)
        self.bucket = oss2.Bucket(auth, self.region, self.bucket_name) 
開發者ID:opendevops-cn,項目名稱:codo-tools,代碼行數:5,代碼來源:oss.py

示例13: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [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

示例14: test_async_fetch_task

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def test_async_fetch_task(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name, content_md5=self.fetch_content_md5, ignore_same_key=False)

        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        time.sleep(5)

        result = bucket.get_async_fetch_task(task_id)
        self.assertEqual(task_id, result.task_id)
        self.assertEqual(ASYNC_FETCH_TASK_STATE_SUCCESS, result.task_state)
        self.assertEqual('', result.error_msg)
        task_config = result.task_config
        self.assertEqual(self.fetch_url, task_config.url)
        self.assertEqual(self.fetch_content_md5, task_config.content_md5)
        self.assertEqual(object_name, task_config.object_name)
        self.assertFalse(task_config.ignore_same_key)
        self.assertEqual('', task_config.host)
        self.assertEqual('', task_config.callback)

        bucket.delete_object(object_name)
        bucket.delete_bucket() 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:29,代碼來源:test_async_fetch_task.py

示例15: test_async_fetch_task_with_few_argument

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Auth [as 別名]
def test_async_fetch_task_with_few_argument(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name)

        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        time.sleep(5)

        result = bucket.get_async_fetch_task(task_id)
        self.assertEqual(task_id, result.task_id)
        self.assertEqual(ASYNC_FETCH_TASK_STATE_SUCCESS, result.task_state)
        self.assertEqual('', result.error_msg)
        task_config = result.task_config
        self.assertEqual(self.fetch_url, task_config.url)
        self.assertEqual('', task_config.content_md5)
        self.assertEqual(object_name, task_config.object_name)
        self.assertTrue(task_config.ignore_same_key)
        self.assertEqual('', task_config.host)
        self.assertEqual('', task_config.callback)

        bucket.delete_object(object_name)
        bucket.delete_bucket() 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:29,代碼來源:test_async_fetch_task.py


注:本文中的oss2.Auth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。