From 1ca97d1f2c475ead034e0f0b6fe9321f10068333 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Fri, 10 Jul 2026 10:11:45 +0000 Subject: [PATCH] feat: update generated APIs --- .../scaleway_async/annotations/__init__.py | 2 + .../scaleway_async/annotations/v1/__init__.py | 69 ++ .../scaleway_async/annotations/v1/api.py | 709 ++++++++++++++++++ .../annotations/v1/marshalling.py | 478 ++++++++++++ .../scaleway_async/annotations/v1/types.py | 439 +++++++++++ scaleway/scaleway/annotations/__init__.py | 2 + scaleway/scaleway/annotations/v1/__init__.py | 69 ++ scaleway/scaleway/annotations/v1/api.py | 709 ++++++++++++++++++ .../scaleway/annotations/v1/marshalling.py | 478 ++++++++++++ scaleway/scaleway/annotations/v1/types.py | 439 +++++++++++ 10 files changed, 3394 insertions(+) create mode 100644 scaleway-async/scaleway_async/annotations/__init__.py create mode 100644 scaleway-async/scaleway_async/annotations/v1/__init__.py create mode 100644 scaleway-async/scaleway_async/annotations/v1/api.py create mode 100644 scaleway-async/scaleway_async/annotations/v1/marshalling.py create mode 100644 scaleway-async/scaleway_async/annotations/v1/types.py create mode 100644 scaleway/scaleway/annotations/__init__.py create mode 100644 scaleway/scaleway/annotations/v1/__init__.py create mode 100644 scaleway/scaleway/annotations/v1/api.py create mode 100644 scaleway/scaleway/annotations/v1/marshalling.py create mode 100644 scaleway/scaleway/annotations/v1/types.py diff --git a/scaleway-async/scaleway_async/annotations/__init__.py b/scaleway-async/scaleway_async/annotations/__init__.py new file mode 100644 index 000000000..8b74a5ed7 --- /dev/null +++ b/scaleway-async/scaleway_async/annotations/__init__.py @@ -0,0 +1,2 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. diff --git a/scaleway-async/scaleway_async/annotations/v1/__init__.py b/scaleway-async/scaleway_async/annotations/v1/__init__.py new file mode 100644 index 000000000..4dbdb856e --- /dev/null +++ b/scaleway-async/scaleway_async/annotations/v1/__init__.py @@ -0,0 +1,69 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from .types import ListAllKeysAndValuesResponseValue +from .types import BindingKey +from .types import BindingValue +from .types import ListAllKeysAndValuesResponseKey +from .types import Binding +from .types import Key +from .types import Value +from .types import CreateBindingRequest +from .types import CreateKeyRequest +from .types import CreateValueRequest +from .types import DeleteAllBindingsMatchingSRNRequest +from .types import DeleteAllBindingsMatchingSRNResponse +from .types import DeleteAllBindingsMatchingValueRequest +from .types import DeleteAllBindingsMatchingValueResponse +from .types import DeleteAllValuesMatchingKeyRequest +from .types import DeleteAllValuesMatchingKeyResponse +from .types import DeleteBindingRequest +from .types import DeleteKeyRequest +from .types import DeleteValueRequest +from .types import GetKeyRequest +from .types import GetValueRequest +from .types import ListAllKeysAndValuesRequest +from .types import ListAllKeysAndValuesResponse +from .types import ListBindingsRequest +from .types import ListBindingsResponse +from .types import ListKeysRequest +from .types import ListKeysResponse +from .types import ListValuesRequest +from .types import ListValuesResponse +from .types import UpdateKeyRequest +from .types import UpdateValueRequest +from .api import AnnotationsV1API + +__all__ = [ + "ListAllKeysAndValuesResponseValue", + "BindingKey", + "BindingValue", + "ListAllKeysAndValuesResponseKey", + "Binding", + "Key", + "Value", + "CreateBindingRequest", + "CreateKeyRequest", + "CreateValueRequest", + "DeleteAllBindingsMatchingSRNRequest", + "DeleteAllBindingsMatchingSRNResponse", + "DeleteAllBindingsMatchingValueRequest", + "DeleteAllBindingsMatchingValueResponse", + "DeleteAllValuesMatchingKeyRequest", + "DeleteAllValuesMatchingKeyResponse", + "DeleteBindingRequest", + "DeleteKeyRequest", + "DeleteValueRequest", + "GetKeyRequest", + "GetValueRequest", + "ListAllKeysAndValuesRequest", + "ListAllKeysAndValuesResponse", + "ListBindingsRequest", + "ListBindingsResponse", + "ListKeysRequest", + "ListKeysResponse", + "ListValuesRequest", + "ListValuesResponse", + "UpdateKeyRequest", + "UpdateValueRequest", + "AnnotationsV1API", +] diff --git a/scaleway-async/scaleway_async/annotations/v1/api.py b/scaleway-async/scaleway_async/annotations/v1/api.py new file mode 100644 index 000000000..15ab97f95 --- /dev/null +++ b/scaleway-async/scaleway_async/annotations/v1/api.py @@ -0,0 +1,709 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Optional + +from scaleway_core.api import API +from scaleway_core.utils import ( + validate_path_param, + fetch_all_pages_async, +) +from .types import ( + Binding, + CreateBindingRequest, + CreateKeyRequest, + CreateValueRequest, + DeleteAllBindingsMatchingSRNResponse, + DeleteAllBindingsMatchingValueResponse, + DeleteAllValuesMatchingKeyResponse, + Key, + ListAllKeysAndValuesResponse, + ListBindingsResponse, + ListKeysResponse, + ListValuesResponse, + UpdateKeyRequest, + UpdateValueRequest, + Value, +) +from .marshalling import ( + unmarshal_Binding, + unmarshal_Key, + unmarshal_Value, + unmarshal_DeleteAllBindingsMatchingSRNResponse, + unmarshal_DeleteAllBindingsMatchingValueResponse, + unmarshal_DeleteAllValuesMatchingKeyResponse, + unmarshal_ListAllKeysAndValuesResponse, + unmarshal_ListBindingsResponse, + unmarshal_ListKeysResponse, + unmarshal_ListValuesResponse, + marshal_CreateBindingRequest, + marshal_CreateKeyRequest, + marshal_CreateValueRequest, + marshal_UpdateKeyRequest, + marshal_UpdateValueRequest, +) + + +class AnnotationsV1API(API): + """ """ + + async def create_key( + self, + *, + name: str, + description: str, + organization_id: Optional[str] = None, + ) -> Key: + """ + Create an annotation key. + :param name: Name of the annotation key. + :param description: Description of the annotation key. + :param organization_id: ID of the organization. + :return: :class:`Key ` + + Usage: + :: + + result = await api.create_key( + name="example", + description="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/keys", + body=marshal_CreateKeyRequest( + CreateKeyRequest( + name=name, + description=description, + organization_id=organization_id, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + async def list_keys( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + ) -> ListKeysResponse: + """ + List of keys. + :param page: Page number. + :param page_size: Maximum number of keys on the page. + :param organization_id: ID of the organization. + :return: :class:`ListKeysResponse ` + + Usage: + :: + + result = await api.list_keys() + """ + + res = self._request( + "GET", + "/annotations/v1/keys", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListKeysResponse(res.json()) + + async def list_keys_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + ) -> list[Key]: + """ + List of keys. + :param page: Page number. + :param page_size: Maximum number of keys on the page. + :param organization_id: ID of the organization. + :return: :class:`list[Key] ` + + Usage: + :: + + result = await api.list_keys_all() + """ + + return await fetch_all_pages_async( + type=ListKeysResponse, + key="keys", + fetcher=self.list_keys, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + }, + ) + + async def get_key( + self, + *, + key_id: str, + ) -> Key: + """ + Retrieve a specific key. + :param key_id: ID of the key to retrieve. + :return: :class:`Key ` + + Usage: + :: + + result = await api.get_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "GET", + f"/annotations/v1/keys/{param_key_id}", + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + async def update_key( + self, + *, + key_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + ) -> Key: + """ + Update name or description. All associated resources will immediately display the new name. + :param key_id: ID of the key to update. + :param name: New name of the key. + :param description: New description of the key. + :return: :class:`Key ` + + Usage: + :: + + result = await api.update_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "PATCH", + f"/annotations/v1/keys/{param_key_id}", + body=marshal_UpdateKeyRequest( + UpdateKeyRequest( + key_id=key_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + async def delete_key( + self, + *, + key_id: str, + ) -> None: + """ + Delete a key definition. Fails if the key has any associated values. + :param key_id: ID of the key to delete. + + Usage: + :: + + result = await api.delete_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "DELETE", + f"/annotations/v1/keys/{param_key_id}", + ) + + self._throw_on_error(res) + + async def create_value( + self, + *, + key_id: str, + name: str, + description: str, + ) -> Value: + """ + Add a value definition to a key. + :param key_id: ID of the key the value will be bound to. + :param name: Name of the value. + :param description: Description of the value. + :return: :class:`Value ` + + Usage: + :: + + result = await api.create_value( + key_id="example", + name="example", + description="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/values", + body=marshal_CreateValueRequest( + CreateValueRequest( + key_id=key_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + async def list_values( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + key_id: Optional[str] = None, + ) -> ListValuesResponse: + """ + List all values for a key, sorted alphabetically by name. + :param page: Page number. + :param page_size: Maximum number of values on the page. + :param organization_id: ID of the organization. + :param key_id: ID of the key to list the values for. + :return: :class:`ListValuesResponse ` + + Usage: + :: + + result = await api.list_values() + """ + + res = self._request( + "GET", + "/annotations/v1/values", + params={ + "key_id": key_id, + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListValuesResponse(res.json()) + + async def list_values_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + key_id: Optional[str] = None, + ) -> list[Value]: + """ + List all values for a key, sorted alphabetically by name. + :param page: Page number. + :param page_size: Maximum number of values on the page. + :param organization_id: ID of the organization. + :param key_id: ID of the key to list the values for. + :return: :class:`list[Value] ` + + Usage: + :: + + result = await api.list_values_all() + """ + + return await fetch_all_pages_async( + type=ListValuesResponse, + key="values", + fetcher=self.list_values, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + "key_id": key_id, + }, + ) + + async def get_value( + self, + *, + value_id: str, + ) -> Value: + """ + Retrieve a specific value. + :param value_id: ID of the value to retrieve. + :return: :class:`Value ` + + Usage: + :: + + result = await api.get_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "GET", + f"/annotations/v1/values/{param_value_id}", + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + async def update_value( + self, + *, + value_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + ) -> Value: + """ + Update name or description. Global update. + :param value_id: ID of the value to update. + :param name: New name of the value. + :param description: New description of the value. + :return: :class:`Value ` + + Usage: + :: + + result = await api.update_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "PATCH", + f"/annotations/v1/values/{param_value_id}", + body=marshal_UpdateValueRequest( + UpdateValueRequest( + value_id=value_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + async def delete_value( + self, + *, + value_id: str, + ) -> None: + """ + Delete a value definition. Fails if the value is currently bound to any resource. + :param value_id: ID of the value to delete. + + Usage: + :: + + result = await api.delete_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "DELETE", + f"/annotations/v1/values/{param_value_id}", + ) + + self._throw_on_error(res) + + async def delete_all_values_matching_key( + self, + *, + key_id: str, + ) -> DeleteAllValuesMatchingKeyResponse: + """ + Delete ALL values associated with a key. Fails if any of these values are currently bound to any resource. + :param key_id: ID of the key for which to delete all values. + :return: :class:`DeleteAllValuesMatchingKeyResponse ` + + Usage: + :: + + result = await api.delete_all_values_matching_key( + key_id="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/values/delete-all-matching-key", + params={ + "key_id": key_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllValuesMatchingKeyResponse(res.json()) + + async def list_all_keys_and_values( + self, + *, + organization_id: Optional[str] = None, + ) -> ListAllKeysAndValuesResponse: + """ + List all keys and values for an organization, sorted alphabetically by key name and value name. + :param organization_id: ID of the organization. + :return: :class:`ListAllKeysAndValuesResponse ` + + Usage: + :: + + result = await api.list_all_keys_and_values() + """ + + res = self._request( + "GET", + "/annotations/v1/all-keys-and-values", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAllKeysAndValuesResponse(res.json()) + + async def create_binding( + self, + *, + srn: str, + value_id: str, + ) -> Binding: + """ + Attach a value to a resource. Fails if the resource already has a value for this key. + :param srn: Scaleway Resource Number to associate. + :param value_id: ID of the value to associate. + :return: :class:`Binding ` + + Usage: + :: + + result = await api.create_binding( + srn="example", + value_id="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/bindings", + body=marshal_CreateBindingRequest( + CreateBindingRequest( + srn=srn, + value_id=value_id, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Binding(res.json()) + + async def list_bindings( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + srn: Optional[str] = None, + value_id: Optional[str] = None, + ) -> ListBindingsResponse: + """ + List all bindings, or filter by Scaleway Resource Number or value ID. Response order by ID. + :param page: Page number. + :param page_size: Maximum number of bindings on the page. + :param organization_id: ID of the organization. + :param srn: Scaleway Resource Number for which to list all bindings. + :param value_id: Value ID for which to list all bindings. + :return: :class:`ListBindingsResponse ` + + Usage: + :: + + result = await api.list_bindings() + """ + + res = self._request( + "GET", + "/annotations/v1/bindings", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + "srn": srn, + "value_id": value_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListBindingsResponse(res.json()) + + async def list_bindings_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + srn: Optional[str] = None, + value_id: Optional[str] = None, + ) -> list[Binding]: + """ + List all bindings, or filter by Scaleway Resource Number or value ID. Response order by ID. + :param page: Page number. + :param page_size: Maximum number of bindings on the page. + :param organization_id: ID of the organization. + :param srn: Scaleway Resource Number for which to list all bindings. + :param value_id: Value ID for which to list all bindings. + :return: :class:`list[Binding] ` + + Usage: + :: + + result = await api.list_bindings_all() + """ + + return await fetch_all_pages_async( + type=ListBindingsResponse, + key="bindings", + fetcher=self.list_bindings, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + "srn": srn, + "value_id": value_id, + }, + ) + + async def delete_binding( + self, + *, + binding_id: str, + ) -> None: + """ + Detach an annotation from a resource. + :param binding_id: ID of the binding to delete. + + Usage: + :: + + result = await api.delete_binding( + binding_id="example", + ) + """ + + param_binding_id = validate_path_param("binding_id", binding_id) + + res = self._request( + "DELETE", + f"/annotations/v1/bindings/{param_binding_id}", + ) + + self._throw_on_error(res) + + async def delete_all_bindings_matching_value( + self, + *, + value_id: str, + ) -> DeleteAllBindingsMatchingValueResponse: + """ + Delete ALL bindings associated with a value. + :param value_id: ID of the value for which all bindings should be deleted. + :return: :class:`DeleteAllBindingsMatchingValueResponse ` + + Usage: + :: + + result = await api.delete_all_bindings_matching_value( + value_id="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/bindings/delete-all-matching-value", + params={ + "value_id": value_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllBindingsMatchingValueResponse(res.json()) + + async def delete_all_bindings_matching_srn( + self, + *, + srn: str, + organization_id: Optional[str] = None, + ) -> DeleteAllBindingsMatchingSRNResponse: + """ + Delete ALL bindings associated with a Scaleway Resource Number. + :param srn: Scaleway Resource Number for which all bindings should be deleted. + :param organization_id: ID of the organization. + :return: :class:`DeleteAllBindingsMatchingSRNResponse ` + + Usage: + :: + + result = await api.delete_all_bindings_matching_srn( + srn="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/bindings/delete-all-matching-srn", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "srn": srn, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllBindingsMatchingSRNResponse(res.json()) diff --git a/scaleway-async/scaleway_async/annotations/v1/marshalling.py b/scaleway-async/scaleway_async/annotations/v1/marshalling.py new file mode 100644 index 000000000..89b94e500 --- /dev/null +++ b/scaleway-async/scaleway_async/annotations/v1/marshalling.py @@ -0,0 +1,478 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Any + +from scaleway_core.profile import ProfileDefaults +from .types import ( + BindingKey, + BindingValue, + Binding, + Key, + Value, + DeleteAllBindingsMatchingSRNResponse, + DeleteAllBindingsMatchingValueResponse, + DeleteAllValuesMatchingKeyResponse, + ListAllKeysAndValuesResponseValue, + ListAllKeysAndValuesResponseKey, + ListAllKeysAndValuesResponse, + ListBindingsResponse, + ListKeysResponse, + ListValuesResponse, + CreateBindingRequest, + CreateKeyRequest, + CreateValueRequest, + UpdateKeyRequest, + UpdateValueRequest, +) + + +def unmarshal_BindingKey(data: Any) -> BindingKey: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BindingKey' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + return BindingKey(**args) + + +def unmarshal_BindingValue(data: Any) -> BindingValue: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BindingValue' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + return BindingValue(**args) + + +def unmarshal_Binding(data: Any) -> Binding: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Binding' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("srn", None) + if field is not None: + args["srn"] = field + else: + args["srn"] = None + + field = data.get("key", None) + if field is not None: + args["key"] = unmarshal_BindingKey(field) + else: + args["key"] = None + + field = data.get("value", None) + if field is not None: + args["value"] = unmarshal_BindingValue(field) + else: + args["value"] = None + + return Binding(**args) + + +def unmarshal_Key(data: Any) -> Key: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Key' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return Key(**args) + + +def unmarshal_Value(data: Any) -> Value: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Value' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("key_id", None) + if field is not None: + args["key_id"] = field + else: + args["key_id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return Value(**args) + + +def unmarshal_DeleteAllBindingsMatchingSRNResponse( + data: Any, +) -> DeleteAllBindingsMatchingSRNResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllBindingsMatchingSRNResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllBindingsMatchingSRNResponse(**args) + + +def unmarshal_DeleteAllBindingsMatchingValueResponse( + data: Any, +) -> DeleteAllBindingsMatchingValueResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllBindingsMatchingValueResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllBindingsMatchingValueResponse(**args) + + +def unmarshal_DeleteAllValuesMatchingKeyResponse( + data: Any, +) -> DeleteAllValuesMatchingKeyResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllValuesMatchingKeyResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllValuesMatchingKeyResponse(**args) + + +def unmarshal_ListAllKeysAndValuesResponseValue( + data: Any, +) -> ListAllKeysAndValuesResponseValue: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponseValue' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return ListAllKeysAndValuesResponseValue(**args) + + +def unmarshal_ListAllKeysAndValuesResponseKey( + data: Any, +) -> ListAllKeysAndValuesResponseKey: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponseKey' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + field = data.get("values", None) + if field is not None: + args["values"] = ( + [unmarshal_ListAllKeysAndValuesResponseValue(v) for v in field] + if field is not None + else None + ) + else: + args["values"] = [] + + return ListAllKeysAndValuesResponseKey(**args) + + +def unmarshal_ListAllKeysAndValuesResponse(data: Any) -> ListAllKeysAndValuesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("keys", None) + if field is not None: + args["keys"] = ( + [unmarshal_ListAllKeysAndValuesResponseKey(v) for v in field] + if field is not None + else None + ) + else: + args["keys"] = [] + + return ListAllKeysAndValuesResponse(**args) + + +def unmarshal_ListBindingsResponse(data: Any) -> ListBindingsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListBindingsResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("bindings", None) + if field is not None: + args["bindings"] = ( + [unmarshal_Binding(v) for v in field] if field is not None else None + ) + else: + args["bindings"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListBindingsResponse(**args) + + +def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListKeysResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("keys", None) + if field is not None: + args["keys"] = [unmarshal_Key(v) for v in field] if field is not None else None + else: + args["keys"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListKeysResponse(**args) + + +def unmarshal_ListValuesResponse(data: Any) -> ListValuesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListValuesResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("values", None) + if field is not None: + args["values"] = ( + [unmarshal_Value(v) for v in field] if field is not None else None + ) + else: + args["values"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListValuesResponse(**args) + + +def marshal_CreateBindingRequest( + request: CreateBindingRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.srn is not None: + output["srn"] = request.srn + + if request.value_id is not None: + output["value_id"] = request.value_id + + return output + + +def marshal_CreateKeyRequest( + request: CreateKeyRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + if request.organization_id is not None: + output["organization_id"] = request.organization_id + else: + output["organization_id"] = defaults.default_organization_id + + return output + + +def marshal_CreateValueRequest( + request: CreateValueRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.key_id is not None: + output["key_id"] = request.key_id + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output + + +def marshal_UpdateKeyRequest( + request: UpdateKeyRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output + + +def marshal_UpdateValueRequest( + request: UpdateValueRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output diff --git a/scaleway-async/scaleway_async/annotations/v1/types.py b/scaleway-async/scaleway_async/annotations/v1/types.py new file mode 100644 index 000000000..9d1a79f1f --- /dev/null +++ b/scaleway-async/scaleway_async/annotations/v1/types.py @@ -0,0 +1,439 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from __future__ import annotations + +from dataclasses import dataclass +from typing import Optional + + +@dataclass +class ListAllKeysAndValuesResponseValue: + id: str + """ + ID of the value. + """ + + name: str + """ + Name of the value. + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class BindingKey: + id: str + """ + ID of the key. + """ + + name: str + """ + Name of the key. + """ + + +@dataclass +class BindingValue: + id: str + """ + ID of the value. + """ + + name: str + """ + Name of the value. + """ + + +@dataclass +class ListAllKeysAndValuesResponseKey: + id: str + """ + ID of the key. + """ + + name: str + """ + Name of the key. + """ + + description: str + """ + Description of the key. + """ + + values: list[ListAllKeysAndValuesResponseValue] + """ + List of values associated with the key, sorted alphabetically by name. + """ + + +@dataclass +class Binding: + id: str + """ + ID of the binding. + """ + + srn: str + """ + Scaleway Resource Number associated to the binding. + """ + + key: Optional[BindingKey] = None + """ + Key associated to the binding. + """ + + value: Optional[BindingValue] = None + """ + Value associated to the binding. + """ + + +@dataclass +class Key: + id: str + """ + ID of the annotation key. + """ + + name: str + """ + Name of the annotation key. + """ + + description: str + """ + Description of the annotation key. + """ + + +@dataclass +class Value: + id: str + """ + ID of the value. + """ + + key_id: str + """ + ID of the key the value is associated to. + """ + + name: str + """ + Name of the value (e.g. "production" for a key "environment"). + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class CreateBindingRequest: + srn: str + """ + Scaleway Resource Number to associate. + """ + + value_id: str + """ + ID of the value to associate. + """ + + +@dataclass +class CreateKeyRequest: + name: str + """ + Name of the annotation key. + """ + + description: str + """ + Description of the annotation key. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class CreateValueRequest: + key_id: str + """ + ID of the key the value will be bound to. + """ + + name: str + """ + Name of the value. + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class DeleteAllBindingsMatchingSRNRequest: + srn: str + """ + Scaleway Resource Number for which all bindings should be deleted. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class DeleteAllBindingsMatchingSRNResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteAllBindingsMatchingValueRequest: + value_id: str + """ + ID of the value for which all bindings should be deleted. + """ + + +@dataclass +class DeleteAllBindingsMatchingValueResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteAllValuesMatchingKeyRequest: + key_id: str + """ + ID of the key for which to delete all values. + """ + + +@dataclass +class DeleteAllValuesMatchingKeyResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteBindingRequest: + binding_id: str + """ + ID of the binding to delete. + """ + + +@dataclass +class DeleteKeyRequest: + key_id: str + """ + ID of the key to delete. + """ + + +@dataclass +class DeleteValueRequest: + value_id: str + """ + ID of the value to delete. + """ + + +@dataclass +class GetKeyRequest: + key_id: str + """ + ID of the key to retrieve. + """ + + +@dataclass +class GetValueRequest: + value_id: str + """ + ID of the value to retrieve. + """ + + +@dataclass +class ListAllKeysAndValuesRequest: + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class ListAllKeysAndValuesResponse: + keys: list[ListAllKeysAndValuesResponseKey] + """ + List of keys with values for an organization, sorted alphabetically by name. + """ + + +@dataclass +class ListBindingsRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of bindings on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + srn: Optional[str] = None + """ + Scaleway Resource Number for which to list all bindings. + """ + + value_id: Optional[str] = None + """ + Value ID for which to list all bindings. + """ + + +@dataclass +class ListBindingsResponse: + bindings: list[Binding] + """ + List of bindings for the organization. Response order by ID. + """ + + total_count: int + """ + Total number of bindings returned. + """ + + +@dataclass +class ListKeysRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of keys on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class ListKeysResponse: + keys: list[Key] + """ + List of keys for an organization, sorted alphabetically by name. + """ + + total_count: int + """ + Total number of keys returned. + """ + + +@dataclass +class ListValuesRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of values on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + key_id: Optional[str] = None + """ + ID of the key to list the values for. + """ + + +@dataclass +class ListValuesResponse: + values: list[Value] + """ + List of values for a key, sorted alphabetically by name. + """ + + total_count: int + """ + Total number of values returned. + """ + + +@dataclass +class UpdateKeyRequest: + key_id: str + """ + ID of the key to update. + """ + + name: Optional[str] = None + """ + New name of the key. + """ + + description: Optional[str] = None + """ + New description of the key. + """ + + +@dataclass +class UpdateValueRequest: + value_id: str + """ + ID of the value to update. + """ + + name: Optional[str] = None + """ + New name of the value. + """ + + description: Optional[str] = None + """ + New description of the value. + """ diff --git a/scaleway/scaleway/annotations/__init__.py b/scaleway/scaleway/annotations/__init__.py new file mode 100644 index 000000000..8b74a5ed7 --- /dev/null +++ b/scaleway/scaleway/annotations/__init__.py @@ -0,0 +1,2 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. diff --git a/scaleway/scaleway/annotations/v1/__init__.py b/scaleway/scaleway/annotations/v1/__init__.py new file mode 100644 index 000000000..4dbdb856e --- /dev/null +++ b/scaleway/scaleway/annotations/v1/__init__.py @@ -0,0 +1,69 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from .types import ListAllKeysAndValuesResponseValue +from .types import BindingKey +from .types import BindingValue +from .types import ListAllKeysAndValuesResponseKey +from .types import Binding +from .types import Key +from .types import Value +from .types import CreateBindingRequest +from .types import CreateKeyRequest +from .types import CreateValueRequest +from .types import DeleteAllBindingsMatchingSRNRequest +from .types import DeleteAllBindingsMatchingSRNResponse +from .types import DeleteAllBindingsMatchingValueRequest +from .types import DeleteAllBindingsMatchingValueResponse +from .types import DeleteAllValuesMatchingKeyRequest +from .types import DeleteAllValuesMatchingKeyResponse +from .types import DeleteBindingRequest +from .types import DeleteKeyRequest +from .types import DeleteValueRequest +from .types import GetKeyRequest +from .types import GetValueRequest +from .types import ListAllKeysAndValuesRequest +from .types import ListAllKeysAndValuesResponse +from .types import ListBindingsRequest +from .types import ListBindingsResponse +from .types import ListKeysRequest +from .types import ListKeysResponse +from .types import ListValuesRequest +from .types import ListValuesResponse +from .types import UpdateKeyRequest +from .types import UpdateValueRequest +from .api import AnnotationsV1API + +__all__ = [ + "ListAllKeysAndValuesResponseValue", + "BindingKey", + "BindingValue", + "ListAllKeysAndValuesResponseKey", + "Binding", + "Key", + "Value", + "CreateBindingRequest", + "CreateKeyRequest", + "CreateValueRequest", + "DeleteAllBindingsMatchingSRNRequest", + "DeleteAllBindingsMatchingSRNResponse", + "DeleteAllBindingsMatchingValueRequest", + "DeleteAllBindingsMatchingValueResponse", + "DeleteAllValuesMatchingKeyRequest", + "DeleteAllValuesMatchingKeyResponse", + "DeleteBindingRequest", + "DeleteKeyRequest", + "DeleteValueRequest", + "GetKeyRequest", + "GetValueRequest", + "ListAllKeysAndValuesRequest", + "ListAllKeysAndValuesResponse", + "ListBindingsRequest", + "ListBindingsResponse", + "ListKeysRequest", + "ListKeysResponse", + "ListValuesRequest", + "ListValuesResponse", + "UpdateKeyRequest", + "UpdateValueRequest", + "AnnotationsV1API", +] diff --git a/scaleway/scaleway/annotations/v1/api.py b/scaleway/scaleway/annotations/v1/api.py new file mode 100644 index 000000000..bdcc35185 --- /dev/null +++ b/scaleway/scaleway/annotations/v1/api.py @@ -0,0 +1,709 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Optional + +from scaleway_core.api import API +from scaleway_core.utils import ( + validate_path_param, + fetch_all_pages, +) +from .types import ( + Binding, + CreateBindingRequest, + CreateKeyRequest, + CreateValueRequest, + DeleteAllBindingsMatchingSRNResponse, + DeleteAllBindingsMatchingValueResponse, + DeleteAllValuesMatchingKeyResponse, + Key, + ListAllKeysAndValuesResponse, + ListBindingsResponse, + ListKeysResponse, + ListValuesResponse, + UpdateKeyRequest, + UpdateValueRequest, + Value, +) +from .marshalling import ( + unmarshal_Binding, + unmarshal_Key, + unmarshal_Value, + unmarshal_DeleteAllBindingsMatchingSRNResponse, + unmarshal_DeleteAllBindingsMatchingValueResponse, + unmarshal_DeleteAllValuesMatchingKeyResponse, + unmarshal_ListAllKeysAndValuesResponse, + unmarshal_ListBindingsResponse, + unmarshal_ListKeysResponse, + unmarshal_ListValuesResponse, + marshal_CreateBindingRequest, + marshal_CreateKeyRequest, + marshal_CreateValueRequest, + marshal_UpdateKeyRequest, + marshal_UpdateValueRequest, +) + + +class AnnotationsV1API(API): + """ """ + + def create_key( + self, + *, + name: str, + description: str, + organization_id: Optional[str] = None, + ) -> Key: + """ + Create an annotation key. + :param name: Name of the annotation key. + :param description: Description of the annotation key. + :param organization_id: ID of the organization. + :return: :class:`Key ` + + Usage: + :: + + result = api.create_key( + name="example", + description="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/keys", + body=marshal_CreateKeyRequest( + CreateKeyRequest( + name=name, + description=description, + organization_id=organization_id, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + def list_keys( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + ) -> ListKeysResponse: + """ + List of keys. + :param page: Page number. + :param page_size: Maximum number of keys on the page. + :param organization_id: ID of the organization. + :return: :class:`ListKeysResponse ` + + Usage: + :: + + result = api.list_keys() + """ + + res = self._request( + "GET", + "/annotations/v1/keys", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListKeysResponse(res.json()) + + def list_keys_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + ) -> list[Key]: + """ + List of keys. + :param page: Page number. + :param page_size: Maximum number of keys on the page. + :param organization_id: ID of the organization. + :return: :class:`list[Key] ` + + Usage: + :: + + result = api.list_keys_all() + """ + + return fetch_all_pages( + type=ListKeysResponse, + key="keys", + fetcher=self.list_keys, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + }, + ) + + def get_key( + self, + *, + key_id: str, + ) -> Key: + """ + Retrieve a specific key. + :param key_id: ID of the key to retrieve. + :return: :class:`Key ` + + Usage: + :: + + result = api.get_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "GET", + f"/annotations/v1/keys/{param_key_id}", + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + def update_key( + self, + *, + key_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + ) -> Key: + """ + Update name or description. All associated resources will immediately display the new name. + :param key_id: ID of the key to update. + :param name: New name of the key. + :param description: New description of the key. + :return: :class:`Key ` + + Usage: + :: + + result = api.update_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "PATCH", + f"/annotations/v1/keys/{param_key_id}", + body=marshal_UpdateKeyRequest( + UpdateKeyRequest( + key_id=key_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Key(res.json()) + + def delete_key( + self, + *, + key_id: str, + ) -> None: + """ + Delete a key definition. Fails if the key has any associated values. + :param key_id: ID of the key to delete. + + Usage: + :: + + result = api.delete_key( + key_id="example", + ) + """ + + param_key_id = validate_path_param("key_id", key_id) + + res = self._request( + "DELETE", + f"/annotations/v1/keys/{param_key_id}", + ) + + self._throw_on_error(res) + + def create_value( + self, + *, + key_id: str, + name: str, + description: str, + ) -> Value: + """ + Add a value definition to a key. + :param key_id: ID of the key the value will be bound to. + :param name: Name of the value. + :param description: Description of the value. + :return: :class:`Value ` + + Usage: + :: + + result = api.create_value( + key_id="example", + name="example", + description="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/values", + body=marshal_CreateValueRequest( + CreateValueRequest( + key_id=key_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + def list_values( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + key_id: Optional[str] = None, + ) -> ListValuesResponse: + """ + List all values for a key, sorted alphabetically by name. + :param page: Page number. + :param page_size: Maximum number of values on the page. + :param organization_id: ID of the organization. + :param key_id: ID of the key to list the values for. + :return: :class:`ListValuesResponse ` + + Usage: + :: + + result = api.list_values() + """ + + res = self._request( + "GET", + "/annotations/v1/values", + params={ + "key_id": key_id, + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListValuesResponse(res.json()) + + def list_values_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + key_id: Optional[str] = None, + ) -> list[Value]: + """ + List all values for a key, sorted alphabetically by name. + :param page: Page number. + :param page_size: Maximum number of values on the page. + :param organization_id: ID of the organization. + :param key_id: ID of the key to list the values for. + :return: :class:`list[Value] ` + + Usage: + :: + + result = api.list_values_all() + """ + + return fetch_all_pages( + type=ListValuesResponse, + key="values", + fetcher=self.list_values, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + "key_id": key_id, + }, + ) + + def get_value( + self, + *, + value_id: str, + ) -> Value: + """ + Retrieve a specific value. + :param value_id: ID of the value to retrieve. + :return: :class:`Value ` + + Usage: + :: + + result = api.get_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "GET", + f"/annotations/v1/values/{param_value_id}", + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + def update_value( + self, + *, + value_id: str, + name: Optional[str] = None, + description: Optional[str] = None, + ) -> Value: + """ + Update name or description. Global update. + :param value_id: ID of the value to update. + :param name: New name of the value. + :param description: New description of the value. + :return: :class:`Value ` + + Usage: + :: + + result = api.update_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "PATCH", + f"/annotations/v1/values/{param_value_id}", + body=marshal_UpdateValueRequest( + UpdateValueRequest( + value_id=value_id, + name=name, + description=description, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Value(res.json()) + + def delete_value( + self, + *, + value_id: str, + ) -> None: + """ + Delete a value definition. Fails if the value is currently bound to any resource. + :param value_id: ID of the value to delete. + + Usage: + :: + + result = api.delete_value( + value_id="example", + ) + """ + + param_value_id = validate_path_param("value_id", value_id) + + res = self._request( + "DELETE", + f"/annotations/v1/values/{param_value_id}", + ) + + self._throw_on_error(res) + + def delete_all_values_matching_key( + self, + *, + key_id: str, + ) -> DeleteAllValuesMatchingKeyResponse: + """ + Delete ALL values associated with a key. Fails if any of these values are currently bound to any resource. + :param key_id: ID of the key for which to delete all values. + :return: :class:`DeleteAllValuesMatchingKeyResponse ` + + Usage: + :: + + result = api.delete_all_values_matching_key( + key_id="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/values/delete-all-matching-key", + params={ + "key_id": key_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllValuesMatchingKeyResponse(res.json()) + + def list_all_keys_and_values( + self, + *, + organization_id: Optional[str] = None, + ) -> ListAllKeysAndValuesResponse: + """ + List all keys and values for an organization, sorted alphabetically by key name and value name. + :param organization_id: ID of the organization. + :return: :class:`ListAllKeysAndValuesResponse ` + + Usage: + :: + + result = api.list_all_keys_and_values() + """ + + res = self._request( + "GET", + "/annotations/v1/all-keys-and-values", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAllKeysAndValuesResponse(res.json()) + + def create_binding( + self, + *, + srn: str, + value_id: str, + ) -> Binding: + """ + Attach a value to a resource. Fails if the resource already has a value for this key. + :param srn: Scaleway Resource Number to associate. + :param value_id: ID of the value to associate. + :return: :class:`Binding ` + + Usage: + :: + + result = api.create_binding( + srn="example", + value_id="example", + ) + """ + + res = self._request( + "POST", + "/annotations/v1/bindings", + body=marshal_CreateBindingRequest( + CreateBindingRequest( + srn=srn, + value_id=value_id, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_Binding(res.json()) + + def list_bindings( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + srn: Optional[str] = None, + value_id: Optional[str] = None, + ) -> ListBindingsResponse: + """ + List all bindings, or filter by Scaleway Resource Number or value ID. Response order by ID. + :param page: Page number. + :param page_size: Maximum number of bindings on the page. + :param organization_id: ID of the organization. + :param srn: Scaleway Resource Number for which to list all bindings. + :param value_id: Value ID for which to list all bindings. + :return: :class:`ListBindingsResponse ` + + Usage: + :: + + result = api.list_bindings() + """ + + res = self._request( + "GET", + "/annotations/v1/bindings", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "page": page, + "page_size": page_size or self.client.default_page_size, + "srn": srn, + "value_id": value_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListBindingsResponse(res.json()) + + def list_bindings_all( + self, + *, + page: Optional[int] = None, + page_size: Optional[int] = None, + organization_id: Optional[str] = None, + srn: Optional[str] = None, + value_id: Optional[str] = None, + ) -> list[Binding]: + """ + List all bindings, or filter by Scaleway Resource Number or value ID. Response order by ID. + :param page: Page number. + :param page_size: Maximum number of bindings on the page. + :param organization_id: ID of the organization. + :param srn: Scaleway Resource Number for which to list all bindings. + :param value_id: Value ID for which to list all bindings. + :return: :class:`list[Binding] ` + + Usage: + :: + + result = api.list_bindings_all() + """ + + return fetch_all_pages( + type=ListBindingsResponse, + key="bindings", + fetcher=self.list_bindings, + args={ + "page": page, + "page_size": page_size, + "organization_id": organization_id, + "srn": srn, + "value_id": value_id, + }, + ) + + def delete_binding( + self, + *, + binding_id: str, + ) -> None: + """ + Detach an annotation from a resource. + :param binding_id: ID of the binding to delete. + + Usage: + :: + + result = api.delete_binding( + binding_id="example", + ) + """ + + param_binding_id = validate_path_param("binding_id", binding_id) + + res = self._request( + "DELETE", + f"/annotations/v1/bindings/{param_binding_id}", + ) + + self._throw_on_error(res) + + def delete_all_bindings_matching_value( + self, + *, + value_id: str, + ) -> DeleteAllBindingsMatchingValueResponse: + """ + Delete ALL bindings associated with a value. + :param value_id: ID of the value for which all bindings should be deleted. + :return: :class:`DeleteAllBindingsMatchingValueResponse ` + + Usage: + :: + + result = api.delete_all_bindings_matching_value( + value_id="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/bindings/delete-all-matching-value", + params={ + "value_id": value_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllBindingsMatchingValueResponse(res.json()) + + def delete_all_bindings_matching_srn( + self, + *, + srn: str, + organization_id: Optional[str] = None, + ) -> DeleteAllBindingsMatchingSRNResponse: + """ + Delete ALL bindings associated with a Scaleway Resource Number. + :param srn: Scaleway Resource Number for which all bindings should be deleted. + :param organization_id: ID of the organization. + :return: :class:`DeleteAllBindingsMatchingSRNResponse ` + + Usage: + :: + + result = api.delete_all_bindings_matching_srn( + srn="example", + ) + """ + + res = self._request( + "DELETE", + "/annotations/v1/bindings/delete-all-matching-srn", + params={ + "organization_id": organization_id + or self.client.default_organization_id, + "srn": srn, + }, + ) + + self._throw_on_error(res) + return unmarshal_DeleteAllBindingsMatchingSRNResponse(res.json()) diff --git a/scaleway/scaleway/annotations/v1/marshalling.py b/scaleway/scaleway/annotations/v1/marshalling.py new file mode 100644 index 000000000..89b94e500 --- /dev/null +++ b/scaleway/scaleway/annotations/v1/marshalling.py @@ -0,0 +1,478 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. + +from typing import Any + +from scaleway_core.profile import ProfileDefaults +from .types import ( + BindingKey, + BindingValue, + Binding, + Key, + Value, + DeleteAllBindingsMatchingSRNResponse, + DeleteAllBindingsMatchingValueResponse, + DeleteAllValuesMatchingKeyResponse, + ListAllKeysAndValuesResponseValue, + ListAllKeysAndValuesResponseKey, + ListAllKeysAndValuesResponse, + ListBindingsResponse, + ListKeysResponse, + ListValuesResponse, + CreateBindingRequest, + CreateKeyRequest, + CreateValueRequest, + UpdateKeyRequest, + UpdateValueRequest, +) + + +def unmarshal_BindingKey(data: Any) -> BindingKey: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BindingKey' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + return BindingKey(**args) + + +def unmarshal_BindingValue(data: Any) -> BindingValue: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BindingValue' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + return BindingValue(**args) + + +def unmarshal_Binding(data: Any) -> Binding: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Binding' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("srn", None) + if field is not None: + args["srn"] = field + else: + args["srn"] = None + + field = data.get("key", None) + if field is not None: + args["key"] = unmarshal_BindingKey(field) + else: + args["key"] = None + + field = data.get("value", None) + if field is not None: + args["value"] = unmarshal_BindingValue(field) + else: + args["value"] = None + + return Binding(**args) + + +def unmarshal_Key(data: Any) -> Key: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Key' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return Key(**args) + + +def unmarshal_Value(data: Any) -> Value: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Value' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("key_id", None) + if field is not None: + args["key_id"] = field + else: + args["key_id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return Value(**args) + + +def unmarshal_DeleteAllBindingsMatchingSRNResponse( + data: Any, +) -> DeleteAllBindingsMatchingSRNResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllBindingsMatchingSRNResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllBindingsMatchingSRNResponse(**args) + + +def unmarshal_DeleteAllBindingsMatchingValueResponse( + data: Any, +) -> DeleteAllBindingsMatchingValueResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllBindingsMatchingValueResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllBindingsMatchingValueResponse(**args) + + +def unmarshal_DeleteAllValuesMatchingKeyResponse( + data: Any, +) -> DeleteAllValuesMatchingKeyResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DeleteAllValuesMatchingKeyResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("total_deleted", None) + if field is not None: + args["total_deleted"] = field + else: + args["total_deleted"] = 0 + + return DeleteAllValuesMatchingKeyResponse(**args) + + +def unmarshal_ListAllKeysAndValuesResponseValue( + data: Any, +) -> ListAllKeysAndValuesResponseValue: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponseValue' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return ListAllKeysAndValuesResponseValue(**args) + + +def unmarshal_ListAllKeysAndValuesResponseKey( + data: Any, +) -> ListAllKeysAndValuesResponseKey: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponseKey' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + else: + args["id"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + field = data.get("values", None) + if field is not None: + args["values"] = ( + [unmarshal_ListAllKeysAndValuesResponseValue(v) for v in field] + if field is not None + else None + ) + else: + args["values"] = [] + + return ListAllKeysAndValuesResponseKey(**args) + + +def unmarshal_ListAllKeysAndValuesResponse(data: Any) -> ListAllKeysAndValuesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAllKeysAndValuesResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("keys", None) + if field is not None: + args["keys"] = ( + [unmarshal_ListAllKeysAndValuesResponseKey(v) for v in field] + if field is not None + else None + ) + else: + args["keys"] = [] + + return ListAllKeysAndValuesResponse(**args) + + +def unmarshal_ListBindingsResponse(data: Any) -> ListBindingsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListBindingsResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("bindings", None) + if field is not None: + args["bindings"] = ( + [unmarshal_Binding(v) for v in field] if field is not None else None + ) + else: + args["bindings"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListBindingsResponse(**args) + + +def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListKeysResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("keys", None) + if field is not None: + args["keys"] = [unmarshal_Key(v) for v in field] if field is not None else None + else: + args["keys"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListKeysResponse(**args) + + +def unmarshal_ListValuesResponse(data: Any) -> ListValuesResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListValuesResponse' failed as data isn't a dictionary." + ) + + args: dict[str, Any] = {} + + field = data.get("values", None) + if field is not None: + args["values"] = ( + [unmarshal_Value(v) for v in field] if field is not None else None + ) + else: + args["values"] = [] + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + else: + args["total_count"] = 0 + + return ListValuesResponse(**args) + + +def marshal_CreateBindingRequest( + request: CreateBindingRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.srn is not None: + output["srn"] = request.srn + + if request.value_id is not None: + output["value_id"] = request.value_id + + return output + + +def marshal_CreateKeyRequest( + request: CreateKeyRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + if request.organization_id is not None: + output["organization_id"] = request.organization_id + else: + output["organization_id"] = defaults.default_organization_id + + return output + + +def marshal_CreateValueRequest( + request: CreateValueRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.key_id is not None: + output["key_id"] = request.key_id + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output + + +def marshal_UpdateKeyRequest( + request: UpdateKeyRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output + + +def marshal_UpdateValueRequest( + request: UpdateValueRequest, + defaults: ProfileDefaults, +) -> dict[str, Any]: + output: dict[str, Any] = {} + + if request.name is not None: + output["name"] = request.name + + if request.description is not None: + output["description"] = request.description + + return output diff --git a/scaleway/scaleway/annotations/v1/types.py b/scaleway/scaleway/annotations/v1/types.py new file mode 100644 index 000000000..9d1a79f1f --- /dev/null +++ b/scaleway/scaleway/annotations/v1/types.py @@ -0,0 +1,439 @@ +# This file was automatically generated. DO NOT EDIT. +# If you have any remark or suggestion do not hesitate to open an issue. +from __future__ import annotations + +from dataclasses import dataclass +from typing import Optional + + +@dataclass +class ListAllKeysAndValuesResponseValue: + id: str + """ + ID of the value. + """ + + name: str + """ + Name of the value. + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class BindingKey: + id: str + """ + ID of the key. + """ + + name: str + """ + Name of the key. + """ + + +@dataclass +class BindingValue: + id: str + """ + ID of the value. + """ + + name: str + """ + Name of the value. + """ + + +@dataclass +class ListAllKeysAndValuesResponseKey: + id: str + """ + ID of the key. + """ + + name: str + """ + Name of the key. + """ + + description: str + """ + Description of the key. + """ + + values: list[ListAllKeysAndValuesResponseValue] + """ + List of values associated with the key, sorted alphabetically by name. + """ + + +@dataclass +class Binding: + id: str + """ + ID of the binding. + """ + + srn: str + """ + Scaleway Resource Number associated to the binding. + """ + + key: Optional[BindingKey] = None + """ + Key associated to the binding. + """ + + value: Optional[BindingValue] = None + """ + Value associated to the binding. + """ + + +@dataclass +class Key: + id: str + """ + ID of the annotation key. + """ + + name: str + """ + Name of the annotation key. + """ + + description: str + """ + Description of the annotation key. + """ + + +@dataclass +class Value: + id: str + """ + ID of the value. + """ + + key_id: str + """ + ID of the key the value is associated to. + """ + + name: str + """ + Name of the value (e.g. "production" for a key "environment"). + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class CreateBindingRequest: + srn: str + """ + Scaleway Resource Number to associate. + """ + + value_id: str + """ + ID of the value to associate. + """ + + +@dataclass +class CreateKeyRequest: + name: str + """ + Name of the annotation key. + """ + + description: str + """ + Description of the annotation key. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class CreateValueRequest: + key_id: str + """ + ID of the key the value will be bound to. + """ + + name: str + """ + Name of the value. + """ + + description: str + """ + Description of the value. + """ + + +@dataclass +class DeleteAllBindingsMatchingSRNRequest: + srn: str + """ + Scaleway Resource Number for which all bindings should be deleted. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class DeleteAllBindingsMatchingSRNResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteAllBindingsMatchingValueRequest: + value_id: str + """ + ID of the value for which all bindings should be deleted. + """ + + +@dataclass +class DeleteAllBindingsMatchingValueResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteAllValuesMatchingKeyRequest: + key_id: str + """ + ID of the key for which to delete all values. + """ + + +@dataclass +class DeleteAllValuesMatchingKeyResponse: + total_deleted: int + """ + Total number of bindings deleted. + """ + + +@dataclass +class DeleteBindingRequest: + binding_id: str + """ + ID of the binding to delete. + """ + + +@dataclass +class DeleteKeyRequest: + key_id: str + """ + ID of the key to delete. + """ + + +@dataclass +class DeleteValueRequest: + value_id: str + """ + ID of the value to delete. + """ + + +@dataclass +class GetKeyRequest: + key_id: str + """ + ID of the key to retrieve. + """ + + +@dataclass +class GetValueRequest: + value_id: str + """ + ID of the value to retrieve. + """ + + +@dataclass +class ListAllKeysAndValuesRequest: + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class ListAllKeysAndValuesResponse: + keys: list[ListAllKeysAndValuesResponseKey] + """ + List of keys with values for an organization, sorted alphabetically by name. + """ + + +@dataclass +class ListBindingsRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of bindings on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + srn: Optional[str] = None + """ + Scaleway Resource Number for which to list all bindings. + """ + + value_id: Optional[str] = None + """ + Value ID for which to list all bindings. + """ + + +@dataclass +class ListBindingsResponse: + bindings: list[Binding] + """ + List of bindings for the organization. Response order by ID. + """ + + total_count: int + """ + Total number of bindings returned. + """ + + +@dataclass +class ListKeysRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of keys on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + +@dataclass +class ListKeysResponse: + keys: list[Key] + """ + List of keys for an organization, sorted alphabetically by name. + """ + + total_count: int + """ + Total number of keys returned. + """ + + +@dataclass +class ListValuesRequest: + page: Optional[int] = 0 + """ + Page number. + """ + + page_size: Optional[int] = 0 + """ + Maximum number of values on the page. + """ + + organization_id: Optional[str] = None + """ + ID of the organization. + """ + + key_id: Optional[str] = None + """ + ID of the key to list the values for. + """ + + +@dataclass +class ListValuesResponse: + values: list[Value] + """ + List of values for a key, sorted alphabetically by name. + """ + + total_count: int + """ + Total number of values returned. + """ + + +@dataclass +class UpdateKeyRequest: + key_id: str + """ + ID of the key to update. + """ + + name: Optional[str] = None + """ + New name of the key. + """ + + description: Optional[str] = None + """ + New description of the key. + """ + + +@dataclass +class UpdateValueRequest: + value_id: str + """ + ID of the value to update. + """ + + name: Optional[str] = None + """ + New name of the value. + """ + + description: Optional[str] = None + """ + New description of the value. + """