Skip to content

Commit 21febcb

Browse files
authored
add vectors bucket
1 parent ab60cd0 commit 21febcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+7001
-13
lines changed

alibabacloud_oss_v2/_client.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Optional, Dict, Iterable, List, Union, cast, Tuple, Iterator
66
from urllib.parse import urlparse, ParseResult, urlencode, quote
77
from xml.etree import ElementTree as ET
8+
import json
89
from . import retry
910
from . import transport
1011
from . import exceptions
@@ -28,6 +29,7 @@
2829
BodyType,
2930
OperationInput,
3031
OperationOutput,
32+
EndpointProvider,
3133
)
3234

3335

@@ -109,6 +111,7 @@ def __init__(
109111
feature_flags: Optional[int] = None,
110112
additional_headers: Optional[List[str]] = None,
111113
operation_timeout: Optional[Union[int, float]] = None,
114+
endpoint_provider: Optional[EndpointProvider] = None,
112115
) -> None:
113116
self.product = product
114117
self.region = region
@@ -126,7 +129,7 @@ def __init__(
126129
self.feature_flags = feature_flags or defaults.FF_DEFAULT
127130
self.additional_headers = additional_headers
128131
self.operation_timeout = operation_timeout
129-
132+
self.endpoint_provider = endpoint_provider
130133

131134
class _InnerOptions:
132135
"""client runtime's information."""
@@ -137,7 +140,6 @@ def __init__(
137140
self.user_agent = user_agent
138141

139142

140-
141143
class _ClientImplMixIn:
142144
"""Client implement"""
143145

@@ -219,7 +221,10 @@ def build_request_context(self, op_input: OperationInput, options: _Options, inn
219221
"""build request context
220222
"""
221223
# host & path
222-
url = _build_url(op_input, options)
224+
if options.endpoint_provider is not None:
225+
url = options.endpoint_provider.build_url(op_input)
226+
else:
227+
url = _build_url(op_input, options)
223228

224229
# queries
225230
if op_input.parameters is not None:
@@ -368,7 +373,10 @@ def service_error_response_handler(response: HttpResponse) -> None:
368373
if not response.is_stream_consumed:
369374
_ = response.read()
370375

371-
raise _to_service_error(response)
376+
if response.headers.get('Content-Type', '') == 'application/json':
377+
raise _to_service_error_json(response)
378+
else:
379+
raise _to_service_error(response)
372380

373381
# insert service error responsed handler first
374382
handlers.append(service_error_response_handler)
@@ -533,6 +541,7 @@ def _resolve_endpoint(config: Config, options: _Options) -> None:
533541
options.endpoint = urlparse(endpoint)
534542

535543

544+
536545
def _resolve_retryer(_: Config, options: _Options) -> None:
537546
"""retryer"""
538547
if options.retryer:
@@ -677,6 +686,61 @@ def _to_service_error(response: HttpResponse) -> exceptions.ServiceError:
677686
error_fileds=error_fileds
678687
)
679688

689+
def _to_service_error_json(response: HttpResponse) -> exceptions.ServiceError:
690+
timestamp = serde.deserialize_httptime(response.headers.get('Date'))
691+
content = response.content or b''
692+
response.close()
693+
694+
error_fileds = {}
695+
code = 'BadErrorResponse'
696+
message = ''
697+
ec = ''
698+
request_id = ''
699+
err_body = b''
700+
try:
701+
err_body = content
702+
if len(err_body) == 0:
703+
err_body = base64.b64decode(
704+
response.headers.get('x-oss-err', ''))
705+
root = json.loads(err_body)
706+
errElem = root.get('Error', None)
707+
if errElem is not None:
708+
for k, v in errElem.items():
709+
if isinstance(v, str):
710+
error_fileds[k] = v
711+
message = error_fileds.get('Message', '')
712+
code = error_fileds.get('Code', '')
713+
ec = error_fileds.get('EC', '')
714+
request_id = error_fileds.get('RequestId', '')
715+
else:
716+
message = f'Expect root node Error, but get {root.keys()}.'
717+
except json.JSONDecodeError as e:
718+
errstr = err_body.decode()
719+
if '"Error":' in errstr:
720+
m = re.search('"Code":(.*),', errstr)
721+
if m:
722+
code = m.group(1).strip(' "')
723+
m = re.search('<Message>(.*)</Message>', errstr)
724+
if m:
725+
message = m.group(1).strip(' "')
726+
if len(message) == 0:
727+
message = f'Failed to parse json from response body due to: {str(e)}. With part response body {err_body[:256]}.'
728+
except Exception as e:
729+
message = f'The body of the response was not readable, due to : {str(e)}.'
730+
731+
return exceptions.ServiceError(
732+
status_code=response.status_code,
733+
code=code,
734+
message=message,
735+
request_id=request_id or response.headers.get('x-oss-request-id', ''),
736+
ec=ec or response.headers.get('x-oss-ec', ''),
737+
timestamp=timestamp,
738+
request_target=f'{response.request.method} {response.request.url}',
739+
snapshot=content,
740+
headers=response.headers,
741+
error_fileds=error_fileds
742+
)
743+
680744
def _build_user_agent(config: Config) -> str:
681745
if config.user_agent:
682746
return f'{utils.get_default_user_agent()}/{config.user_agent}'

alibabacloud_oss_v2/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(
2929
additional_headers: Optional[List[str]] = None,
3030
user_agent: Optional[str] = None,
3131
cloud_box_id: Optional[str] = None,
32-
enable_auto_detect_cloud_box_id: Optional[bool] = None
32+
enable_auto_detect_cloud_box_id: Optional[bool] = None,
33+
account_id: Optional[str] = None
3334
) -> None:
3435
"""
3536
Args:
@@ -73,6 +74,7 @@ def __init__(
7374
user_agent: (str, optional): The optional user specific identifier appended to the User-Agent header.
7475
cloud_box_id: (str, optional): The cloud box id.
7576
enable_auto_detect_cloud_box_id: (bool, optional): The cloud box id is automatically extracted from endpoint.
77+
account_id: (str, optional): The account id, must be required in vectors options.
7678
"""
7779
self.region = region
7880
self.endpoint = endpoint
@@ -98,6 +100,7 @@ def __init__(
98100
self.user_agent = user_agent
99101
self.cloud_box_id = cloud_box_id
100102
self.enable_auto_detect_cloud_box_id = enable_auto_detect_cloud_box_id
103+
self.account_id = account_id
101104

102105
def load_default() -> Config:
103106
"""Using the SDK's default configuration"""

alibabacloud_oss_v2/endpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def from_region(region:str, disable_ssl:bool, etype:str) -> str:
3737

3838
return endpoint
3939

40-
4140
def is_ip(hostname:str):
4241
"""Check whether the host name is an IP address."""
4342
is_ipv6 = False

alibabacloud_oss_v2/models/bucket_basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PutBucketRequest(serde.RequestModel):
4242
"acl": {"tag": "input", "position": "header", "rename": "x-oss-acl"},
4343
"resource_group_id": {"tag": "input", "position": "header", "rename": "x-oss-resource-group-id"},
4444
"create_bucket_configuration": {"tag": "input", "position": "body", "rename": "CreateBucketConfiguration", "type": "xml"},
45+
"bucket_tagging": {"tag": "input", "position": "header", "rename": "x-oss-bucket-tagging"},
4546
}
4647

4748
def __init__(
@@ -50,6 +51,7 @@ def __init__(
5051
acl: Optional[str] = None,
5152
resource_group_id: Optional[str] = None,
5253
create_bucket_configuration: Optional["CreateBucketConfiguration"] = None,
54+
bucket_tagging: Optional[str] = None,
5355
**kwargs: Any
5456
) -> None:
5557
"""
@@ -58,13 +60,15 @@ def __init__(
5860
acl (str, optional): The access control list (ACL) of the bucket.
5961
resource_group_id (str, optional): The ID of the resource group.
6062
create_bucket_configuration (CreateBucketConfiguration, optional):
61-
The configuration information for the bucket.
63+
The configuration information for the bucket.
64+
bucket_tagging (str, optional): The tagging information for the bucket.
6265
"""
6366
super().__init__(**kwargs)
6467
self.bucket = bucket
6568
self.acl = acl
6669
self.resource_group_id = resource_group_id
6770
self.create_bucket_configuration = create_bucket_configuration
71+
self.bucket_tagging = bucket_tagging
6872

6973

7074
class PutBucketResult(serde.ResultModel):

alibabacloud_oss_v2/models/bucket_logging.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class LoggingEnabled(serde.Model):
6262
_attribute_map = {
6363
'target_bucket': {'tag': 'xml', 'rename': 'TargetBucket', 'type': 'str'},
6464
'target_prefix': {'tag': 'xml', 'rename': 'TargetPrefix', 'type': 'str'},
65+
'logging_role': {'tag': 'xml', 'rename': 'LoggingRole', 'type': 'str'},
6566
}
6667

6768
_xml_map = {
@@ -72,16 +73,19 @@ def __init__(
7273
self,
7374
target_bucket: Optional[str] = None,
7475
target_prefix: Optional[str] = None,
76+
logging_role: Optional[str] = None,
7577
**kwargs: Any
7678
) -> None:
7779
"""
7880
Args:
7981
target_bucket (str, optional): The bucket that stores access logs.
8082
target_prefix (str, optional): The prefix of the log objects. This parameter can be left empty.
83+
logging_role (str, optional): The role used for logging operations.
8184
"""
8285
super().__init__(**kwargs)
8386
self.target_bucket = target_bucket
8487
self.target_prefix = target_prefix
88+
self.logging_role = logging_role
8589

8690

8791
class UserDefinedLogFieldsConfiguration(serde.Model):

alibabacloud_oss_v2/models/bucket_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, List, Any, Union
33
from .. import serde
44
from .object_basic import TagSet, Tag
5-
5+
from dataclasses import dataclass
66

77
class Tagging(serde.Model):
88
"""

alibabacloud_oss_v2/models/object_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .. import serde
88
from ..types import BodyType, StreamBody, AsyncStreamBody
99
from .bucket_basic import Owner
10-
10+
from dataclasses import dataclass
1111

1212
class PutObjectRequest(serde.RequestModel):
1313
"""The request for the PutObject operation."""

alibabacloud_oss_v2/models/public_access_block.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from dataclasses import dataclass
23
from typing import Optional, List, Any, Union
34
from .. import serde
45

@@ -71,6 +72,7 @@ def __init__(
7172
super().__init__(**kwargs)
7273
self.public_access_block_configuration = public_access_block_configuration
7374

75+
@dataclass
7476
class PutPublicAccessBlockRequest(serde.RequestModel):
7577
"""
7678
The request for the PutPublicAccessBlock operation.

0 commit comments

Comments
 (0)