def test_https(self): bucket_name = random_string(63) bucket = oss2.Bucket(oss2.AnonymousAuth(), OSS_ENDPOINT.replace('http://', 'https://'), bucket_name) self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')
def test_invalid_bucket_name(self): bucket_name = random_string(64) bucket = oss2.Bucket(oss2.AnonymousAuth(), 'http://oss-cn-hangzhou.aliyuncs.com', bucket_name) self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')
def test_ip(self): bucket_name = random_string(63) ip = socket.gethostbyname('oss-cn-hangzhou.aliyuncs.com') bucket = oss2.Bucket(oss2.AnonymousAuth(), ip, bucket_name) self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')
def test_ip(self): bucket_name = random_string(63) ip = socket.gethostbyname( OSS_ENDPOINT.replace('https://', '').replace('http://', '')) bucket = oss2.Bucket(oss2.AnonymousAuth(), ip, bucket_name) self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')
def test_check_endpoint(self): from oss2.api import _normalize_endpoint endpoint = 'www.aliyuncs.com/?x=123#segemnt ' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('http://www.aliyuncs.com', normalized_endpoint) endpoint = 'http://www.aliyuncs.com/?x=123#segemnt ' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('http://www.aliyuncs.com', normalized_endpoint) endpoint = 'http://192.168.1.1:3182/?x=123#segemnt ' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('http://192.168.1.1:3182', normalized_endpoint) endpoint = 'http://www.aliyuncs.com:80/?x=123#segemnt ' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('http://www.aliyuncs.com:80', normalized_endpoint) endpoint = 'https://www.aliyuncs.com:443/?x=123#segemnt' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('https://www.aliyuncs.com:443', normalized_endpoint) endpoint = 'https://www.aliyuncs.com:443' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket') normalized_endpoint = _normalize_endpoint(endpoint) self.assertEqual('https://www.aliyuncs.com:443', normalized_endpoint) self.assertRaises(oss2.exceptions.ClientError, oss2.Bucket, oss2.AnonymousAuth(), OSS_ENDPOINT + '\\', 'test-bucket')
def __init__( self, endpoint: str, key: Optional[str] = None, secret: Optional[str] = None, token: Optional[str] = None, default_cache_type: Optional[str] = "readahead", **kwargs, # pylint: disable=too-many-arguments ): """ Parameters ---------- key : string (None) If not anonymous, use this access key ID, if specified secret : string (None) If not anonymous, use this secret access key, if specified token : string (None) If not anonymous, use this security token, if specified endpoint : string (None) Defualt endpoints of the fs Endpoints are the adderss where OSS locate like: http://oss-cn-hangzhou.aliyuncs.com or https://oss-me-east-1.aliyuncs.com """ super().__init__(**kwargs) if token: self._auth = oss2.StsAuth(key, secret, token) elif key: self._auth = oss2.Auth(key, secret) else: self._auth = oss2.AnonymousAuth() self._endpoint = endpoint or os.getenv("OSS_ENDPOINT", None) if self._endpoint is None: logger.warning( "OSS endpoint is not setted, OSSFS could not work properly" "without a endpoint, please set it manually with " "`ossfs.set_endpoint` later") self._default_cache_type = default_cache_type self._session = oss2.Session()
def test_check_endpoint1(self): from oss2.api import _normalize_endpoint endpoint = 'www.aliyuncs.com' oss2.Bucket(oss2.AnonymousAuth(), endpoint, 'test-bucket')
def test_invalid_bucket_name(self): bucket_name = random_string(64) self.assertRaises(oss2.exceptions.ClientError, oss2.Bucket, oss2.AnonymousAuth(), OSS_ENDPOINT, bucket_name)
def test_invalid_bucket_name(self): bucket_name = random_string(64) bucket = oss2.Bucket(oss2.AnonymousAuth(), OSS_ENDPOINT, bucket_name) self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')