Skip to content

Commit 1a093d7

Browse files
zhuxiaolong37huiguangjun
authored andcommitted
Add cloud box id
1 parent b0c9b28 commit 1a093d7

File tree

14 files changed

+808
-4
lines changed

14 files changed

+808
-4
lines changed

alibabacloud_oss_v2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from .models.bucket_tags import *
4242
from .models.bucket_meta_query import *
4343
from .models.bucket_https_config import *
44+
from .models.cloud_box import *
4445

4546
from .config import Config
4647
from .client import Client

alibabacloud_oss_v2/_client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def resolve_config(self, config: Config) ->Tuple[_Options, _InnerOptions]:
151151
_resolve_signer(config, options)
152152
_resolve_address_style(config, options)
153153
_resolve_feature_flags(config, options)
154+
_resolve_cloud_box(config, options)
154155
self._resolve_httpclient(config, options) # pylint: disable=no-member
155156

156157
inner = _InnerOptions()
@@ -568,6 +569,29 @@ def _resolve_feature_flags(config: Config, options: _Options) -> None:
568569
if utils.safety_bool(config.disable_download_crc64_check):
569570
options.feature_flags = options.feature_flags & ~defaults.FF_ENABLE_CRC64_CHECK_DOWNLOAD
570571

572+
573+
def _resolve_cloud_box(config: Config, options: _Options) -> None:
574+
"""cloud box"""
575+
if config.cloud_box_id is not None:
576+
options.region = str(config.cloud_box_id)
577+
options.product = defaults.CLOUD_BOX_PRODUCT
578+
return
579+
580+
if not config.enable_auto_detect_cloud_box_id:
581+
return
582+
583+
host = options.endpoint.hostname
584+
if not (host.endswith(".oss-cloudbox.aliyuncs.com") or
585+
host.endswith(".oss-cloudbox-control.aliyuncs.com")):
586+
return
587+
588+
keys = host.split(".")
589+
if len(keys) != 5 or not keys[0].startswith("cb-"):
590+
return
591+
options.region = keys[0]
592+
options.product = defaults.CLOUD_BOX_PRODUCT
593+
594+
571595
def _apply_operation_metadata(op_input: OperationInput, options: _Options) -> None:
572596
handlers = op_input.op_metadata.get('opm-response-handler', None)
573597
if handlers is not None:

alibabacloud_oss_v2/client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,4 +2193,19 @@ def clean_restored_object(self, request: models.CleanRestoredObjectRequest, **kw
21932193
Returns:
21942194
CleanRestoredObjectResult: Response result for CleanRestoredObject operation.
21952195
"""
2196-
return operations.clean_restored_object(self._client, request, **kwargs)
2196+
return operations.clean_restored_object(self._client, request, **kwargs)
2197+
2198+
# cloud box
2199+
def list_cloud_boxes(self, request: models.ListCloudBoxesRequest, **kwargs
2200+
) -> models.ListCloudBoxesResult:
2201+
"""
2202+
ListCloudBoxes Lists cloud box buckets that belong to the current account.
2203+
2204+
Args:
2205+
request (ListCloudBoxesRequest): Request parameters for ListCloudBoxes operation.
2206+
2207+
Returns:
2208+
ListCloudBoxesResult: Response result for ListCloudBoxes operation.
2209+
"""
2210+
2211+
return operations.list_cloud_boxes(self._client, request, **kwargs)

alibabacloud_oss_v2/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def __init__(
2727
disable_upload_crc64_check: Optional[bool] = None,
2828
disable_download_crc64_check: Optional[bool] = None,
2929
additional_headers: Optional[List[str]] = None,
30-
user_agent: Optional[str] = None
30+
user_agent: Optional[str] = None,
31+
cloud_box_id: Optional[str] = None,
32+
enable_auto_detect_cloud_box_id: Optional[bool] = None
3133
) -> None:
3234
"""
3335
Args:
@@ -67,6 +69,8 @@ def __init__(
6769
Set this to `true` to disable this feature.
6870
additional_headers: (List[str], optional): Additional signable headers.
6971
user_agent: (str, optional): The optional user specific identifier appended to the User-Agent header.
72+
cloud_box_id: (str, optional): The cloud box id.
73+
enable_auto_detect_cloud_box_id: (bool, optional): The cloud box id is automatically extracted from endpoint.
7074
"""
7175
self.region = region
7276
self.endpoint = endpoint
@@ -90,6 +94,8 @@ def __init__(
9094
self.disable_download_crc64_check = disable_download_crc64_check
9195
self.additional_headers = additional_headers
9296
self.user_agent = user_agent
97+
self.cloud_box_id = cloud_box_id
98+
self.enable_auto_detect_cloud_box_id = enable_auto_detect_cloud_box_id
9399

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

alibabacloud_oss_v2/defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# Product for signing
1111
DEFAULT_PRODUCT = "oss"
1212

13+
# CloudBoxProduct Product of cloud box for signing
14+
CLOUD_BOX_PRODUCT = "oss-cloudbox"
15+
1316
# The URL's scheme, default is https
1417
DEFAULT_ENDPOINT_SCHEME = "https"
1518

alibabacloud_oss_v2/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
from .bucket_style import *
2929
from .bucket_tags import *
3030
from .bucket_meta_query import *
31-
from .bucket_https_config import *
31+
from .bucket_https_config import *
32+
from .cloud_box import *
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from typing import Optional, List, Any
2+
from .. import serde
3+
from .bucket_basic import Owner
4+
5+
class CloudBoxProperties(serde.Model):
6+
"""
7+
Information about cloud box.
8+
"""
9+
10+
_attribute_map = {
11+
'id': {'tag': 'xml', 'rename': 'ID'},
12+
'name': {'tag': 'xml', 'rename': 'Name'},
13+
'region': {'tag': 'xml', 'rename': 'Region'},
14+
'control_endpoint': {'tag': 'xml', 'rename': 'ControlEndpoint'},
15+
'data_endpoint': {'tag': 'xml', 'rename': 'DataEndpoint'},
16+
'alias': {'tag': 'xml', 'rename': 'Alias'},
17+
}
18+
19+
_xml_map = {
20+
"name": "CloudBox"
21+
}
22+
23+
def __init__(
24+
self,
25+
id: Optional[str] = None,
26+
name: Optional[str] = None,
27+
region: Optional[str] = None,
28+
control_endpoint: Optional[str] = None,
29+
data_endpoint: Optional[str] = None,
30+
alias: Optional[str] = None,
31+
**kwargs: Any
32+
) -> None:
33+
"""
34+
Args:
35+
id (str, optional): Cloud Box ID.
36+
name (str, optional): Cloud Box Name.
37+
region (str, optional): Regions supported by Cloud Box.
38+
control_endpoint (str, optional): control endpoint.
39+
data_endpoint (str, optional): data endpoint.
40+
alias (str, optional): The alias of the access point.
41+
"""
42+
super().__init__(**kwargs)
43+
self.id = id
44+
self.name = name
45+
self.region = region
46+
self.control_endpoint = control_endpoint
47+
self.data_endpoint = data_endpoint
48+
self.alias = alias
49+
50+
51+
52+
class ListCloudBoxesRequest(serde.RequestModel):
53+
"""
54+
The request for the ListCloudBoxes operation.
55+
"""
56+
57+
_attribute_map = {
58+
"marker": {"tag": "input", "position": "query", "rename": "marker"},
59+
"max_keys": {"tag": "input", "position": "query", "rename": "max-keys", "type": "int"},
60+
"prefix": {"tag": "input", "position": "query", "rename": "prefix"},
61+
}
62+
63+
def __init__(
64+
self,
65+
marker: Optional[str] = None,
66+
max_keys: Optional[int] = None,
67+
prefix: Optional[str] = None,
68+
**kwargs: Any
69+
) -> None:
70+
"""
71+
Args:
72+
marker (str, optional): The name of the bucket from which the list operation begins.
73+
max_keys (int, optional): The maximum number of buckets that can be returned in the single query. Valid values: 1 to 1000.
74+
prefix (str, optional): The prefix that the names of returned buckets must contain.
75+
"""
76+
super().__init__(**kwargs)
77+
self.marker = marker
78+
self.max_keys = max_keys
79+
self.prefix = prefix
80+
81+
82+
class ListCloudBoxesResult(serde.ResultModel):
83+
"""
84+
The result for the ListCloudBoxes operation.
85+
"""
86+
87+
_attribute_map = {
88+
'prefix': {'tag': 'xml', 'rename': 'Prefix'},
89+
'marker': {'tag': 'xml', 'rename': 'Marker'},
90+
'max_keys': {'tag': 'xml', 'rename': 'MaxKeys'},
91+
'is_truncated': {'tag': 'xml', 'rename': 'IsTruncated', 'type': 'bool'},
92+
'next_marker': {'tag': 'xml', 'rename': 'NextMarker'},
93+
"owner": {"tag": "xml", "rename": "Owner", "type": "Owner"},
94+
"cloud_boxes": {"tag": "xml", "rename": "CloudBoxes/CloudBox", "type": "[CloudBoxProperties]"},
95+
}
96+
97+
_xml_map = {
98+
'name': 'ListCloudBoxResult'
99+
}
100+
101+
_dependency_map = {
102+
"Owner": {"new": lambda: Owner()},
103+
"CloudBoxProperties": {"new": lambda: CloudBoxProperties()},
104+
}
105+
106+
def __init__(
107+
self,
108+
prefix: Optional[str] = None,
109+
marker: Optional[str] = None,
110+
max_keys: Optional[int] = None,
111+
is_truncated: Optional[bool] = None,
112+
next_marker: Optional[str] = None,
113+
owner: Optional[Owner] = None,
114+
cloud_boxes: Optional[List[CloudBoxProperties]] = None,
115+
**kwargs: Any
116+
) -> None:
117+
"""
118+
Args:
119+
prefix (str, optional): The prefix that the names of returned buckets must contain.
120+
marker (str, optional): The name of the bucket from which the list operation begins.
121+
max_keys (int, optional): The maximum number of buckets that can be returned in the single query. Valid values: 1 to 1000.
122+
is_truncated (str, bool): Indicates whether the returned list is truncated. Valid values: * true: indicates that not all results are returned. * false: indicates that all results are returned.
123+
next_marker (str, optional): The marker for the next ListBuckets request, which can be used to return the remaining results.
124+
owner (Owner, optional): The container that stores information about the object owner.
125+
cloud_boxes ([CloudBoxProperties], optional): The container that stores information about cloud box bucket.
126+
"""
127+
super().__init__(**kwargs)
128+
self.prefix = prefix
129+
self.marker = marker
130+
self.max_keys = max_keys
131+
self.is_truncated = is_truncated
132+
self.next_marker = next_marker
133+
self.owner = owner
134+
self.cloud_boxes = cloud_boxes

alibabacloud_oss_v2/operations/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
from .bucket_style import *
2929
from .bucket_tags import *
3030
from .bucket_meta_query import *
31-
from .bucket_https_config import *
31+
from .bucket_https_config import *
32+
from .cloud_box import *
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from ..types import OperationInput, CaseInsensitiveDict
2+
from .. import serde
3+
from .. import serde_utils
4+
from .. import models
5+
from .._client import _SyncClientImpl
6+
7+
def list_cloud_boxes(client: _SyncClientImpl, request: models.ListCloudBoxesRequest, **kwargs) -> models.ListCloudBoxesResult:
8+
"""
9+
ListCloudBoxes Lists cloud box buckets that belong to the current account.
10+
11+
Args:
12+
client (_SyncClientImpl): A agent that sends the request.
13+
request (ListCloudBoxesRequest): The request for the ListCloudBoxes operation.
14+
15+
Returns:
16+
ListCloudBoxesResult: The result for the ListCloudBoxes operation.
17+
"""
18+
19+
op_input = serde.serialize_input(
20+
request=request,
21+
op_input=OperationInput(
22+
op_name='ListCloudBoxes',
23+
method='GET',
24+
headers=CaseInsensitiveDict({
25+
'Content-Type': 'application/xml',
26+
}),
27+
parameters={
28+
'cloudboxes': '',
29+
},
30+
op_metadata={'sub-resource': ['cloudboxes']},
31+
),
32+
custom_serializer=[
33+
serde_utils.add_content_md5
34+
]
35+
)
36+
37+
op_output = client.invoke_operation(op_input, **kwargs)
38+
39+
return serde.deserialize_output(
40+
result=models.ListCloudBoxesResult(),
41+
op_output=op_output,
42+
custom_deserializer=[
43+
serde.deserialize_output_xmlbody
44+
],
45+
)
46+

sample/list_cloud_boxes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import argparse
2+
import alibabacloud_oss_v2 as oss
3+
4+
parser = argparse.ArgumentParser(description="list cloud boxes sample")
5+
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
6+
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
7+
8+
9+
def main():
10+
11+
args = parser.parse_args()
12+
13+
# Loading credentials values from the environment variables
14+
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
15+
16+
# Using the SDK's default configuration
17+
cfg = oss.config.load_default()
18+
cfg.credentials_provider = credentials_provider
19+
cfg.region = args.region
20+
if args.endpoint is not None:
21+
cfg.endpoint = args.endpoint
22+
23+
client = oss.Client(cfg)
24+
25+
result = client.list_cloud_boxes(oss.ListCloudBoxesRequest())
26+
27+
print(vars(result))
28+
29+
if __name__ == "__main__":
30+
main()

0 commit comments

Comments
 (0)