# Path: upcloud_api/api.py
# class API:
#     """
#     Handles basic HTTP communication with API.
#     """
# 
#     api_root = 'https://api.upcloud.com/1.3'
#     user_agent = f'upcloud-python-api/{__version__}'
# 
#     def __init__(self, token, timeout=None):
#         """
#         Initialize the API with a given Authorization token and default timeout.
#         """
#         self.token = token
#         self.timeout = timeout
# 
#     def api_request(self, method, endpoint, body=None, params=None, timeout=-1):
#         """
#         Perform a request with a given JSON body to a given endpoint in UpCloud's API.
# 
#         Handles errors with __error_middleware.
#         """
#         if method not in {'GET', 'POST', 'PUT', 'PATCH', 'DELETE'}:
#             raise Exception('Invalid/Forbidden HTTP method')
# 
#         url = f'{self.api_root}{endpoint}'
#         headers = {'Authorization': self.token, 'User-Agent': self.user_agent}
# 
#         if body:
#             data = json.dumps(body)
#             headers['Content-Type'] = 'application/json'
#         else:
#             data = None
# 
#         call_timeout = timeout if timeout != -1 else self.timeout
# 
#         res = requests.request(
#             method=method, url=url, data=data, params=params, headers=headers, timeout=call_timeout
#         )
# 
#         if res.text:
#             res_json = res.json()
#         else:
#             res_json = {}
# 
#         return self.__error_middleware(res, res_json)
# 
#     def get_request(self, endpoint, params=None, timeout=-1):
#         """
#         Perform a GET request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('GET', endpoint, params=params, timeout=timeout)
# 
#     def post_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a POST request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('POST', endpoint, body=body, timeout=timeout)
# 
#     def put_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a PUT request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('PUT', endpoint, body=body, timeout=timeout)
# 
#     def patch_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a PATCH request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('PATCH', endpoint, body=body, timeout=timeout)
# 
#     def delete_request(self, endpoint, timeout=-1):
#         """
#         Perform a DELETE request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('DELETE', endpoint, timeout=timeout)
# 
#     def __error_middleware(self, res, res_json):
#         """
#         Middleware that raises an exception when HTTP statuscode is an error code.
#         """
#         if res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]:
#             err_dict = res_json.get('error', {})
#             raise UpCloudAPIError(
#                 error_code=err_dict.get('error_code'), error_message=err_dict.get('error_message')
#             )
# 
#         return res_json
# 
# Path: upcloud_api/object_storage.py
# class ObjectStorage(UpCloudResource):
#     """
#     Class representation of UpCloud Object Storage.
#     """
# 
#     ATTRIBUTES = {
#         'uuid': None,
#         'name': None,
#         'description': None,
#         'size': None,
#         'state': None,
#         'url': None,
#         'zone': None,
#     }
# 
#     def __str__(self):
#         """
#         String representation of Object Storage.
#         """
#         return self.uuid


import datetime
from typing import List, Optional
from upcloud_api.api import API
from upcloud_api.object_storage import ObjectStorage
        A request to get details about a specific Object Storage device by the given uuid.
        """
        url = f'/object-storage/{uuid}'
        res = self.api.get_request(url)
        return ObjectStorage(cloud_manager=self, **res['object_storage'])

    def modify_object_storage(
        self,
        object_storage: str,
        access_key: Optional[str] = None,
        secret_key: Optional[str] = None,
        description: Optional[str] = None,
        size: Optional[int] = None,
    ) -> ObjectStorage:
        """
        Modify requests can be used to update the details of an Object Storage including description, access_key and secret_key.
        """
        url = f'/object-storage/{object_storage}'
        body = {'object_storage': {}}
        if access_key and secret_key:
            body['object_storage']['access_key'] = access_key
            body['object_storage']['secret_key'] = secret_key
        elif access_key or secret_key:
            raise Exception('Both keys must be provided or none')

        if description:
            body['object_storage']['description'] = description
        if size:
            body['object_storage']['size'] = size
        res = self.api.patch_request(url, body)

# Path: upcloud_api/api.py
# class API:
#     """
#     Handles basic HTTP communication with API.
#     """
# 
#     api_root = 'https://api.upcloud.com/1.3'
#     user_agent = f'upcloud-python-api/{__version__}'
# 
#     def __init__(self, token, timeout=None):
#         """
#         Initialize the API with a given Authorization token and default timeout.
#         """
#         self.token = token
#         self.timeout = timeout
# 
#     def api_request(self, method, endpoint, body=None, params=None, timeout=-1):
#         """
#         Perform a request with a given JSON body to a given endpoint in UpCloud's API.
# 
#         Handles errors with __error_middleware.
#         """
#         if method not in {'GET', 'POST', 'PUT', 'PATCH', 'DELETE'}:
#             raise Exception('Invalid/Forbidden HTTP method')
# 
#         url = f'{self.api_root}{endpoint}'
#         headers = {'Authorization': self.token, 'User-Agent': self.user_agent}
# 
#         if body:
#             data = json.dumps(body)
#             headers['Content-Type'] = 'application/json'
#         else:
#             data = None
# 
#         call_timeout = timeout if timeout != -1 else self.timeout
# 
#         res = requests.request(
#             method=method, url=url, data=data, params=params, headers=headers, timeout=call_timeout
#         )
# 
#         if res.text:
#             res_json = res.json()
#         else:
#             res_json = {}
# 
#         return self.__error_middleware(res, res_json)
# 
#     def get_request(self, endpoint, params=None, timeout=-1):
#         """
#         Perform a GET request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('GET', endpoint, params=params, timeout=timeout)
# 
#     def post_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a POST request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('POST', endpoint, body=body, timeout=timeout)
# 
#     def put_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a PUT request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('PUT', endpoint, body=body, timeout=timeout)
# 
#     def patch_request(self, endpoint, body=None, timeout=-1):
#         """
#         Perform a PATCH request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('PATCH', endpoint, body=body, timeout=timeout)
# 
#     def delete_request(self, endpoint, timeout=-1):
#         """
#         Perform a DELETE request to a given endpoint in UpCloud's API.
#         """
#         return self.api_request('DELETE', endpoint, timeout=timeout)
# 
#     def __error_middleware(self, res, res_json):
#         """
#         Middleware that raises an exception when HTTP statuscode is an error code.
#         """
#         if res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]:
#             err_dict = res_json.get('error', {})
#             raise UpCloudAPIError(
#                 error_code=err_dict.get('error_code'), error_message=err_dict.get('error_message')
#             )
# 
#         return res_json
# 
# Path: upcloud_api/object_storage.py
# class ObjectStorage(UpCloudResource):
#     """
#     Class representation of UpCloud Object Storage.
#     """
# 
#     ATTRIBUTES = {
#         'uuid': None,
#         'name': None,
#         'description': None,
#         'size': None,
#         'state': None,
#         'url': None,
#         'zone': None,
#     }
# 
#     def __str__(self):
#         """
#         String representation of Object Storage.
#         """
#         return self.uuid


# Path: upcloud_api/cloud_manager/object_storage_mixin.py
import datetime
from typing import List, Optional
from upcloud_api.api import API
from upcloud_api.object_storage import ObjectStorage

        A request to get details about a specific Object Storage device by the given uuid.
        """
        url = f'/object-storage/{uuid}'
        res = self.api.get_request(url)
        return ObjectStorage(cloud_manager=self, **res['object_storage'])

    def modify_object_storage(
        self,
        object_storage: str,
        access_key: Optional[str] = None,
        secret_key: Optional[str] = None,
        description: Optional[str] = None,
        size: Optional[int] = None,
    ) -> ObjectStorage:
        """
        Modify requests can be used to update the details of an Object Storage including description, access_key and secret_key.
        """
        url = f'/object-storage/{object_storage}'
        body = {'object_storage': {}}
        if access_key and secret_key:
            body['object_storage']['access_key'] = access_key
            body['object_storage']['secret_key'] = secret_key
        elif access_key or secret_key:
            raise Exception('Both keys must be provided or none')

        if description:
            body['object_storage']['description'] = description
        if size:
            body['object_storage']['size'] = size
        res = self.api.patch_request(url, body)

        return ObjectStorage(cloud_manager=self, **res['object_storage'])