Exemple #1
0
    def __make_signature(self, req, bucket_name, key):
        string_to_sign = self.__get_string_to_sign(req, bucket_name, key)

        logging.debug('string_to_sign={0}'.format(string_to_sign))

        h = hmac.new(to_bytes(self.oss_secret_key), to_bytes(string_to_sign),
                     hashlib.sha1)
        return utils.b64encode_as_string(h.digest())
Exemple #2
0
    def test_fetch_success_callback_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'
        callback = '{"callbackUrl":"www.abc.com/callback","callbackBody":"${etag}"}'
        base64_callback = oss2.utils.b64encode_as_string(to_bytes(callback))
        task_config = AsyncFetchTaskConfiguration(self.fetch_url,
                                                  object_name=object_name,
                                                  callback=base64_callback)

        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_FETCH_SUCCESS_CALLBACK_FAILED,
                         result.task_state)
        self.assertNotEqual('', 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(base64_callback, task_config.callback)

        bucket.delete_object(object_name)
        bucket.delete_bucket()
            def read(self, amt=None):
                if self.offset >= self.size:
                    return to_bytes('')

                if amt is None or amt < 0:
                    bytes_to_read = self.size - self.offset
                else:
                    bytes_to_read = min(amt, self.size - self.offset)

                content = self.data[self.offset:self.offset + bytes_to_read]

                self.offset += bytes_to_read

                return content
 def __init__(self, data, size):
     self.data = to_bytes(data)
     self.offset = 0
     self.size = size
Exemple #5
0
access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', '<你的AccessKeyId>')
access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', '<你的AccessKeySecret>')
bucket_name = os.getenv('OSS_TEST_BUCKET', '<你的Bucket>')
endpoint = os.getenv('OSS_TEST_ENDPOINT', '<你的访问域名>')

# 确认上面的参数都填写正确了
for param in (access_key_id, access_key_secret, bucket_name, endpoint):
    assert '<' not in param, '请设置参数:' + param

# 创建Bucket对象,所有Object相关的接口都可以通过Bucket对象来进行
bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)

object_name = "test-async-object"
url = "<yourSrcObjectUrl>"
callback = '{"callbackUrl":"www.abc.com/callback","callbackBody":"${etag}"}'
base64_callback = oss2.utils.b64encode_as_string(to_bytes(callback))

# 可以选填host, callback, content_md5, ignore_same_key等参数
task_config = AsyncFetchTaskConfiguration(url, object_name, callback=base64_callback, ignore_same_key=False)

# 创建异步获取文件到bucket的任务
result = bucket.put_async_fetch_task(task_config)
task_id = result.task_id
print('task_id:', result.task_id)

time.sleep(5)

# 获取指定的异步任务信息
result = bucket.get_async_fetch_task(task_id)

# 打印获取到的异步任务信息