-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Object Storage Gen 2 #503
Changes from 7 commits
bf1b659
dcf0227
4eb1a62
aabc2cd
271ef57
1aeddef
848ac7f
fdf833d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||||||||
from dataclasses import dataclass | ||||||||||||||
from typing import Optional | ||||||||||||||
from urllib import parse | ||||||||||||||
|
||||||||||||||
|
@@ -11,7 +12,7 @@ | |||||||||||||
Property, | ||||||||||||||
Region, | ||||||||||||||
) | ||||||||||||||
from linode_api4.objects.serializable import StrEnum | ||||||||||||||
from linode_api4.objects.serializable import JSONObject, StrEnum | ||||||||||||||
from linode_api4.util import drop_null_keys | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
@@ -28,6 +29,27 @@ class ObjectStorageKeyPermission(StrEnum): | |||||||||||||
READ_WRITE = "read_write" | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class ObjectStorageEndpointType(StrEnum): | ||||||||||||||
E0 = "E0" | ||||||||||||||
E1 = "E1" | ||||||||||||||
E2 = "E2" | ||||||||||||||
E3 = "E3" | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
@dataclass | ||||||||||||||
class ObjectStorageEndpoint(JSONObject): | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||||||||||||||
""" | ||||||||||||||
ObjectStorageEndpoint contains the core fields of an object storage endpoint object. | ||||||||||||||
|
||||||||||||||
NOTE: This is not implemented as a typical API object (Base) because Object Storage Endpoints | ||||||||||||||
cannot be refreshed, as there is no singular GET endpoint. | ||||||||||||||
""" | ||||||||||||||
|
||||||||||||||
region: str = "" | ||||||||||||||
endpoint_type: ObjectStorageEndpointType = "" | ||||||||||||||
s3_endpoint: Optional[str] = None | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class ObjectStorageBucket(DerivedBase): | ||||||||||||||
""" | ||||||||||||||
A bucket where objects are stored in. | ||||||||||||||
|
@@ -47,6 +69,8 @@ class ObjectStorageBucket(DerivedBase): | |||||||||||||
"label": Property(identifier=True), | ||||||||||||||
"objects": Property(), | ||||||||||||||
"size": Property(), | ||||||||||||||
"endpoint_type": Property(), | ||||||||||||||
"s3_endpoint": Property(), | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@classmethod | ||||||||||||||
|
@@ -63,13 +87,10 @@ def make_instance(cls, id, client, parent_id=None, json=None): | |||||||||||||
Override this method to pass in the parent_id from the _raw_json object | ||||||||||||||
when it's available. | ||||||||||||||
""" | ||||||||||||||
if json is None: | ||||||||||||||
return None | ||||||||||||||
|
||||||||||||||
cluster_or_region = json.get("region") or json.get("cluster") | ||||||||||||||
|
||||||||||||||
if parent_id is None and cluster_or_region: | ||||||||||||||
parent_id = cluster_or_region | ||||||||||||||
if json is not None: | ||||||||||||||
cluster_or_region = json.get("region") or json.get("cluster") | ||||||||||||||
if parent_id is None and cluster_or_region: | ||||||||||||||
parent_id = cluster_or_region | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional: This snippet can be simplified a bit 🙂
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice simplification! |
||||||||||||||
|
||||||||||||||
if parent_id: | ||||||||||||||
return super().make(id, client, cls, parent_id=parent_id, json=json) | ||||||||||||||
|
@@ -78,6 +99,31 @@ def make_instance(cls, id, client, parent_id=None, json=None): | |||||||||||||
"Unexpected json response when making a new Object Storage Bucket instance." | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
def access_get(self): | ||||||||||||||
zliang-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
""" | ||||||||||||||
Returns a result object which wraps the current access config for this ObjectStorageBucket. | ||||||||||||||
|
||||||||||||||
API Documentation: TODO | ||||||||||||||
|
||||||||||||||
:returns: A result object which wraps the access that this ObjectStorageBucket is currently configured with. | ||||||||||||||
:rtype: MappedObject | ||||||||||||||
""" | ||||||||||||||
result = self._client.get( | ||||||||||||||
"{}/access".format(self.api_endpoint), | ||||||||||||||
model=self, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
if not any( | ||||||||||||||
key in result | ||||||||||||||
for key in ["acl", "acl_xml", "cors_enabled", "cors_xml"] | ||||||||||||||
): | ||||||||||||||
raise UnexpectedResponseError( | ||||||||||||||
"Unexpected response when getting the bucket access config of a bucket!", | ||||||||||||||
json=result, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
return MappedObject(**result) | ||||||||||||||
|
||||||||||||||
def access_modify( | ||||||||||||||
self, | ||||||||||||||
acl: Optional[ObjectStorageACL] = None, | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"acl": "authenticated-read", | ||
"acl_xml": "<AccessControlPolicy...", | ||
"cors_enabled": true, | ||
"cors_xml": "<CORSConfiguration>..." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these two be given
Optional[...]
types to be consistent with their default values?