From 8df528d3bb69797b7a9fdada0549834636291f08 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Wed, 29 Jan 2025 21:22:42 -0600 Subject: [PATCH] feat: type hinting improvements --- .openapi-generator/FILES | 2 - example/example1/requirements.txt | 1 + openfga_sdk/api/open_fga_api.py | 36 +- openfga_sdk/api_client.py | 8 +- openfga_sdk/client/client.py | 182 +++++++--- openfga_sdk/client/models/assertion.py | 44 ++- openfga_sdk/client/models/batch_check_item.py | 90 ++--- .../client/models/batch_check_request.py | 9 +- .../client/models/batch_check_response.py | 9 +- .../models/batch_check_single_response.py | 57 +-- openfga_sdk/client/models/check_request.py | 99 +++--- .../models/client_batch_check_response.py | 42 ++- openfga_sdk/client/models/expand_request.py | 16 +- .../client/models/list_objects_request.py | 70 ++-- .../client/models/list_relations_request.py | 70 ++-- .../client/models/list_users_request.py | 81 ++--- .../client/models/read_changes_request.py | 30 +- openfga_sdk/client/models/tuple.py | 80 ++--- openfga_sdk/client/models/write_request.py | 44 ++- openfga_sdk/client/models/write_response.py | 22 +- .../client/models/write_single_response.py | 54 ++- .../client/models/write_transaction_opts.py | 45 ++- openfga_sdk/configuration.py | 36 +- openfga_sdk/help.py | 118 ++++--- .../models/aborted_message_response.py | 9 +- openfga_sdk/models/any.py | 9 +- openfga_sdk/models/assertion.py | 9 +- openfga_sdk/models/assertion_tuple_key.py | 13 +- openfga_sdk/models/auth_error_code.py | 9 +- openfga_sdk/models/authorization_model.py | 9 +- openfga_sdk/models/batch_check_item.py | 9 +- openfga_sdk/models/batch_check_request.py | 9 +- openfga_sdk/models/batch_check_response.py | 9 +- .../models/batch_check_single_result.py | 9 +- openfga_sdk/models/check_error.py | 9 +- openfga_sdk/models/check_request.py | 9 +- openfga_sdk/models/check_request_tuple_key.py | 13 +- openfga_sdk/models/check_response.py | 9 +- openfga_sdk/models/computed.py | 9 +- openfga_sdk/models/condition.py | 9 +- openfga_sdk/models/condition_metadata.py | 9 +- .../models/condition_param_type_ref.py | 12 +- openfga_sdk/models/consistency_preference.py | 9 +- openfga_sdk/models/contextual_tuple_keys.py | 9 +- openfga_sdk/models/create_store_request.py | 9 +- openfga_sdk/models/create_store_response.py | 9 +- openfga_sdk/models/difference.py | 9 +- openfga_sdk/models/error_code.py | 9 +- openfga_sdk/models/expand_request.py | 9 +- .../models/expand_request_tuple_key.py | 9 +- openfga_sdk/models/expand_response.py | 9 +- openfga_sdk/models/fga_object.py | 9 +- openfga_sdk/models/forbidden_response.py | 9 +- openfga_sdk/models/get_store_response.py | 9 +- openfga_sdk/models/internal_error_code.py | 9 +- .../models/internal_error_message_response.py | 9 +- openfga_sdk/models/leaf.py | 9 +- openfga_sdk/models/list_objects_request.py | 9 +- openfga_sdk/models/list_objects_response.py | 9 +- openfga_sdk/models/list_stores_response.py | 17 +- openfga_sdk/models/list_users_request.py | 9 +- openfga_sdk/models/list_users_response.py | 9 +- openfga_sdk/models/metadata.py | 9 +- openfga_sdk/models/node.py | 9 +- openfga_sdk/models/nodes.py | 9 +- openfga_sdk/models/not_found_error_code.py | 9 +- openfga_sdk/models/null_value.py | 9 +- openfga_sdk/models/object_relation.py | 9 +- .../path_unknown_error_message_response.py | 9 +- .../models/read_assertions_response.py | 12 +- .../read_authorization_model_response.py | 9 +- .../read_authorization_models_response.py | 9 +- openfga_sdk/models/read_changes_response.py | 17 +- openfga_sdk/models/read_request.py | 9 +- openfga_sdk/models/read_request_tuple_key.py | 13 +- openfga_sdk/models/read_response.py | 17 +- openfga_sdk/models/relation_metadata.py | 9 +- openfga_sdk/models/relation_reference.py | 9 +- openfga_sdk/models/relationship_condition.py | 9 +- openfga_sdk/models/source_info.py | 9 +- openfga_sdk/models/status.py | 19 +- openfga_sdk/models/store.py | 9 +- ...esult_of_streamed_list_objects_response.py | 12 +- .../models/streamed_list_objects_response.py | 9 +- openfga_sdk/models/tuple.py | 9 +- openfga_sdk/models/tuple_change.py | 9 +- openfga_sdk/models/tuple_key.py | 9 +- .../models/tuple_key_without_condition.py | 13 +- openfga_sdk/models/tuple_operation.py | 9 +- openfga_sdk/models/tuple_to_userset.py | 17 +- openfga_sdk/models/type_definition.py | 13 +- openfga_sdk/models/type_name.py | 9 +- openfga_sdk/models/typed_wildcard.py | 9 +- .../models/unauthenticated_response.py | 9 +- .../unprocessable_content_error_code.py | 9 +- .../unprocessable_content_message_response.py | 12 +- openfga_sdk/models/user.py | 13 +- openfga_sdk/models/user_type_filter.py | 9 +- openfga_sdk/models/users.py | 9 +- openfga_sdk/models/userset.py | 9 +- openfga_sdk/models/userset_tree.py | 9 +- openfga_sdk/models/userset_tree_difference.py | 9 +- .../models/userset_tree_tuple_to_userset.py | 9 +- openfga_sdk/models/userset_user.py | 9 +- openfga_sdk/models/usersets.py | 9 +- .../validation_error_message_response.py | 9 +- .../models/write_assertions_request.py | 9 +- .../write_authorization_model_request.py | 9 +- .../write_authorization_model_response.py | 9 +- openfga_sdk/models/write_request.py | 9 +- openfga_sdk/models/write_request_deletes.py | 9 +- openfga_sdk/models/write_request_writes.py | 9 +- openfga_sdk/rest.py | 83 +++-- openfga_sdk/sync/api_client.py | 16 +- openfga_sdk/sync/client/client.py | 200 ++++++++--- openfga_sdk/sync/open_fga_api.py | 36 +- openfga_sdk/sync/rest.py | 105 +++--- openfga_sdk/telemetry/attributes.py | 184 +++++----- openfga_sdk/telemetry/configuration.py | 334 ++++++++++++------ openfga_sdk/telemetry/counters.py | 9 +- openfga_sdk/telemetry/histograms.py | 9 +- openfga_sdk/telemetry/metrics.py | 137 +++++-- openfga_sdk/telemetry/utilities.py | 20 -- pyproject.toml | 17 +- requirements.txt | 1 + test-requirements.txt | 1 + test/rest_test.py | 4 +- test/sync/rest_test.py | 5 +- test/telemetry/utilities_test.py | 27 -- 129 files changed, 1820 insertions(+), 1483 deletions(-) delete mode 100644 openfga_sdk/telemetry/utilities.py delete mode 100644 test/telemetry/utilities_test.py diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index df90346..09c39d0 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -258,7 +258,6 @@ openfga_sdk/telemetry/counters.py openfga_sdk/telemetry/histograms.py openfga_sdk/telemetry/metrics.py openfga_sdk/telemetry/telemetry.py -openfga_sdk/telemetry/utilities.py openfga_sdk/validation.py pyproject.toml requirements.txt @@ -285,5 +284,4 @@ test/telemetry/counters_test.py test/telemetry/histograms_test.py test/telemetry/metrics_test.py test/telemetry/telemetry_test.py -test/telemetry/utilities_test.py test/test_open_fga_api.py diff --git a/example/example1/requirements.txt b/example/example1/requirements.txt index 1bec09a..eed4777 100644 --- a/example/example1/requirements.txt +++ b/example/example1/requirements.txt @@ -9,3 +9,4 @@ python-dateutil >= 2.8.2 urllib3 >= 2.1.0 yarl >= 1.9.4 python-dotenv >= 1, <2 + diff --git a/openfga_sdk/api/open_fga_api.py b/openfga_sdk/api/open_fga_api.py index 2845e94..56d73fc 100644 --- a/openfga_sdk/api/open_fga_api.py +++ b/openfga_sdk/api/open_fga_api.py @@ -194,7 +194,7 @@ async def batch_check_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "batch_check", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -375,7 +375,7 @@ async def check_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "check", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -543,7 +543,7 @@ async def create_store_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "create_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -692,7 +692,7 @@ async def delete_store_with_http_info(self, **kwargs): response_types_map = {} - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "delete_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -873,7 +873,7 @@ async def expand_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "expand", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1030,7 +1030,7 @@ async def get_store_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "get_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1212,7 +1212,7 @@ async def list_objects_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_objects", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1378,7 +1378,7 @@ async def list_stores_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_stores", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1559,7 +1559,7 @@ async def list_users_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_users", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1740,7 +1740,7 @@ async def read_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1917,7 +1917,7 @@ async def read_assertions_with_http_info(self, authorization_model_id, **kwargs) 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_assertions", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2092,7 +2092,7 @@ async def read_authorization_model_with_http_info(self, id, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_authorization_model", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2266,7 +2266,7 @@ async def read_authorization_models_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_authorization_models", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2450,7 +2450,7 @@ async def read_changes_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_changes", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2632,7 +2632,7 @@ async def streamed_list_objects_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "streamed_list_objects", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2813,7 +2813,7 @@ async def write_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -3007,7 +3007,7 @@ async def write_assertions_with_http_info( response_types_map = {} - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write_assertions", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -3191,7 +3191,7 @@ async def write_authorization_model_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write_authorization_model", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( diff --git a/openfga_sdk/api_client.py b/openfga_sdk/api_client.py index c38eba2..feb9ba9 100644 --- a/openfga_sdk/api_client.py +++ b/openfga_sdk/api_client.py @@ -21,7 +21,7 @@ import urllib from multiprocessing.pool import ThreadPool -from dateutil.parser import parse +from dateutil.parser import parse # type: ignore[import-untyped] import openfga_sdk.models from openfga_sdk import rest, oauth2 @@ -166,7 +166,8 @@ async def __call_api( _request_auth=None, _retry_params=None, _oauth2_client=None, - _telemetry_attributes: dict[TelemetryAttribute, str | int] = None, + _telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] + | None = None, _streaming: bool = False, ): self.configuration.is_valid() @@ -511,7 +512,8 @@ async def call_api( _request_auth=None, _retry_params=None, _oauth2_client=None, - _telemetry_attributes: dict[TelemetryAttribute, str | int] = None, + _telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] + | None = None, _streaming: bool = False, ): """Makes the HTTP request (synchronous) and returns deserialized data. diff --git a/openfga_sdk/client/client.py b/openfga_sdk/client/client.py index a4eb3b8..e087b91 100644 --- a/openfga_sdk/client/client.py +++ b/openfga_sdk/client/client.py @@ -89,22 +89,31 @@ def _chuck_array(array, max_size): ] -def set_heading_if_not_set(options: dict[str, int | str], name: str, value: str): +def set_heading_if_not_set( + options: dict[str, int | str | dict[str, int | str]] | None, + name: str, + value: str, +) -> dict[str, int | str | dict[str, int | str]]: """ Set heading to the value if it is not set """ - if options is None: - options = {} - headers = options.get("headers") - if headers is None: - headers = {} - if headers.get(name) is None: - headers[name] = value - options["headers"] = headers - return options - - -def options_to_kwargs(options: dict[str, int | str] = None): + _options: dict[str, int | str | dict[str, int | str]] = ( + options if options is not None else {} + ) + + if type(_options.get("headers")) is not dict: + _options["headers"] = {} + + if type(_options["headers"]) is dict: + if type(_options["headers"].get(name)) not in [int, str]: + _options["headers"][name] = value + + return _options + + +def options_to_kwargs( + options: dict[str, int | str | dict[str, int | str]] | None = None, +) -> dict[str, int | str | dict[str, int | str]]: """ Return kwargs with continuation_token and page_size """ @@ -121,7 +130,9 @@ def options_to_kwargs(options: dict[str, int | str] = None): return kwargs -def options_to_transaction_info(options: dict[str, int | str] = None): +def options_to_transaction_info( + options: dict[str, int | str | dict[str, int | str]] | None = None, +): """ Return the transaction info """ @@ -156,7 +167,10 @@ async def __aexit__(self, exc_type, exc_value, traceback): async def close(self): await self._api.close() - def _get_authorization_model_id(self, options: object) -> str | None: + def _get_authorization_model_id( + self, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ) -> str | None: """ Return the authorization model ID if specified in the options. Otherwise, return the authorization model ID stored in the client's configuration @@ -173,13 +187,21 @@ def _get_authorization_model_id(self, options: object) -> str | None: ) return authorization_model_id - def _get_consistency(self, options: object) -> str | None: + def _get_consistency( + self, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ) -> str | None: """ Returns the consistency requested if specified in the options. Otherwise, returns None. """ - if options is not None and "consistency" in options: - return options["consistency"] + consistency: int | str | dict[str, int | str] | None = ( + options.get("consistency", None) if options is not None else None + ) + + if type(consistency) is str: + return consistency + return None def set_store_id(self, value): @@ -210,7 +232,9 @@ def get_authorization_model_id(self): # Stores ################# - async def list_stores(self, options: dict[str, int | str] = None): + async def list_stores( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ List the stores in the system :param page_size(options) - Number of items returned per request @@ -228,7 +252,9 @@ async def list_stores(self, options: dict[str, int | str] = None): return api_response async def create_store( - self, body: CreateStoreRequest, options: dict[str, int | str] = None + self, + body: CreateStoreRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Create the stores in the system @@ -241,7 +267,9 @@ async def create_store( api_response = await self._api.create_store(body, **kwargs) return api_response - async def get_store(self, options: dict[str, int | str] = None): + async def get_store( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Get the store info in the system. Store id is from the configuration. :param header(options) - Custom headers to send alongside the request @@ -255,7 +283,9 @@ async def get_store(self, options: dict[str, int | str] = None): ) return api_response - async def delete_store(self, options: dict[str, int | str] = None): + async def delete_store( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Delete the store from the system. Store id is from the configuration. :param header(options) - Custom headers to send alongside the request @@ -273,7 +303,9 @@ async def delete_store(self, options: dict[str, int | str] = None): # Authorization Models ####################### - async def read_authorization_models(self, options: dict[str, int | str] = None): + async def read_authorization_models( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Return all the authorization models for a particular store. :param header(options) - Custom headers to send alongside the request @@ -288,7 +320,9 @@ async def read_authorization_models(self, options: dict[str, int | str] = None): return api_response async def write_authorization_model( - self, body: WriteAuthorizationModelRequest, options: dict[str, int | str] = None + self, + body: WriteAuthorizationModelRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Write authorization model. @@ -305,7 +339,9 @@ async def write_authorization_model( ) return api_response - async def read_authorization_model(self, options: dict[str, int | str] = None): + async def read_authorization_model( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Read an authorization model. :param header(options) - Custom headers to send alongside the request @@ -322,7 +358,7 @@ async def read_authorization_model(self, options: dict[str, int | str] = None): return api_response async def read_latest_authorization_model( - self, options: dict[str, int | str] = None + self, options: dict[str, int | str | dict[str, int | str]] | None = None ): """ Convenient method of reading the latest authorization model @@ -348,7 +384,9 @@ async def read_latest_authorization_model( ####################### async def read_changes( - self, body: ClientReadChangesRequest, options: dict[str, str] = None + self, + body: ClientReadChangesRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Read changes for specified type @@ -361,14 +399,23 @@ async def read_changes( :param retryParams.minWaitInMs(options) - Override the minimum wait before a retry is initiated """ kwargs = options_to_kwargs(options) - kwargs["type"] = body.type - kwargs["start_time"] = body.start_time + + if body.type is not None: + kwargs["type"] = body.type + + if body.start_time is not None: + kwargs["start_time"] = body.start_time + api_response = await self._api.read_changes( **kwargs, ) return api_response - async def read(self, body: ReadRequestTupleKey, options: dict[str, str] = None): + async def read( + self, + body: ReadRequestTupleKey, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Read changes for specified type :param body - the tuples we want to read @@ -410,7 +457,10 @@ async def read(self, body: ReadRequestTupleKey, options: dict[str, str] = None): return api_response async def _write_single_batch( - self, batch: list[ClientTuple], is_write: bool, options: dict[str, str] = None + self, + batch: list[ClientTuple], + is_write: bool, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): try: write_batch = None @@ -433,7 +483,7 @@ async def _write_batches( tuple_keys: list[ClientTuple], transaction: WriteTransactionOpts, is_write: bool, - options: dict[str, str] = None, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Internal function for write/delete batches @@ -457,7 +507,9 @@ async def _write_batches( return batch_write_responses async def _write_with_transaction( - self, body: ClientWriteRequest, options: dict[str, str] = None + self, + body: ClientWriteRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Write or deletes tuples @@ -491,7 +543,11 @@ async def _write_with_transaction( ] return ClientWriteResponse(writes=writes_response, deletes=deletes_response) - async def write(self, body: ClientWriteRequest, options: dict[str, str] = None): + async def write( + self, + body: ClientWriteRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Write or deletes tuples :param body - the write request @@ -524,7 +580,9 @@ async def write(self, body: ClientWriteRequest, options: dict[str, str] = None): return ClientWriteResponse(writes=writes_response, deletes=deletes_response) async def write_tuples( - self, body: list[ClientTuple], options: dict[str, str] = None + self, + body: list[ClientTuple], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Convenient method for writing tuples @@ -539,7 +597,9 @@ async def write_tuples( return result async def delete_tuples( - self, body: list[ClientTuple], options: dict[str, str] = None + self, + body: list[ClientTuple], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Convenient method for deleteing tuples @@ -556,7 +616,11 @@ async def delete_tuples( ####################### # Relationship Queries ####################### - async def check(self, body: ClientCheckRequest, options: dict[str, str] = None): + async def check( + self, + body: ClientCheckRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Check whether a user is authorized to access an object :param body - ClientCheckRequest defining check request @@ -590,7 +654,7 @@ async def _single_client_batch_check( self, body: ClientCheckRequest, semaphore: asyncio.Semaphore, - options: dict[str, str] = None, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a single batch request and return body in a SingleBatchCheckResponse @@ -616,7 +680,9 @@ async def _single_client_batch_check( semaphore.release() async def client_batch_check( - self, body: list[ClientCheckRequest], options: dict[str, str | int] = None + self, + body: list[ClientCheckRequest], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a set of checks @@ -655,7 +721,7 @@ async def _single_batch_check( self, body: BatchCheckRequest, semaphore: asyncio.Semaphore, - options: dict[str, str] = None, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a single BatchCheck request @@ -672,7 +738,11 @@ async def _single_batch_check( finally: semaphore.release() - async def batch_check(self, body: ClientBatchCheckRequest, options=None): + async def batch_check( + self, + body: ClientBatchCheckRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Run a batchcheck request :param body - BatchCheck request @@ -765,7 +835,11 @@ async def coro(checks): return ClientBatchCheckResponse(result) - async def expand(self, body: ClientExpandRequest, options: dict[str, str] = None): + async def expand( + self, + body: ClientExpandRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Run expand request :param body - list of ClientExpandRequest defining expand request @@ -794,7 +868,9 @@ async def expand(self, body: ClientExpandRequest, options: dict[str, str] = None return api_response async def list_objects( - self, body: ClientListObjectsRequest, options: dict[str, str] = None + self, + body: ClientListObjectsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run list object request @@ -824,7 +900,9 @@ async def list_objects( return api_response async def streamed_list_objects( - self, body: ClientListObjectsRequest, options: dict[str, str] = None + self, + body: ClientListObjectsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Retrieve all objects of the given type that the user has a relation with, using the streaming ListObjects API. @@ -861,7 +939,9 @@ async def streamed_list_objects( yield StreamedListObjectsResponse(response["result"]["object"]) async def list_relations( - self, body: ClientListRelationsRequest, options: dict[str, str] = None + self, + body: ClientListRelationsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Return all the relations for which user has a relationship with the object @@ -895,7 +975,9 @@ async def list_relations( return [i.request.relation for i in result_list] async def list_users( - self, body: ClientListUsersRequest, options: dict[str, str] = None + self, + body: ClientListUsersRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run list users request @@ -929,7 +1011,9 @@ async def list_users( ####################### # Assertions ####################### - async def read_assertions(self, options: dict[str, str] = None): + async def read_assertions( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Return the assertions :param authorization_model_id(options) - Overrides the authorization model id in the configuration @@ -945,7 +1029,9 @@ async def read_assertions(self, options: dict[str, str] = None): return api_response async def write_assertions( - self, body: list[ClientAssertion], options: dict[str, str] = None + self, + body: list[ClientAssertion], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Upsert the assertions diff --git a/openfga_sdk/client/models/assertion.py b/openfga_sdk/client/models/assertion.py index 7389e32..c8335e2 100644 --- a/openfga_sdk/client/models/assertion.py +++ b/openfga_sdk/client/models/assertion.py @@ -16,36 +16,70 @@ class ClientAssertion: ClientAssertion flattens the input necessary for an Assertion """ - def __init__(self, user: str, relation: str, object: str, expectation: bool): + def __init__( + self, + user: str, + relation: str, + object: str, + expectation: bool, + ) -> None: self._user = user self._relation = relation self._object = object self._expectation = expectation @property - def user(self): + def user(self) -> str: """ Return user """ return self._user + @user.setter + def user(self, user: str) -> None: + """ + Set user + """ + self._user = user + @property - def relation(self): + def relation(self) -> str: """ Return relation """ return self._relation + @relation.setter + def relation(self, relation: str) -> None: + """ + Set relation + """ + self._relation = relation + @property - def object(self): + def object(self) -> str: """ Return object """ return self._object + @object.setter + def object(self, object: str) -> None: + """ + Set object + """ + self._object = object + @property - def expectation(self): + def expectation(self) -> bool: """ Return expectation """ return self._expectation + + @expectation.setter + def expectation(self, expectation: bool) -> None: + """ + Set expectation + """ + self._expectation = expectation diff --git a/openfga_sdk/client/models/batch_check_item.py b/openfga_sdk/client/models/batch_check_item.py index f11e38e..0834014 100644 --- a/openfga_sdk/client/models/batch_check_item.py +++ b/openfga_sdk/client/models/batch_check_item.py @@ -16,7 +16,7 @@ from openfga_sdk.models.contextual_tuple_keys import ContextualTupleKeys -def construct_batch_item(check): +def construct_batch_item(check) -> BatchCheckItem: batch_item = BatchCheckItem( tuple_key=CheckRequestTupleKey( user=check.user, @@ -41,95 +41,97 @@ def __init__( user: str, relation: str, object: str, - correlation_id: str = None, - contextual_tuples: list[ClientTuple] = None, - context: object = None, - ): + correlation_id: str | None = None, + contextual_tuples: list[ClientTuple] | None = None, + context: dict[str, int | str] | None = None, + ) -> None: self._user = user self._relation = relation self._object = object self._correlation_id = correlation_id - self._contextual_tuples = None - if contextual_tuples: - self._contextual_tuples = contextual_tuples + self._contextual_tuples = contextual_tuples self._context = context @property - def user(self): + def user(self) -> str: """ Return user """ return self._user + @user.setter + def user(self, value: str) -> None: + """ + Set user + """ + self._user = value + @property - def relation(self): + def relation(self) -> str: """ Return relation """ return self._relation - @property - def object(self): + @relation.setter + def relation(self, value: str) -> None: """ - Return object + Set relation """ - return self._object + self._relation = value @property - def contextual_tuples(self): + def object(self) -> str: """ - Return contextual tuples + Return object """ - return self._contextual_tuples + return self._object - @property - def context(self): + @object.setter + def object(self, value: str) -> None: """ - Return context + Set object """ - return self._context + self._object = value @property - def correlation_id(self): - """ """ - return self._correlation_id - - @user.setter - def user(self, value): + def correlation_id(self) -> str | None: """ - Set user + Return correlation id """ - self._user = value + return self._correlation_id - @relation.setter - def relation(self, value): + @correlation_id.setter + def correlation_id(self, value: str | None) -> None: """ - Set relation + Set correlation id """ - self._relation = value + self._correlation_id = value - @object.setter - def object(self, value): + @property + def contextual_tuples(self) -> list[ClientTuple] | None: """ - Set object + Return contextual tuples """ - self._object = value + return self._contextual_tuples @contextual_tuples.setter - def contextual_tuples(self, value): + def contextual_tuples(self, value: list[ClientTuple] | None) -> None: """ Set contextual tuples """ self._contextual_tuples = value + @property + def context(self) -> dict[str, int | str] | None: + """ + Return context + """ + return self._context + @context.setter - def context(self, value): + def context(self, value: dict[str, int | str] | None) -> None: """ Set context """ self._context = value - - @correlation_id.setter - def correlation_id(self, value): - """ """ - self._correlation_id = value diff --git a/openfga_sdk/client/models/batch_check_request.py b/openfga_sdk/client/models/batch_check_request.py index 76c0f2b..a988e52 100644 --- a/openfga_sdk/client/models/batch_check_request.py +++ b/openfga_sdk/client/models/batch_check_request.py @@ -18,18 +18,21 @@ class ClientBatchCheckRequest: ClientBatchCheckRequest encapsulates the parameters for a BatchCheck request """ - def __init__(self, checks: list[ClientBatchCheckItem]): + def __init__( + self, + checks: list[ClientBatchCheckItem], + ) -> None: self._checks = checks @property - def checks(self): + def checks(self) -> list[ClientBatchCheckItem]: """ Return checks """ return self._checks @checks.setter - def checks(self, checks): + def checks(self, checks: list[ClientBatchCheckItem]) -> None: """ Set checks """ diff --git a/openfga_sdk/client/models/batch_check_response.py b/openfga_sdk/client/models/batch_check_response.py index c3bc075..7adb0f2 100644 --- a/openfga_sdk/client/models/batch_check_response.py +++ b/openfga_sdk/client/models/batch_check_response.py @@ -16,18 +16,21 @@ class ClientBatchCheckResponse: - def __init__(self, result: list[ClientBatchCheckSingleResponse]): + def __init__( + self, + result: list[ClientBatchCheckSingleResponse], + ) -> None: self._result = result @property - def result(self): + def result(self) -> list[ClientBatchCheckSingleResponse]: """ Return result """ return self._result @result.setter - def result(self, result): + def result(self, result: list[ClientBatchCheckSingleResponse]) -> None: """ Set result """ diff --git a/openfga_sdk/client/models/batch_check_single_response.py b/openfga_sdk/client/models/batch_check_single_response.py index 2b61ed1..8f9a604 100644 --- a/openfga_sdk/client/models/batch_check_single_response.py +++ b/openfga_sdk/client/models/batch_check_single_response.py @@ -20,67 +20,68 @@ def __init__( allowed: bool, request: ClientTuple, correlation_id: str, - error: CheckError = None, - ): + error: CheckError | None = None, + ) -> None: self._allowed = allowed self._request = request self._correlation_id = correlation_id self._error = error - # Set "false" if there was an error and allowed isn't set + + # Set `allowed` to `false` if there was an error and allowed isn't otherwise set. if error is not None and allowed is None: self._allowed = False @property - def allowed(self): + def allowed(self) -> bool: """ Return allowed """ return self._allowed - @property - def request(self): - """ - Return request - """ - return self._request - - @property - def correlation_id(self): + @allowed.setter + def allowed(self, allowed: bool) -> None: """ - Return correlation_id + Set allowed """ - return self._correlation_id + self._allowed = allowed @property - def error(self): + def request(self) -> ClientTuple: """ - Return error - """ - return self._error - - @allowed.setter - def allowed(self, allowed): - """ - Set allowed + Return request """ - self._allowed = allowed + return self._request @request.setter - def request(self, request): + def request(self, request: ClientTuple) -> None: """ Set request """ self._request = request + @property + def correlation_id(self) -> str: + """ + Return correlation_id + """ + return self._correlation_id + @correlation_id.setter - def correlation_id(self, correlation_id): + def correlation_id(self, correlation_id: str) -> None: """ Set correlation_id """ self._correlation_id = correlation_id + @property + def error(self) -> CheckError | None: + """ + Return error + """ + return self._error + @error.setter - def error(self, error): + def error(self, error: CheckError | None) -> None: """ Set error """ diff --git a/openfga_sdk/client/models/check_request.py b/openfga_sdk/client/models/check_request.py index 4653766..fdfc56f 100644 --- a/openfga_sdk/client/models/check_request.py +++ b/openfga_sdk/client/models/check_request.py @@ -13,19 +13,6 @@ from openfga_sdk.client.models.tuple import ClientTuple -def construct_check_request( - user: str, - relation: str, - object: str, - contextual_tuples: list[ClientTuple] = None, - context: object = None, -): - """ - helper function to construct the check request body - """ - return ClientCheckRequest(user, relation, object, contextual_tuples, context) - - class ClientCheckRequest: """ ClientCheckRequest encapsulates the parameters for check request @@ -36,83 +23,97 @@ def __init__( user: str, relation: str, object: str, - contextual_tuples: list[ClientTuple] = None, - context: object = None, - ): + contextual_tuples: list[ClientTuple] | None = None, + context: dict[str, int | str] | None = None, + ) -> None: self._user = user self._relation = relation self._object = object self._contextual_tuples = None + self._context = context + if contextual_tuples: self._contextual_tuples = contextual_tuples - self._context = context @property - def user(self): + def user(self) -> str: """ Return user """ return self._user - @property - def relation(self): + @user.setter + def user(self, value: str) -> None: """ - Return relation + Set user """ - return self._relation + self._user = value @property - def object(self): + def relation(self) -> str: """ - Return object + Return relation """ - return self._object + return self._relation - @property - def contextual_tuples(self): + @relation.setter + def relation(self, value: str) -> None: """ - Return contextual tuples + Set relation """ - return self._contextual_tuples + self._relation = value @property - def context(self): - """ - Return context + def object(self) -> str: """ - return self._context - - @user.setter - def user(self, value): - """ - Set user - """ - self._user = value - - @relation.setter - def relation(self, value): - """ - Set relation + Return object """ - self._relation = value + return self._object @object.setter - def object(self, value): + def object(self, value: str) -> None: """ Set object """ self._object = value + @property + def contextual_tuples(self) -> list[ClientTuple] | None: + """ + Return contextual tuples + """ + return self._contextual_tuples + @contextual_tuples.setter - def contextual_tuples(self, value): + def contextual_tuples(self, value: list[ClientTuple] | None) -> None: """ Set contextual tuples """ self._contextual_tuples = value + @property + def context(self) -> dict[str, int | str] | None: + """ + Return context + """ + return self._context + @context.setter - def context(self, value): + def context(self, value: dict[str, int | str] | None) -> None: """ Set context """ self._context = value + + +def construct_check_request( + user: str, + relation: str, + object: str, + contextual_tuples: list[ClientTuple] | None = None, + context: dict[str, int | str] | None = None, +) -> ClientCheckRequest: + """ + helper function to construct the check request body + """ + return ClientCheckRequest(user, relation, object, contextual_tuples, context) diff --git a/openfga_sdk/client/models/client_batch_check_response.py b/openfga_sdk/client/models/client_batch_check_response.py index 17fe207..d4969c9 100644 --- a/openfga_sdk/client/models/client_batch_check_response.py +++ b/openfga_sdk/client/models/client_batch_check_response.py @@ -23,42 +23,70 @@ def __init__( self, allowed: bool, request: ClientCheckRequest, - response: CheckResponse, - error: Exception = None, - ): + response: CheckResponse | None = None, + error: Exception | None = None, + ) -> None: self._allowed = allowed self._request = request self._response = response self._error = error @property - def allowed(self): + def allowed(self) -> bool: """ Return whether request is allowed """ return self._allowed + @allowed.setter + def allowed(self, value: bool) -> None: + """ + Set whether request is allowed + """ + self._allowed = value + @property - def request(self): + def request(self) -> ClientCheckRequest: """ Return original request """ return self._request + @request.setter + def request(self, value: ClientCheckRequest) -> None: + """ + Set original request + """ + self._request = value + @property - def response(self): + def response(self) -> CheckResponse | None: """ Return original request """ return self._response + @response.setter + def response(self, value: CheckResponse | None) -> None: + """ + Set original request + """ + self._response = value + @property - def error(self): + def error(self) -> Exception | None: """ Return error associated with batch request (if any) """ return self._error + @error.setter + def error(self, value: Exception | None) -> None: + """ + Set error associated with batch request + """ + self._error = value + def __str__(self): """ Return the class string diff --git a/openfga_sdk/client/models/expand_request.py b/openfga_sdk/client/models/expand_request.py index 222169c..62b61d0 100644 --- a/openfga_sdk/client/models/expand_request.py +++ b/openfga_sdk/client/models/expand_request.py @@ -22,49 +22,49 @@ def __init__( self, relation: str, object: str, - contextual_tuples: list[ClientTuple] = None, - ): + contextual_tuples: list[ClientTuple] | None = None, + ) -> None: self._relation = relation self._object = object self._contextual_tuples = contextual_tuples @property - def relation(self): + def relation(self) -> str: """ Return relation """ return self._relation @relation.setter - def relation(self, value): + def relation(self, value: str) -> None: """ Set relation """ self._relation = value @property - def object(self): + def object(self) -> str: """ Return object """ return self._object @object.setter - def object(self, value): + def object(self, value: str) -> None: """ Set object """ self._object = value @property - def contextual_tuples(self): + def contextual_tuples(self) -> list[ClientTuple] | None: """ Return contextual_tuples """ return self._contextual_tuples @contextual_tuples.setter - def contextual_tuples(self, value): + def contextual_tuples(self, value: list[ClientTuple] | None) -> None: """ Set contextual tuples """ diff --git a/openfga_sdk/client/models/list_objects_request.py b/openfga_sdk/client/models/list_objects_request.py index d63e767..a78f34f 100644 --- a/openfga_sdk/client/models/list_objects_request.py +++ b/openfga_sdk/client/models/list_objects_request.py @@ -23,9 +23,9 @@ def __init__( user: str, relation: str, type: str, - contextual_tuples: list[ClientTuple] = None, - context: object = None, - ): + contextual_tuples: list[ClientTuple] | None = None, + context: object | None = None, + ) -> None: self._user = user self._relation = relation self._type = type @@ -33,70 +33,70 @@ def __init__( self._context = context @property - def user(self): + def user(self) -> str: """ Return user """ return self._user - @property - def relation(self): + @user.setter + def user(self, value: str) -> None: """ - Return relation + Set user """ - return self._relation + self._user = value @property - def type(self): + def relation(self) -> str: """ - Return type + Return relation """ - return self._type + return self._relation - @property - def contextual_tuples(self): + @relation.setter + def relation(self, value: str) -> None: """ - Return contextual_tuples + Set relation """ - return self._contextual_tuples + self._relation = value @property - def context(self): - """ - Return context - """ - return self._context - - @user.setter - def user(self, value): + def type(self) -> str: """ - Set user - """ - self._user = value - - @relation.setter - def relation(self, value): - """ - Set relation + Return type """ - self._relation = value + return self._type @type.setter - def type(self, value): + def type(self, value: str) -> None: """ Set type """ self._type = value + @property + def contextual_tuples(self) -> list[ClientTuple] | None: + """ + Return contextual_tuples + """ + return self._contextual_tuples + @contextual_tuples.setter - def contextual_tuples(self, value): + def contextual_tuples(self, value: list[ClientTuple] | None) -> None: """ Set contextual tuples """ self._contextual_tuples = value + @property + def context(self) -> object | None: + """ + Return context + """ + return self._context + @context.setter - def context(self, value): + def context(self, value: object | None) -> None: """ Set context """ diff --git a/openfga_sdk/client/models/list_relations_request.py b/openfga_sdk/client/models/list_relations_request.py index ca91b18..6873bc6 100644 --- a/openfga_sdk/client/models/list_relations_request.py +++ b/openfga_sdk/client/models/list_relations_request.py @@ -23,9 +23,9 @@ def __init__( user: str, relations: list[str], object: str, - contextual_tuples: list[ClientTuple] = None, - context: object = None, - ): + contextual_tuples: list[ClientTuple] | None = None, + context: dict[str, int | str] | None = None, + ) -> None: self._user = user self._relations = relations self._object = object @@ -33,70 +33,70 @@ def __init__( self._context = context @property - def user(self): + def user(self) -> str: """ Return user """ return self._user - @property - def relations(self): + @user.setter + def user(self, value: str) -> None: """ - Return relations + Set user """ - return self._relations + self._user = value @property - def object(self): + def relations(self) -> list[str]: """ - Return object + Return relations """ - return self._object + return self._relations - @property - def contextual_tuples(self): + @relations.setter + def relations(self, value: list[str]) -> None: """ - Return contextual_tuples + Set relations """ - return self._contextual_tuples + self._relations = value @property - def context(self): - """ - Return context - """ - return self._context - - @user.setter - def user(self, value): + def object(self) -> str: """ - Set user - """ - self._user = value - - @relations.setter - def relations(self, value): - """ - Set relations + Return object """ - self._relations = value + return self._object @object.setter - def object(self, value): + def object(self, value: str) -> None: """ Set object """ self._object = value + @property + def contextual_tuples(self) -> list[ClientTuple] | None: + """ + Return contextual_tuples + """ + return self._contextual_tuples + @contextual_tuples.setter - def contextual_tuples(self, value): + def contextual_tuples(self, value: list[ClientTuple] | None) -> None: """ Set contextual tuples """ self._contextual_tuples = value + @property + def context(self) -> dict[str, int | str] | None: + """ + Return context + """ + return self._context + @context.setter - def context(self, value): + def context(self, value: dict[str, int | str] | None) -> None: """ Set context """ diff --git a/openfga_sdk/client/models/list_users_request.py b/openfga_sdk/client/models/list_users_request.py index 27a00c1..c412241 100644 --- a/openfga_sdk/client/models/list_users_request.py +++ b/openfga_sdk/client/models/list_users_request.py @@ -22,12 +22,12 @@ class ClientListUsersRequest: def __init__( self, - object: FgaObject = None, - relation: str = None, - user_filters: list[UserTypeFilter] = None, - contextual_tuples: list[ClientTuple] = None, - context: object = None, - ): + object: FgaObject | None = None, + relation: str | None = None, + user_filters: list[UserTypeFilter] | None = None, + contextual_tuples: list[ClientTuple] | None = None, + context: dict[str, int | str] | None = None, + ) -> None: self._object = object self._relation = relation self._user_filters = user_filters @@ -35,9 +35,9 @@ def __init__( self._context = context @property - def object(self) -> FgaObject: - """Gets the object of this ClientListUsersRequest. - + def object(self) -> FgaObject | None: + """ + Gets the object of this ClientListUsersRequest. :return: The object of this ClientListUsersRequest. :rtype: str @@ -45,20 +45,19 @@ def object(self) -> FgaObject: return self._object @object.setter - def object(self, object: FgaObject): - """Sets the object of this ClientListUsersRequest. - + def object(self, object: FgaObject | None) -> None: + """ + Sets the object of this ClientListUsersRequest. :param object: The object of this ClientListUsersRequest. :type object: str """ - self._object = object @property - def relation(self) -> str: - """Gets the relation of this ClientListUsersRequest. - + def relation(self) -> str | None: + """ + Gets the relation of this ClientListUsersRequest. :return: The relation of this ClientListUsersRequest. :rtype: str @@ -66,20 +65,19 @@ def relation(self) -> str: return self._relation @relation.setter - def relation(self, relation: str): - """Sets the relation of this ClientListUsersRequest. - + def relation(self, relation: str | None) -> None: + """ + Sets the relation of this ClientListUsersRequest. :param relation: The relation of this ClientListUsersRequest. :type relation: str """ - self._relation = relation @property - def user_filters(self) -> list[UserTypeFilter]: - """Gets the user_filters of this ClientListUsersRequest. - + def user_filters(self) -> list[UserTypeFilter] | None: + """ + Gets the user_filters of this ClientListUsersRequest. :return: The user_filters of this ClientListUsersRequest. :rtype: str @@ -87,20 +85,19 @@ def user_filters(self) -> list[UserTypeFilter]: return self._user_filters @user_filters.setter - def user_filters(self, user_filters: list[UserTypeFilter]): - """Sets the user_filters of this ClientListUsersRequest. - + def user_filters(self, user_filters: list[UserTypeFilter] | None) -> None: + """ + Sets the user_filters of this ClientListUsersRequest. :param user_filters: The user_filters of this ClientListUsersRequest. :type user_filters: str """ - self._user_filters = user_filters @property - def contextual_tuples(self) -> list[ClientTuple]: - """Gets the contextual_tuples of this ClientListUsersRequest. - + def contextual_tuples(self) -> list[ClientTuple] | None: + """ + Gets the contextual_tuples of this ClientListUsersRequest. :return: The contextual_tuples of this ClientListUsersRequest. :rtype: ContextualTupleKeys @@ -108,35 +105,29 @@ def contextual_tuples(self) -> list[ClientTuple]: return self._contextual_tuples @contextual_tuples.setter - def contextual_tuples(self, contextual_tuples: list[ClientTuple]): - """Sets the contextual_tuples of this ClientListUsersRequest. - + def contextual_tuples(self, contextual_tuples: list[ClientTuple] | None) -> None: + """ + Sets the contextual_tuples of this ClientListUsersRequest. :param contextual_tuples: The contextual_tuples of this ClientListUsersRequest. :type contextual_tuples: ContextualTupleKeys """ - self._contextual_tuples = contextual_tuples @property - def context(self) -> object: - """Gets the context of this ClientListUsersRequest. + def context(self) -> dict[str, int | str] | None: + """ + Gets the context of this ClientListUsersRequest. Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. - - :return: The context of this ClientListUsersRequest. - :rtype: object """ return self._context @context.setter - def context(self, context: object): - """Sets the context of this ClientListUsersRequest. + def context(self, context: dict[str, int | str] | None) -> None: + """ + Sets the context of this ClientListUsersRequest. Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. - - :param context: The context of this ClientListUsersRequest. - :type context: object """ - self._context = context diff --git a/openfga_sdk/client/models/read_changes_request.py b/openfga_sdk/client/models/read_changes_request.py index 14f4cad..a8257d1 100644 --- a/openfga_sdk/client/models/read_changes_request.py +++ b/openfga_sdk/client/models/read_changes_request.py @@ -16,20 +16,44 @@ class ClientReadChangesRequest: ClientReadChangesRequest encapsulates the parameters required to read changes """ - def __init__(self, type: str, start_time: str = None): + def __init__( + self, + type: str, + start_time: str | None = None, + ): self._type = type self._startTime = start_time @property - def type(self): + def type(self) -> str: """ Return type """ return self._type + @type.setter + def type( + self, + value: str, + ) -> None: + """ + Set type + """ + self._type = value + @property - def start_time(self): + def start_time(self) -> str | None: """ Return startTime """ return self._startTime + + @start_time.setter + def start_time( + self, + value: str | None, + ) -> None: + """ + Set startTime + """ + self._startTime = value diff --git a/openfga_sdk/client/models/tuple.py b/openfga_sdk/client/models/tuple.py index 23246ba..5979ebb 100644 --- a/openfga_sdk/client/models/tuple.py +++ b/openfga_sdk/client/models/tuple.py @@ -25,79 +25,59 @@ def __init__( relation: str, object: str, condition: RelationshipCondition | None = None, - ): + ) -> None: self._user = user self._relation = relation self._object = object self._condition = condition - def __eq__(self, other): - return ( + def __eq__(self, other) -> bool: + if ( self.user == other.user and self.relation == other.relation and self.object == other.object - ) - - @property - def user(self): - """ - Return user - """ - return self._user + and self.condition == other.condition + ): + return True - @property - def relation(self): - """ - Return relation - """ - return self._relation + return False @property - def object(self): - """ - Return object - """ - return self._object - - @property - def condition(self): - """ - Return condition - """ - return self._condition + def user(self) -> str: + return self._user @user.setter - def user(self, value): - """ - Set user - """ + def user(self, value: str) -> None: self._user = value + @property + def relation(self) -> str: + return self._relation + @relation.setter - def relation(self, value): - """ - Set relation - """ + def relation(self, value: str) -> None: self._relation = value + @property + def object(self) -> str: + return self._object + @object.setter - def object(self, value): - """ - Set object - """ + def object(self, value: str) -> None: self._object = value + @property + def condition(self) -> RelationshipCondition | None: + return self._condition + @condition.setter - def condition(self, value): - """ - Set condition - """ + def condition(self, value: RelationshipCondition | None) -> None: self._condition = value @property - def tuple_key(self): + def tuple_key(self) -> TupleKey: """ - Return the tuple as tuple_key + Return the ClientTuple as TupleKey """ return TupleKey( object=self.object, @@ -107,11 +87,11 @@ def tuple_key(self): ) -def convert_tuple_keys(lists: list[ClientTuple]): +def convert_tuple_keys(lists: list[ClientTuple]) -> list[TupleKey] | None: """ Return the items as tuple_keys """ if lists is None: return None - items = map(lambda item: item.tuple_key, lists) - return list(items) + + return list(map(lambda item: item.tuple_key, lists)) diff --git a/openfga_sdk/client/models/write_request.py b/openfga_sdk/client/models/write_request.py index 46c1186..f511659 100644 --- a/openfga_sdk/client/models/write_request.py +++ b/openfga_sdk/client/models/write_request.py @@ -21,55 +21,67 @@ class ClientWriteRequest: """ def __init__( - self, writes: list[ClientTuple] = None, deletes: list[ClientTuple] = None - ): + self, + writes: list[ClientTuple] | None = None, + deletes: list[ClientTuple] | None = None, + ) -> None: self._writes = writes self._deletes = deletes @property - def writes(self): + def writes(self) -> list[ClientTuple] | None: """ Return writes """ return self._writes - @property - def deletes(self): - """ - Return deletes - """ - return self._deletes - @writes.setter - def writes(self, value): + def writes(self, value: list[ClientTuple] | None) -> None: """ Set writes """ self._writes = value + @property + def deletes(self) -> list[ClientTuple] | None: + """ + Return deletes + """ + return self._deletes + @deletes.setter - def deletes(self, value): + def deletes(self, value: list[ClientTuple] | None) -> None: """ Set deletes """ self._deletes = value @property - def writes_tuple_keys(self): + def writes_tuple_keys(self) -> WriteRequestWrites | None: """ Return the writes as tuple keys """ - keys = convert_tuple_keys(self.writes) + if self._writes is None: + return None + + keys = convert_tuple_keys(self._writes) + if keys is None: return None + return WriteRequestWrites(tuple_keys=keys) @property - def deletes_tuple_keys(self): + def deletes_tuple_keys(self) -> WriteRequestDeletes | None: """ Return the delete as tuple keys """ - keys = convert_tuple_keys(self.deletes) + if self._deletes is None: + return None + + keys = convert_tuple_keys(self._deletes) + if keys is None: return None + return WriteRequestDeletes(tuple_keys=keys) diff --git a/openfga_sdk/client/models/write_response.py b/openfga_sdk/client/models/write_response.py index c35e799..4e607eb 100644 --- a/openfga_sdk/client/models/write_response.py +++ b/openfga_sdk/client/models/write_response.py @@ -20,22 +20,36 @@ class ClientWriteResponse: def __init__( self, - writes: list[ClientWriteSingleResponse], - deletes: list[ClientWriteSingleResponse], - ): + writes: list[ClientWriteSingleResponse] | None = None, + deletes: list[ClientWriteSingleResponse] | None = None, + ) -> None: self._writes = writes self._deletes = deletes @property - def writes(self): + def writes(self) -> list[ClientWriteSingleResponse] | None: """ Return the writes response """ return self._writes + @writes.setter + def writes(self, value: list[ClientWriteSingleResponse] | None) -> None: + """ + Set the writes response + """ + self._writes = value + @property def deletes(self): """ Return the delete response """ return self._deletes + + @deletes.setter + def deletes(self, value: list[ClientWriteSingleResponse] | None) -> None: + """ + Set the delete response + """ + self._deletes = value diff --git a/openfga_sdk/client/models/write_single_response.py b/openfga_sdk/client/models/write_single_response.py index b6eebee..b99b901 100644 --- a/openfga_sdk/client/models/write_single_response.py +++ b/openfga_sdk/client/models/write_single_response.py @@ -13,21 +13,17 @@ from openfga_sdk.client.models.tuple import ClientTuple -def construct_write_single_response( - tuple_key: ClientTuple, success: bool, error: Exception = None -): - """ - Helper function to return a single write response - """ - return ClientWriteSingleResponse(tuple_key, success, error) - - class ClientWriteSingleResponse: """ ClientWriteSingleResponse encapsulates the response of a single write """ - def __init__(self, tuple_key: ClientTuple, success: bool, error: Exception = None): + def __init__( + self, + tuple_key: ClientTuple, + success: bool, + error: Exception | None = None, + ) -> None: self._tuple_key = tuple_key self._success = success self._error = error @@ -40,22 +36,54 @@ def __eq__(self, other): ) @property - def tuple_key(self): + def tuple_key(self) -> ClientTuple: """ Return tuple_key """ return self._tuple_key + @tuple_key.setter + def tuple_key(self, value: ClientTuple) -> None: + """ + Set tuple_key + """ + self._tuple_key = value + @property - def success(self): + def success(self) -> bool: """ Return success """ return self._success + @success.setter + def success(self, value: bool) -> None: + """ + Set success + """ + self._success = value + @property - def error(self): + def error(self) -> Exception | None: """ Return error """ return self._error + + @error.setter + def error(self, value: Exception | None) -> None: + """ + Set error + """ + self._error = value + + +def construct_write_single_response( + tuple_key: ClientTuple, + success: bool, + error: Exception | None = None, +) -> ClientWriteSingleResponse: + """ + Helper function to return a single write response + """ + return ClientWriteSingleResponse(tuple_key, success, error) diff --git a/openfga_sdk/client/models/write_transaction_opts.py b/openfga_sdk/client/models/write_transaction_opts.py index f222dab..0e914a5 100644 --- a/openfga_sdk/client/models/write_transaction_opts.py +++ b/openfga_sdk/client/models/write_transaction_opts.py @@ -21,48 +21,57 @@ def __init__( disabled: bool = False, max_per_chunk: int = 1, max_parallel_requests: int = 10, - ): + ) -> None: self._disabled = disabled self._max_per_chunk = max_per_chunk self._max_parallel_requests = max_parallel_requests @property - def disabled(self): + def disabled(self) -> bool: """ Return disabled """ return self._disabled - @property - def max_per_chunk(self): + @disabled.setter + def disabled( + self, + value: bool, + ) -> None: """ - Return max per chunk + Set disabled """ - return self._max_per_chunk + self._disabled = value @property - def max_parallel_requests(self): - """ - Return max parallel requests - """ - return self._max_parallel_requests - - @disabled.setter - def disabled(self, value): + def max_per_chunk(self) -> int: """ - Set disabled + Return max per chunk """ - self._disabled = value + return self._max_per_chunk @max_per_chunk.setter - def max_per_chunk(self, value): + def max_per_chunk( + self, + value: int, + ) -> None: """ Set max_per_chunk """ self._max_per_chunk = value + @property + def max_parallel_requests(self) -> int: + """ + Return max parallel requests + """ + return self._max_parallel_requests + @max_parallel_requests.setter - def max_parallel_requests(self, value): + def max_parallel_requests( + self, + value: int, + ) -> None: """ Set max_parallel_requests """ diff --git a/openfga_sdk/configuration.py b/openfga_sdk/configuration.py index b8b0a01..5208d67 100644 --- a/openfga_sdk/configuration.py +++ b/openfga_sdk/configuration.py @@ -165,16 +165,20 @@ def __init__( server_operation_variables=None, ssl_ca_cert=None, api_url=None, # TODO: restructure when removing api_scheme/api_host - telemetry: dict[ - TelemetryConfigurationType | str, - TelemetryMetricsConfiguration - | dict[ - TelemetryHistogram | TelemetryCounter, - TelemetryMetricConfiguration | dict[TelemetryAttribute, bool] | None, + telemetry: ( + dict[ + TelemetryConfigurationType | str, + TelemetryMetricsConfiguration + | dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None, ] - | None, - ] - | None = None, + | None + ) = None, timeout_millisec: int | None = None, ): """Constructor""" @@ -433,13 +437,14 @@ def telemetry(self) -> TelemetryConfiguration | None: def telemetry( self, value: ( - dict[ + TelemetryConfiguration + | dict[ TelemetryConfigurationType | str, TelemetryMetricsConfiguration | dict[ - TelemetryHistogram | TelemetryCounter, + TelemetryHistogram | TelemetryCounter | str, TelemetryMetricConfiguration - | dict[TelemetryAttribute, bool] + | dict[TelemetryAttribute | str, bool] | None, ] | None, @@ -449,12 +454,13 @@ def telemetry( ) -> None: """Set the telemetry configuration""" if value is not None: + if isinstance(value, TelemetryConfiguration): + self._telemetry = value + return + if isinstance(value, dict): self._telemetry = TelemetryConfiguration(value) return - elif isinstance(value, TelemetryConfiguration): - self._telemetry = value - return self._telemetry = None diff --git a/openfga_sdk/help.py b/openfga_sdk/help.py index 636afd9..7a7cd79 100644 --- a/openfga_sdk/help.py +++ b/openfga_sdk/help.py @@ -13,89 +13,105 @@ import json import platform import sys -from collections import OrderedDict - -import opentelemetry.version from . import __version__ as openfga_sdk_version -try: - import urllib3 +def get_urllib3_version() -> str: + try: + import urllib3 - urllib3_version = urllib3.__version__ -except ModuleNotFoundError: - urllib3_version = "" + return urllib3.__version__ + except ModuleNotFoundError: + return "" -try: - import dateutil - dateutil_version = dateutil.__version__ -except ModuleNotFoundError: - dateutil_version = "" +def get_dateutil_version() -> str: + try: + import dateutil # type: ignore[import-untyped] -try: - import aiohttp + version = dateutil.__version__ - aiohttp_version = aiohttp.__version__ -except ModuleNotFoundError: - aiohttp_version = "" + if type(version) is not str: + try: + version = str(version) + except Exception: + pass -try: - import opentelemetry + if type(version) is str: + return version - opentelemetry_version = opentelemetry.version.__version__ -except ModuleNotFoundError: - opentelemetry_version = "" + except ModuleNotFoundError: + pass + return "" -def info() -> dict[str, dict[str, str]]: + +def get_aiohttp_version() -> str: + try: + import aiohttp + + return aiohttp.__version__ + except ModuleNotFoundError: + return "" + + +def get_opentelemetry_version() -> str: + try: + import opentelemetry.version + + return opentelemetry.version.__version__ + except ModuleNotFoundError: + return "" + + +def info() -> dict[str, str | dict[str, str] | dict[str, dict[str, str]]]: """ Generate information for a bug report. Based on the requests package help utility module. """ + platform_info: dict[str, str] = {"system": "Unknown", "release": "Unknown"} + implementation_version: str = "Unknown" + try: - platform_info = { - "system": platform.system(), - "release": platform.release(), - } - except OSError: - platform_info = {"system": "Unknown", "release": "Unknown"} + platform_info["system"] = platform.system() + platform_info["release"] = platform.release() + except Exception: + pass - implementation = platform.python_implementation() + implementation: str = platform.python_implementation() if implementation == "CPython": implementation_version = platform.python_version() - elif implementation == "PyPy": + + if implementation == "PyPy": pypy_version_info = sys.pypy_version_info # type: ignore[attr-defined] + implementation_version = ( f"{pypy_version_info.major}." f"{pypy_version_info.minor}." f"{pypy_version_info.micro}" ) + if pypy_version_info.releaselevel != "final": implementation_version = "".join( [implementation_version, pypy_version_info.releaselevel] ) - else: - implementation_version = "Unknown" - - return OrderedDict( - { - "platform": platform_info, - "implementation": { - "name": implementation, - "version": implementation_version, - }, - "openfga_sdk": {"version": openfga_sdk_version}, - "dependencies": { - "urllib3": {"version": urllib3_version}, - "python-dateutil": {"version": dateutil_version}, - "aiohttp": {"version": aiohttp_version}, - "opentelemetry": {"version": opentelemetry_version}, - }, - } - ) + + return { + "platform": platform_info, + "implementation": { + "name": implementation, + "version": implementation_version, + }, + "openfga_sdk": {"version": openfga_sdk_version}, + "dependencies": { + "urllib3": {"version": get_urllib3_version()}, + "python-dateutil": {"version": get_dateutil_version()}, + "aiohttp": {"version": get_aiohttp_version()}, + "opentelemetry": {"version": get_opentelemetry_version()}, + }, + } def main() -> None: diff --git a/openfga_sdk/models/aborted_message_response.py b/openfga_sdk/models/aborted_message_response.py index 8150d35..0608a3e 100644 --- a/openfga_sdk/models/aborted_message_response.py +++ b/openfga_sdk/models/aborted_message_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class AbortedMessageResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "str", "message": "str"} + openapi_types: dict[str, str] = {"code": "str", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """AbortedMessageResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/any.py b/openfga_sdk/models/any.py index 2b1214b..7de2051 100644 --- a/openfga_sdk/models/any.py +++ b/openfga_sdk/models/any.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Any: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"type": "str"} + openapi_types: dict[str, str] = {"type": "str"} - attribute_map = {"type": "@type"} + attribute_map: dict[str, str] = {"type": "@type"} def __init__(self, type=None, local_vars_configuration=None): """Any - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/assertion.py b/openfga_sdk/models/assertion.py index 9938475..731a1bb 100644 --- a/openfga_sdk/models/assertion.py +++ b/openfga_sdk/models/assertion.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class Assertion: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "AssertionTupleKey", "expectation": "bool", "contextual_tuples": "list[TupleKey]", "context": "object", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "expectation": "expectation", "contextual_tuples": "contextual_tuples", diff --git a/openfga_sdk/models/assertion_tuple_key.py b/openfga_sdk/models/assertion_tuple_key.py index fcc6472..5252859 100644 --- a/openfga_sdk/models/assertion_tuple_key.py +++ b/openfga_sdk/models/assertion_tuple_key.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,13 @@ class AssertionTupleKey: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"object": "str", "relation": "str", "user": "str"} + openapi_types: dict[str, str] = {"object": "str", "relation": "str", "user": "str"} - attribute_map = {"object": "object", "relation": "relation", "user": "user"} + attribute_map: dict[str, str] = { + "object": "object", + "relation": "relation", + "user": "user", + } def __init__( self, object=None, relation=None, user=None, local_vars_configuration=None diff --git a/openfga_sdk/models/auth_error_code.py b/openfga_sdk/models/auth_error_code.py index 7a457e8..f2a4dc2 100644 --- a/openfga_sdk/models/auth_error_code.py +++ b/openfga_sdk/models/auth_error_code.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -58,9 +55,9 @@ class AuthErrorCode: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """AuthErrorCode - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/authorization_model.py b/openfga_sdk/models/authorization_model.py index 0701fbd..73b020c 100644 --- a/openfga_sdk/models/authorization_model.py +++ b/openfga_sdk/models/authorization_model.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class AuthorizationModel: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "id": "str", "schema_version": "str", "type_definitions": "list[TypeDefinition]", "conditions": "dict[str, Condition]", } - attribute_map = { + attribute_map: dict[str, str] = { "id": "id", "schema_version": "schema_version", "type_definitions": "type_definitions", diff --git a/openfga_sdk/models/batch_check_item.py b/openfga_sdk/models/batch_check_item.py index 83f8397..b0af174 100644 --- a/openfga_sdk/models/batch_check_item.py +++ b/openfga_sdk/models/batch_check_item.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class BatchCheckItem: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "CheckRequestTupleKey", "contextual_tuples": "ContextualTupleKeys", "context": "object", "correlation_id": "str", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "contextual_tuples": "contextual_tuples", "context": "context", diff --git a/openfga_sdk/models/batch_check_request.py b/openfga_sdk/models/batch_check_request.py index 4357b9c..b375ea8 100644 --- a/openfga_sdk/models/batch_check_request.py +++ b/openfga_sdk/models/batch_check_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class BatchCheckRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "checks": "list[BatchCheckItem]", "authorization_model_id": "str", "consistency": "ConsistencyPreference", } - attribute_map = { + attribute_map: dict[str, str] = { "checks": "checks", "authorization_model_id": "authorization_model_id", "consistency": "consistency", diff --git a/openfga_sdk/models/batch_check_response.py b/openfga_sdk/models/batch_check_response.py index 5c5f38f..8ff5e9a 100644 --- a/openfga_sdk/models/batch_check_response.py +++ b/openfga_sdk/models/batch_check_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class BatchCheckResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"result": "dict[str, BatchCheckSingleResult]"} + openapi_types: dict[str, str] = {"result": "dict[str, BatchCheckSingleResult]"} - attribute_map = {"result": "result"} + attribute_map: dict[str, str] = {"result": "result"} def __init__(self, result=None, local_vars_configuration=None): """BatchCheckResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/batch_check_single_result.py b/openfga_sdk/models/batch_check_single_result.py index f51d791..cbe29b6 100644 --- a/openfga_sdk/models/batch_check_single_result.py +++ b/openfga_sdk/models/batch_check_single_result.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class BatchCheckSingleResult: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"allowed": "bool", "error": "CheckError"} + openapi_types: dict[str, str] = {"allowed": "bool", "error": "CheckError"} - attribute_map = {"allowed": "allowed", "error": "error"} + attribute_map: dict[str, str] = {"allowed": "allowed", "error": "error"} def __init__(self, allowed=None, error=None, local_vars_configuration=None): """BatchCheckSingleResult - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/check_error.py b/openfga_sdk/models/check_error.py index ce687c9..1da3da0 100644 --- a/openfga_sdk/models/check_error.py +++ b/openfga_sdk/models/check_error.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class CheckError: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "input_error": "ErrorCode", "internal_error": "InternalErrorCode", "message": "str", } - attribute_map = { + attribute_map: dict[str, str] = { "input_error": "input_error", "internal_error": "internal_error", "message": "message", diff --git a/openfga_sdk/models/check_request.py b/openfga_sdk/models/check_request.py index 3ba2284..056eeb0 100644 --- a/openfga_sdk/models/check_request.py +++ b/openfga_sdk/models/check_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class CheckRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "CheckRequestTupleKey", "contextual_tuples": "ContextualTupleKeys", "authorization_model_id": "str", @@ -42,7 +39,7 @@ class CheckRequest: "consistency": "ConsistencyPreference", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "contextual_tuples": "contextual_tuples", "authorization_model_id": "authorization_model_id", diff --git a/openfga_sdk/models/check_request_tuple_key.py b/openfga_sdk/models/check_request_tuple_key.py index ec7197c..292f4e2 100644 --- a/openfga_sdk/models/check_request_tuple_key.py +++ b/openfga_sdk/models/check_request_tuple_key.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,13 @@ class CheckRequestTupleKey: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"user": "str", "relation": "str", "object": "str"} + openapi_types: dict[str, str] = {"user": "str", "relation": "str", "object": "str"} - attribute_map = {"user": "user", "relation": "relation", "object": "object"} + attribute_map: dict[str, str] = { + "user": "user", + "relation": "relation", + "object": "object", + } def __init__( self, user=None, relation=None, object=None, local_vars_configuration=None diff --git a/openfga_sdk/models/check_response.py b/openfga_sdk/models/check_response.py index aa51541..f31f3e0 100644 --- a/openfga_sdk/models/check_response.py +++ b/openfga_sdk/models/check_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class CheckResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"allowed": "bool", "resolution": "str"} + openapi_types: dict[str, str] = {"allowed": "bool", "resolution": "str"} - attribute_map = {"allowed": "allowed", "resolution": "resolution"} + attribute_map: dict[str, str] = {"allowed": "allowed", "resolution": "resolution"} def __init__(self, allowed=None, resolution=None, local_vars_configuration=None): """CheckResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/computed.py b/openfga_sdk/models/computed.py index 84c3b11..6b5f6be 100644 --- a/openfga_sdk/models/computed.py +++ b/openfga_sdk/models/computed.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Computed: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"userset": "str"} + openapi_types: dict[str, str] = {"userset": "str"} - attribute_map = {"userset": "userset"} + attribute_map: dict[str, str] = {"userset": "userset"} def __init__(self, userset=None, local_vars_configuration=None): """Computed - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/condition.py b/openfga_sdk/models/condition.py index 228f31d..c65a6d5 100644 --- a/openfga_sdk/models/condition.py +++ b/openfga_sdk/models/condition.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class Condition: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "name": "str", "expression": "str", "parameters": "dict[str, ConditionParamTypeRef]", "metadata": "ConditionMetadata", } - attribute_map = { + attribute_map: dict[str, str] = { "name": "name", "expression": "expression", "parameters": "parameters", diff --git a/openfga_sdk/models/condition_metadata.py b/openfga_sdk/models/condition_metadata.py index 8f5c9a4..389c02d 100644 --- a/openfga_sdk/models/condition_metadata.py +++ b/openfga_sdk/models/condition_metadata.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ConditionMetadata: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"module": "str", "source_info": "SourceInfo"} + openapi_types: dict[str, str] = {"module": "str", "source_info": "SourceInfo"} - attribute_map = {"module": "module", "source_info": "source_info"} + attribute_map: dict[str, str] = {"module": "module", "source_info": "source_info"} def __init__(self, module=None, source_info=None, local_vars_configuration=None): """ConditionMetadata - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/condition_param_type_ref.py b/openfga_sdk/models/condition_param_type_ref.py index 76d9efa..4aa37a9 100644 --- a/openfga_sdk/models/condition_param_type_ref.py +++ b/openfga_sdk/models/condition_param_type_ref.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,12 +30,15 @@ class ConditionParamTypeRef: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "type_name": "TypeName", "generic_types": "list[ConditionParamTypeRef]", } - attribute_map = {"type_name": "type_name", "generic_types": "generic_types"} + attribute_map: dict[str, str] = { + "type_name": "type_name", + "generic_types": "generic_types", + } def __init__( self, type_name=None, generic_types=None, local_vars_configuration=None diff --git a/openfga_sdk/models/consistency_preference.py b/openfga_sdk/models/consistency_preference.py index e6593e3..9cc65f0 100644 --- a/openfga_sdk/models/consistency_preference.py +++ b/openfga_sdk/models/consistency_preference.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -42,9 +39,9 @@ class ConsistencyPreference: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """ConsistencyPreference - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/contextual_tuple_keys.py b/openfga_sdk/models/contextual_tuple_keys.py index 9656778..19d4486 100644 --- a/openfga_sdk/models/contextual_tuple_keys.py +++ b/openfga_sdk/models/contextual_tuple_keys.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ContextualTupleKeys: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tuple_keys": "list[TupleKey]"} + openapi_types: dict[str, str] = {"tuple_keys": "list[TupleKey]"} - attribute_map = {"tuple_keys": "tuple_keys"} + attribute_map: dict[str, str] = {"tuple_keys": "tuple_keys"} def __init__(self, tuple_keys=None, local_vars_configuration=None): """ContextualTupleKeys - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/create_store_request.py b/openfga_sdk/models/create_store_request.py index 6d989cb..8e899d4 100644 --- a/openfga_sdk/models/create_store_request.py +++ b/openfga_sdk/models/create_store_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class CreateStoreRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"name": "str"} + openapi_types: dict[str, str] = {"name": "str"} - attribute_map = {"name": "name"} + attribute_map: dict[str, str] = {"name": "name"} def __init__(self, name=None, local_vars_configuration=None): """CreateStoreRequest - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/create_store_response.py b/openfga_sdk/models/create_store_response.py index 2c27808..4264ed4 100644 --- a/openfga_sdk/models/create_store_response.py +++ b/openfga_sdk/models/create_store_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class CreateStoreResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "id": "str", "name": "str", "created_at": "datetime", "updated_at": "datetime", } - attribute_map = { + attribute_map: dict[str, str] = { "id": "id", "name": "name", "created_at": "created_at", diff --git a/openfga_sdk/models/difference.py b/openfga_sdk/models/difference.py index f343ea9..f28512f 100644 --- a/openfga_sdk/models/difference.py +++ b/openfga_sdk/models/difference.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Difference: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"base": "Userset", "subtract": "Userset"} + openapi_types: dict[str, str] = {"base": "Userset", "subtract": "Userset"} - attribute_map = {"base": "base", "subtract": "subtract"} + attribute_map: dict[str, str] = {"base": "base", "subtract": "subtract"} def __init__(self, base=None, subtract=None, local_vars_configuration=None): """Difference - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/error_code.py b/openfga_sdk/models/error_code.py index 695765a..ae2ac28 100644 --- a/openfga_sdk/models/error_code.py +++ b/openfga_sdk/models/error_code.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -152,9 +149,9 @@ class ErrorCode: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """ErrorCode - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/expand_request.py b/openfga_sdk/models/expand_request.py index 6c59682..f804a4c 100644 --- a/openfga_sdk/models/expand_request.py +++ b/openfga_sdk/models/expand_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class ExpandRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "ExpandRequestTupleKey", "authorization_model_id": "str", "consistency": "ConsistencyPreference", "contextual_tuples": "ContextualTupleKeys", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "authorization_model_id": "authorization_model_id", "consistency": "consistency", diff --git a/openfga_sdk/models/expand_request_tuple_key.py b/openfga_sdk/models/expand_request_tuple_key.py index cdc544f..8046116 100644 --- a/openfga_sdk/models/expand_request_tuple_key.py +++ b/openfga_sdk/models/expand_request_tuple_key.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ExpandRequestTupleKey: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"relation": "str", "object": "str"} + openapi_types: dict[str, str] = {"relation": "str", "object": "str"} - attribute_map = {"relation": "relation", "object": "object"} + attribute_map: dict[str, str] = {"relation": "relation", "object": "object"} def __init__(self, relation=None, object=None, local_vars_configuration=None): """ExpandRequestTupleKey - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/expand_response.py b/openfga_sdk/models/expand_response.py index 2fdb336..a5a5c20 100644 --- a/openfga_sdk/models/expand_response.py +++ b/openfga_sdk/models/expand_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ExpandResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tree": "UsersetTree"} + openapi_types: dict[str, str] = {"tree": "UsersetTree"} - attribute_map = {"tree": "tree"} + attribute_map: dict[str, str] = {"tree": "tree"} def __init__(self, tree=None, local_vars_configuration=None): """ExpandResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/fga_object.py b/openfga_sdk/models/fga_object.py index a6254e5..b9788bf 100644 --- a/openfga_sdk/models/fga_object.py +++ b/openfga_sdk/models/fga_object.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class FgaObject: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"type": "str", "id": "str"} + openapi_types: dict[str, str] = {"type": "str", "id": "str"} - attribute_map = {"type": "type", "id": "id"} + attribute_map: dict[str, str] = {"type": "type", "id": "id"} def __init__(self, type=None, id=None, local_vars_configuration=None): """FgaObject - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/forbidden_response.py b/openfga_sdk/models/forbidden_response.py index 5f1f350..7d0df99 100644 --- a/openfga_sdk/models/forbidden_response.py +++ b/openfga_sdk/models/forbidden_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ForbiddenResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "AuthErrorCode", "message": "str"} + openapi_types: dict[str, str] = {"code": "AuthErrorCode", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """ForbiddenResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/get_store_response.py b/openfga_sdk/models/get_store_response.py index ae2997f..98b4f86 100644 --- a/openfga_sdk/models/get_store_response.py +++ b/openfga_sdk/models/get_store_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class GetStoreResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "id": "str", "name": "str", "created_at": "datetime", @@ -41,7 +38,7 @@ class GetStoreResponse: "deleted_at": "datetime", } - attribute_map = { + attribute_map: dict[str, str] = { "id": "id", "name": "name", "created_at": "created_at", diff --git a/openfga_sdk/models/internal_error_code.py b/openfga_sdk/models/internal_error_code.py index 1e4b3b4..ef4c7a4 100644 --- a/openfga_sdk/models/internal_error_code.py +++ b/openfga_sdk/models/internal_error_code.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -60,9 +57,9 @@ class InternalErrorCode: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """InternalErrorCode - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/internal_error_message_response.py b/openfga_sdk/models/internal_error_message_response.py index 0c30fd5..fa36a5d 100644 --- a/openfga_sdk/models/internal_error_message_response.py +++ b/openfga_sdk/models/internal_error_message_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class InternalErrorMessageResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "InternalErrorCode", "message": "str"} + openapi_types: dict[str, str] = {"code": "InternalErrorCode", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """InternalErrorMessageResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/leaf.py b/openfga_sdk/models/leaf.py index 60ee85f..cbe66cd 100644 --- a/openfga_sdk/models/leaf.py +++ b/openfga_sdk/models/leaf.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class Leaf: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "users": "Users", "computed": "Computed", "tuple_to_userset": "UsersetTreeTupleToUserset", } - attribute_map = { + attribute_map: dict[str, str] = { "users": "users", "computed": "computed", "tuple_to_userset": "tupleToUserset", diff --git a/openfga_sdk/models/list_objects_request.py b/openfga_sdk/models/list_objects_request.py index 16e1a71..fea346b 100644 --- a/openfga_sdk/models/list_objects_request.py +++ b/openfga_sdk/models/list_objects_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class ListObjectsRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "authorization_model_id": "str", "type": "str", "relation": "str", @@ -43,7 +40,7 @@ class ListObjectsRequest: "consistency": "ConsistencyPreference", } - attribute_map = { + attribute_map: dict[str, str] = { "authorization_model_id": "authorization_model_id", "type": "type", "relation": "relation", diff --git a/openfga_sdk/models/list_objects_response.py b/openfga_sdk/models/list_objects_response.py index 0df985e..6ca881c 100644 --- a/openfga_sdk/models/list_objects_response.py +++ b/openfga_sdk/models/list_objects_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ListObjectsResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"objects": "list[str]"} + openapi_types: dict[str, str] = {"objects": "list[str]"} - attribute_map = {"objects": "objects"} + attribute_map: dict[str, str] = {"objects": "objects"} def __init__(self, objects=None, local_vars_configuration=None): """ListObjectsResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/list_stores_response.py b/openfga_sdk/models/list_stores_response.py index 9e66f04..007dbe4 100644 --- a/openfga_sdk/models/list_stores_response.py +++ b/openfga_sdk/models/list_stores_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,15 @@ class ListStoresResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"stores": "list[Store]", "continuation_token": "str"} - - attribute_map = {"stores": "stores", "continuation_token": "continuation_token"} + openapi_types: dict[str, str] = { + "stores": "list[Store]", + "continuation_token": "str", + } + + attribute_map: dict[str, str] = { + "stores": "stores", + "continuation_token": "continuation_token", + } def __init__( self, stores=None, continuation_token=None, local_vars_configuration=None diff --git a/openfga_sdk/models/list_users_request.py b/openfga_sdk/models/list_users_request.py index 238a1e6..e0b5520 100644 --- a/openfga_sdk/models/list_users_request.py +++ b/openfga_sdk/models/list_users_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class ListUsersRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "authorization_model_id": "str", "object": "FgaObject", "relation": "str", @@ -43,7 +40,7 @@ class ListUsersRequest: "consistency": "ConsistencyPreference", } - attribute_map = { + attribute_map: dict[str, str] = { "authorization_model_id": "authorization_model_id", "object": "object", "relation": "relation", diff --git a/openfga_sdk/models/list_users_response.py b/openfga_sdk/models/list_users_response.py index c8a2ed3..1aa7a84 100644 --- a/openfga_sdk/models/list_users_response.py +++ b/openfga_sdk/models/list_users_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ListUsersResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"users": "list[User]"} + openapi_types: dict[str, str] = {"users": "list[User]"} - attribute_map = {"users": "users"} + attribute_map: dict[str, str] = {"users": "users"} def __init__(self, users=None, local_vars_configuration=None): """ListUsersResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/metadata.py b/openfga_sdk/models/metadata.py index bcbcd87..bcb706a 100644 --- a/openfga_sdk/models/metadata.py +++ b/openfga_sdk/models/metadata.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class Metadata: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "relations": "dict[str, RelationMetadata]", "module": "str", "source_info": "SourceInfo", } - attribute_map = { + attribute_map: dict[str, str] = { "relations": "relations", "module": "module", "source_info": "source_info", diff --git a/openfga_sdk/models/node.py b/openfga_sdk/models/node.py index 609918a..9d1a0ab 100644 --- a/openfga_sdk/models/node.py +++ b/openfga_sdk/models/node.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class Node: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "name": "str", "leaf": "Leaf", "difference": "UsersetTreeDifference", @@ -41,7 +38,7 @@ class Node: "intersection": "Nodes", } - attribute_map = { + attribute_map: dict[str, str] = { "name": "name", "leaf": "leaf", "difference": "difference", diff --git a/openfga_sdk/models/nodes.py b/openfga_sdk/models/nodes.py index 3c5955a..27070ac 100644 --- a/openfga_sdk/models/nodes.py +++ b/openfga_sdk/models/nodes.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Nodes: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"nodes": "list[Node]"} + openapi_types: dict[str, str] = {"nodes": "list[Node]"} - attribute_map = {"nodes": "nodes"} + attribute_map: dict[str, str] = {"nodes": "nodes"} def __init__(self, nodes=None, local_vars_configuration=None): """Nodes - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/not_found_error_code.py b/openfga_sdk/models/not_found_error_code.py index 9462823..7f06423 100644 --- a/openfga_sdk/models/not_found_error_code.py +++ b/openfga_sdk/models/not_found_error_code.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -48,9 +45,9 @@ class NotFoundErrorCode: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """NotFoundErrorCode - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/null_value.py b/openfga_sdk/models/null_value.py index 2abae30..8899c2d 100644 --- a/openfga_sdk/models/null_value.py +++ b/openfga_sdk/models/null_value.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -40,9 +37,9 @@ class NullValue: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """NullValue - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/object_relation.py b/openfga_sdk/models/object_relation.py index 069d924..b7f9b24 100644 --- a/openfga_sdk/models/object_relation.py +++ b/openfga_sdk/models/object_relation.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ObjectRelation: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"object": "str", "relation": "str"} + openapi_types: dict[str, str] = {"object": "str", "relation": "str"} - attribute_map = {"object": "object", "relation": "relation"} + attribute_map: dict[str, str] = {"object": "object", "relation": "relation"} def __init__(self, object=None, relation=None, local_vars_configuration=None): """ObjectRelation - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/path_unknown_error_message_response.py b/openfga_sdk/models/path_unknown_error_message_response.py index 9f81aa4..384cfca 100644 --- a/openfga_sdk/models/path_unknown_error_message_response.py +++ b/openfga_sdk/models/path_unknown_error_message_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class PathUnknownErrorMessageResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "NotFoundErrorCode", "message": "str"} + openapi_types: dict[str, str] = {"code": "NotFoundErrorCode", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """PathUnknownErrorMessageResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/read_assertions_response.py b/openfga_sdk/models/read_assertions_response.py index 7543ffd..f7daf4c 100644 --- a/openfga_sdk/models/read_assertions_response.py +++ b/openfga_sdk/models/read_assertions_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,12 @@ class ReadAssertionsResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"authorization_model_id": "str", "assertions": "list[Assertion]"} + openapi_types: dict[str, str] = { + "authorization_model_id": "str", + "assertions": "list[Assertion]", + } - attribute_map = { + attribute_map: dict[str, str] = { "authorization_model_id": "authorization_model_id", "assertions": "assertions", } diff --git a/openfga_sdk/models/read_authorization_model_response.py b/openfga_sdk/models/read_authorization_model_response.py index 0e6960e..f713ee9 100644 --- a/openfga_sdk/models/read_authorization_model_response.py +++ b/openfga_sdk/models/read_authorization_model_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ReadAuthorizationModelResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"authorization_model": "AuthorizationModel"} + openapi_types: dict[str, str] = {"authorization_model": "AuthorizationModel"} - attribute_map = {"authorization_model": "authorization_model"} + attribute_map: dict[str, str] = {"authorization_model": "authorization_model"} def __init__(self, authorization_model=None, local_vars_configuration=None): """ReadAuthorizationModelResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/read_authorization_models_response.py b/openfga_sdk/models/read_authorization_models_response.py index 42ebdd8..5696c1c 100644 --- a/openfga_sdk/models/read_authorization_models_response.py +++ b/openfga_sdk/models/read_authorization_models_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,12 +30,12 @@ class ReadAuthorizationModelsResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "authorization_models": "list[AuthorizationModel]", "continuation_token": "str", } - attribute_map = { + attribute_map: dict[str, str] = { "authorization_models": "authorization_models", "continuation_token": "continuation_token", } diff --git a/openfga_sdk/models/read_changes_response.py b/openfga_sdk/models/read_changes_response.py index 3ecc873..6b56409 100644 --- a/openfga_sdk/models/read_changes_response.py +++ b/openfga_sdk/models/read_changes_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,15 @@ class ReadChangesResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"changes": "list[TupleChange]", "continuation_token": "str"} - - attribute_map = {"changes": "changes", "continuation_token": "continuation_token"} + openapi_types: dict[str, str] = { + "changes": "list[TupleChange]", + "continuation_token": "str", + } + + attribute_map: dict[str, str] = { + "changes": "changes", + "continuation_token": "continuation_token", + } def __init__( self, changes=None, continuation_token=None, local_vars_configuration=None diff --git a/openfga_sdk/models/read_request.py b/openfga_sdk/models/read_request.py index 5b043c3..25da56e 100644 --- a/openfga_sdk/models/read_request.py +++ b/openfga_sdk/models/read_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class ReadRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "ReadRequestTupleKey", "page_size": "int", "continuation_token": "str", "consistency": "ConsistencyPreference", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "page_size": "page_size", "continuation_token": "continuation_token", diff --git a/openfga_sdk/models/read_request_tuple_key.py b/openfga_sdk/models/read_request_tuple_key.py index bed602c..560aff4 100644 --- a/openfga_sdk/models/read_request_tuple_key.py +++ b/openfga_sdk/models/read_request_tuple_key.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,13 @@ class ReadRequestTupleKey: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"user": "str", "relation": "str", "object": "str"} + openapi_types: dict[str, str] = {"user": "str", "relation": "str", "object": "str"} - attribute_map = {"user": "user", "relation": "relation", "object": "object"} + attribute_map: dict[str, str] = { + "user": "user", + "relation": "relation", + "object": "object", + } def __init__( self, user=None, relation=None, object=None, local_vars_configuration=None diff --git a/openfga_sdk/models/read_response.py b/openfga_sdk/models/read_response.py index c50f3aa..1569ffc 100644 --- a/openfga_sdk/models/read_response.py +++ b/openfga_sdk/models/read_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,15 @@ class ReadResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tuples": "list[Tuple]", "continuation_token": "str"} - - attribute_map = {"tuples": "tuples", "continuation_token": "continuation_token"} + openapi_types: dict[str, str] = { + "tuples": "list[Tuple]", + "continuation_token": "str", + } + + attribute_map: dict[str, str] = { + "tuples": "tuples", + "continuation_token": "continuation_token", + } def __init__( self, tuples=None, continuation_token=None, local_vars_configuration=None diff --git a/openfga_sdk/models/relation_metadata.py b/openfga_sdk/models/relation_metadata.py index c81ac9b..dbbdbaf 100644 --- a/openfga_sdk/models/relation_metadata.py +++ b/openfga_sdk/models/relation_metadata.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class RelationMetadata: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "directly_related_user_types": "list[RelationReference]", "module": "str", "source_info": "SourceInfo", } - attribute_map = { + attribute_map: dict[str, str] = { "directly_related_user_types": "directly_related_user_types", "module": "module", "source_info": "source_info", diff --git a/openfga_sdk/models/relation_reference.py b/openfga_sdk/models/relation_reference.py index dd35dd4..ff8bb02 100644 --- a/openfga_sdk/models/relation_reference.py +++ b/openfga_sdk/models/relation_reference.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class RelationReference: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "type": "str", "relation": "str", "wildcard": "object", "condition": "str", } - attribute_map = { + attribute_map: dict[str, str] = { "type": "type", "relation": "relation", "wildcard": "wildcard", diff --git a/openfga_sdk/models/relationship_condition.py b/openfga_sdk/models/relationship_condition.py index d282e0b..73cc2cf 100644 --- a/openfga_sdk/models/relationship_condition.py +++ b/openfga_sdk/models/relationship_condition.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class RelationshipCondition: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"name": "str", "context": "object"} + openapi_types: dict[str, str] = {"name": "str", "context": "object"} - attribute_map = {"name": "name", "context": "context"} + attribute_map: dict[str, str] = {"name": "name", "context": "context"} def __init__(self, name=None, context=None, local_vars_configuration=None): """RelationshipCondition - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/source_info.py b/openfga_sdk/models/source_info.py index 214a86e..d4ca70e 100644 --- a/openfga_sdk/models/source_info.py +++ b/openfga_sdk/models/source_info.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class SourceInfo: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"file": "str"} + openapi_types: dict[str, str] = {"file": "str"} - attribute_map = {"file": "file"} + attribute_map: dict[str, str] = {"file": "file"} def __init__(self, file=None, local_vars_configuration=None): """SourceInfo - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/status.py b/openfga_sdk/models/status.py index e088415..2bf2424 100644 --- a/openfga_sdk/models/status.py +++ b/openfga_sdk/models/status.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,17 @@ class Status: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "int", "message": "str", "details": "list[Any]"} - - attribute_map = {"code": "code", "message": "message", "details": "details"} + openapi_types: dict[str, str] = { + "code": "int", + "message": "str", + "details": "list[Any]", + } + + attribute_map: dict[str, str] = { + "code": "code", + "message": "message", + "details": "details", + } def __init__( self, code=None, message=None, details=None, local_vars_configuration=None diff --git a/openfga_sdk/models/store.py b/openfga_sdk/models/store.py index 43d25e8..c95c99e 100644 --- a/openfga_sdk/models/store.py +++ b/openfga_sdk/models/store.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class Store: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "id": "str", "name": "str", "created_at": "datetime", @@ -41,7 +38,7 @@ class Store: "deleted_at": "datetime", } - attribute_map = { + attribute_map: dict[str, str] = { "id": "id", "name": "name", "created_at": "created_at", diff --git a/openfga_sdk/models/stream_result_of_streamed_list_objects_response.py b/openfga_sdk/models/stream_result_of_streamed_list_objects_response.py index d72f2dc..308c84b 100644 --- a/openfga_sdk/models/stream_result_of_streamed_list_objects_response.py +++ b/openfga_sdk/models/stream_result_of_streamed_list_objects_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,12 @@ class StreamResultOfStreamedListObjectsResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"result": "StreamedListObjectsResponse", "error": "Status"} + openapi_types: dict[str, str] = { + "result": "StreamedListObjectsResponse", + "error": "Status", + } - attribute_map = {"result": "result", "error": "error"} + attribute_map: dict[str, str] = {"result": "result", "error": "error"} def __init__(self, result=None, error=None, local_vars_configuration=None): """StreamResultOfStreamedListObjectsResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/streamed_list_objects_response.py b/openfga_sdk/models/streamed_list_objects_response.py index 087dcfb..0ea3a8c 100644 --- a/openfga_sdk/models/streamed_list_objects_response.py +++ b/openfga_sdk/models/streamed_list_objects_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class StreamedListObjectsResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"object": "str"} + openapi_types: dict[str, str] = {"object": "str"} - attribute_map = {"object": "object"} + attribute_map: dict[str, str] = {"object": "object"} def __init__(self, object=None, local_vars_configuration=None): """StreamedListObjectsResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/tuple.py b/openfga_sdk/models/tuple.py index afe5340..167296c 100644 --- a/openfga_sdk/models/tuple.py +++ b/openfga_sdk/models/tuple.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Tuple: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"key": "TupleKey", "timestamp": "datetime"} + openapi_types: dict[str, str] = {"key": "TupleKey", "timestamp": "datetime"} - attribute_map = {"key": "key", "timestamp": "timestamp"} + attribute_map: dict[str, str] = {"key": "key", "timestamp": "timestamp"} def __init__(self, key=None, timestamp=None, local_vars_configuration=None): """Tuple - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/tuple_change.py b/openfga_sdk/models/tuple_change.py index c4710c9..7286b0d 100644 --- a/openfga_sdk/models/tuple_change.py +++ b/openfga_sdk/models/tuple_change.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class TupleChange: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "tuple_key": "TupleKey", "operation": "TupleOperation", "timestamp": "datetime", } - attribute_map = { + attribute_map: dict[str, str] = { "tuple_key": "tuple_key", "operation": "operation", "timestamp": "timestamp", diff --git a/openfga_sdk/models/tuple_key.py b/openfga_sdk/models/tuple_key.py index d9bdf23..190f302 100644 --- a/openfga_sdk/models/tuple_key.py +++ b/openfga_sdk/models/tuple_key.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,14 +30,14 @@ class TupleKey: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "user": "str", "relation": "str", "object": "str", "condition": "RelationshipCondition", } - attribute_map = { + attribute_map: dict[str, str] = { "user": "user", "relation": "relation", "object": "object", diff --git a/openfga_sdk/models/tuple_key_without_condition.py b/openfga_sdk/models/tuple_key_without_condition.py index 79ff24b..32723d8 100644 --- a/openfga_sdk/models/tuple_key_without_condition.py +++ b/openfga_sdk/models/tuple_key_without_condition.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,13 @@ class TupleKeyWithoutCondition: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"user": "str", "relation": "str", "object": "str"} + openapi_types: dict[str, str] = {"user": "str", "relation": "str", "object": "str"} - attribute_map = {"user": "user", "relation": "relation", "object": "object"} + attribute_map: dict[str, str] = { + "user": "user", + "relation": "relation", + "object": "object", + } def __init__( self, user=None, relation=None, object=None, local_vars_configuration=None diff --git a/openfga_sdk/models/tuple_operation.py b/openfga_sdk/models/tuple_operation.py index 1b2e6d4..3a27eaf 100644 --- a/openfga_sdk/models/tuple_operation.py +++ b/openfga_sdk/models/tuple_operation.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -41,9 +38,9 @@ class TupleOperation: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """TupleOperation - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/tuple_to_userset.py b/openfga_sdk/models/tuple_to_userset.py index f9d401f..972a657 100644 --- a/openfga_sdk/models/tuple_to_userset.py +++ b/openfga_sdk/models/tuple_to_userset.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,15 @@ class TupleToUserset: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tupleset": "ObjectRelation", "computed_userset": "ObjectRelation"} - - attribute_map = {"tupleset": "tupleset", "computed_userset": "computedUserset"} + openapi_types: dict[str, str] = { + "tupleset": "ObjectRelation", + "computed_userset": "ObjectRelation", + } + + attribute_map: dict[str, str] = { + "tupleset": "tupleset", + "computed_userset": "computedUserset", + } def __init__( self, tupleset=None, computed_userset=None, local_vars_configuration=None diff --git a/openfga_sdk/models/type_definition.py b/openfga_sdk/models/type_definition.py index feb4434..559f611 100644 --- a/openfga_sdk/models/type_definition.py +++ b/openfga_sdk/models/type_definition.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,17 @@ class TypeDefinition: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "type": "str", "relations": "dict[str, Userset]", "metadata": "Metadata", } - attribute_map = {"type": "type", "relations": "relations", "metadata": "metadata"} + attribute_map: dict[str, str] = { + "type": "type", + "relations": "relations", + "metadata": "metadata", + } def __init__( self, type=None, relations=None, metadata=None, local_vars_configuration=None diff --git a/openfga_sdk/models/type_name.py b/openfga_sdk/models/type_name.py index 006c0d2..17e117b 100644 --- a/openfga_sdk/models/type_name.py +++ b/openfga_sdk/models/type_name.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -64,9 +61,9 @@ class TypeName: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """TypeName - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/typed_wildcard.py b/openfga_sdk/models/typed_wildcard.py index 0494ea9..60e7c8f 100644 --- a/openfga_sdk/models/typed_wildcard.py +++ b/openfga_sdk/models/typed_wildcard.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class TypedWildcard: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"type": "str"} + openapi_types: dict[str, str] = {"type": "str"} - attribute_map = {"type": "type"} + attribute_map: dict[str, str] = {"type": "type"} def __init__(self, type=None, local_vars_configuration=None): """TypedWildcard - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/unauthenticated_response.py b/openfga_sdk/models/unauthenticated_response.py index ab88511..9c1c756 100644 --- a/openfga_sdk/models/unauthenticated_response.py +++ b/openfga_sdk/models/unauthenticated_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UnauthenticatedResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "ErrorCode", "message": "str"} + openapi_types: dict[str, str] = {"code": "ErrorCode", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """UnauthenticatedResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/unprocessable_content_error_code.py b/openfga_sdk/models/unprocessable_content_error_code.py index 012bd86..f84707c 100644 --- a/openfga_sdk/models/unprocessable_content_error_code.py +++ b/openfga_sdk/models/unprocessable_content_error_code.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -41,9 +38,9 @@ class UnprocessableContentErrorCode: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {} + openapi_types: dict[str, str] = {} - attribute_map = {} + attribute_map: dict[str, str] = {} def __init__(self, local_vars_configuration=None): """UnprocessableContentErrorCode - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/unprocessable_content_message_response.py b/openfga_sdk/models/unprocessable_content_message_response.py index abecf0f..cbb85e7 100644 --- a/openfga_sdk/models/unprocessable_content_message_response.py +++ b/openfga_sdk/models/unprocessable_content_message_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,12 @@ class UnprocessableContentMessageResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "UnprocessableContentErrorCode", "message": "str"} + openapi_types: dict[str, str] = { + "code": "UnprocessableContentErrorCode", + "message": "str", + } - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """UnprocessableContentMessageResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/user.py b/openfga_sdk/models/user.py index e0ffdd5..5466637 100644 --- a/openfga_sdk/models/user.py +++ b/openfga_sdk/models/user.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,17 @@ class User: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "object": "FgaObject", "userset": "UsersetUser", "wildcard": "TypedWildcard", } - attribute_map = {"object": "object", "userset": "userset", "wildcard": "wildcard"} + attribute_map: dict[str, str] = { + "object": "object", + "userset": "userset", + "wildcard": "wildcard", + } def __init__( self, object=None, userset=None, wildcard=None, local_vars_configuration=None diff --git a/openfga_sdk/models/user_type_filter.py b/openfga_sdk/models/user_type_filter.py index 75215cf..59acd13 100644 --- a/openfga_sdk/models/user_type_filter.py +++ b/openfga_sdk/models/user_type_filter.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UserTypeFilter: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"type": "str", "relation": "str"} + openapi_types: dict[str, str] = {"type": "str", "relation": "str"} - attribute_map = {"type": "type", "relation": "relation"} + attribute_map: dict[str, str] = {"type": "type", "relation": "relation"} def __init__(self, type=None, relation=None, local_vars_configuration=None): """UserTypeFilter - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/users.py b/openfga_sdk/models/users.py index aa887dd..dadf37d 100644 --- a/openfga_sdk/models/users.py +++ b/openfga_sdk/models/users.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Users: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"users": "list[str]"} + openapi_types: dict[str, str] = {"users": "list[str]"} - attribute_map = {"users": "users"} + attribute_map: dict[str, str] = {"users": "users"} def __init__(self, users=None, local_vars_configuration=None): """Users - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/userset.py b/openfga_sdk/models/userset.py index 8ef105c..efa9581 100644 --- a/openfga_sdk/models/userset.py +++ b/openfga_sdk/models/userset.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,7 +30,7 @@ class Userset: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "this": "object", "computed_userset": "ObjectRelation", "tuple_to_userset": "TupleToUserset", @@ -42,7 +39,7 @@ class Userset: "difference": "Difference", } - attribute_map = { + attribute_map: dict[str, str] = { "this": "this", "computed_userset": "computedUserset", "tuple_to_userset": "tupleToUserset", diff --git a/openfga_sdk/models/userset_tree.py b/openfga_sdk/models/userset_tree.py index dbfdee4..f4cfab4 100644 --- a/openfga_sdk/models/userset_tree.py +++ b/openfga_sdk/models/userset_tree.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UsersetTree: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"root": "Node"} + openapi_types: dict[str, str] = {"root": "Node"} - attribute_map = {"root": "root"} + attribute_map: dict[str, str] = {"root": "root"} def __init__(self, root=None, local_vars_configuration=None): """UsersetTree - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/userset_tree_difference.py b/openfga_sdk/models/userset_tree_difference.py index 5681d92..52f8150 100644 --- a/openfga_sdk/models/userset_tree_difference.py +++ b/openfga_sdk/models/userset_tree_difference.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UsersetTreeDifference: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"base": "Node", "subtract": "Node"} + openapi_types: dict[str, str] = {"base": "Node", "subtract": "Node"} - attribute_map = {"base": "base", "subtract": "subtract"} + attribute_map: dict[str, str] = {"base": "base", "subtract": "subtract"} def __init__(self, base=None, subtract=None, local_vars_configuration=None): """UsersetTreeDifference - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/userset_tree_tuple_to_userset.py b/openfga_sdk/models/userset_tree_tuple_to_userset.py index fcb23ae..9261840 100644 --- a/openfga_sdk/models/userset_tree_tuple_to_userset.py +++ b/openfga_sdk/models/userset_tree_tuple_to_userset.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UsersetTreeTupleToUserset: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tupleset": "str", "computed": "list[Computed]"} + openapi_types: dict[str, str] = {"tupleset": "str", "computed": "list[Computed]"} - attribute_map = {"tupleset": "tupleset", "computed": "computed"} + attribute_map: dict[str, str] = {"tupleset": "tupleset", "computed": "computed"} def __init__(self, tupleset=None, computed=None, local_vars_configuration=None): """UsersetTreeTupleToUserset - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/userset_user.py b/openfga_sdk/models/userset_user.py index 72a84ad..e69172c 100644 --- a/openfga_sdk/models/userset_user.py +++ b/openfga_sdk/models/userset_user.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class UsersetUser: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"type": "str", "id": "str", "relation": "str"} + openapi_types: dict[str, str] = {"type": "str", "id": "str", "relation": "str"} - attribute_map = {"type": "type", "id": "id", "relation": "relation"} + attribute_map: dict[str, str] = {"type": "type", "id": "id", "relation": "relation"} def __init__( self, type=None, id=None, relation=None, local_vars_configuration=None diff --git a/openfga_sdk/models/usersets.py b/openfga_sdk/models/usersets.py index d66fc72..d335789 100644 --- a/openfga_sdk/models/usersets.py +++ b/openfga_sdk/models/usersets.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class Usersets: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"child": "list[Userset]"} + openapi_types: dict[str, str] = {"child": "list[Userset]"} - attribute_map = {"child": "child"} + attribute_map: dict[str, str] = {"child": "child"} def __init__(self, child=None, local_vars_configuration=None): """Usersets - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/validation_error_message_response.py b/openfga_sdk/models/validation_error_message_response.py index 5cf82d6..76ac69b 100644 --- a/openfga_sdk/models/validation_error_message_response.py +++ b/openfga_sdk/models/validation_error_message_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class ValidationErrorMessageResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"code": "ErrorCode", "message": "str"} + openapi_types: dict[str, str] = {"code": "ErrorCode", "message": "str"} - attribute_map = {"code": "code", "message": "message"} + attribute_map: dict[str, str] = {"code": "code", "message": "message"} def __init__(self, code=None, message=None, local_vars_configuration=None): """ValidationErrorMessageResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/write_assertions_request.py b/openfga_sdk/models/write_assertions_request.py index 4c97b3d..09c1749 100644 --- a/openfga_sdk/models/write_assertions_request.py +++ b/openfga_sdk/models/write_assertions_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class WriteAssertionsRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"assertions": "list[Assertion]"} + openapi_types: dict[str, str] = {"assertions": "list[Assertion]"} - attribute_map = {"assertions": "assertions"} + attribute_map: dict[str, str] = {"assertions": "assertions"} def __init__(self, assertions=None, local_vars_configuration=None): """WriteAssertionsRequest - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/write_authorization_model_request.py b/openfga_sdk/models/write_authorization_model_request.py index 4424966..a191e95 100644 --- a/openfga_sdk/models/write_authorization_model_request.py +++ b/openfga_sdk/models/write_authorization_model_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class WriteAuthorizationModelRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "type_definitions": "list[TypeDefinition]", "schema_version": "str", "conditions": "dict[str, Condition]", } - attribute_map = { + attribute_map: dict[str, str] = { "type_definitions": "type_definitions", "schema_version": "schema_version", "conditions": "conditions", diff --git a/openfga_sdk/models/write_authorization_model_response.py b/openfga_sdk/models/write_authorization_model_response.py index 87196bf..35ed540 100644 --- a/openfga_sdk/models/write_authorization_model_response.py +++ b/openfga_sdk/models/write_authorization_model_response.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class WriteAuthorizationModelResponse: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"authorization_model_id": "str"} + openapi_types: dict[str, str] = {"authorization_model_id": "str"} - attribute_map = {"authorization_model_id": "authorization_model_id"} + attribute_map: dict[str, str] = {"authorization_model_id": "authorization_model_id"} def __init__(self, authorization_model_id=None, local_vars_configuration=None): """WriteAuthorizationModelResponse - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/write_request.py b/openfga_sdk/models/write_request.py index 48fa290..01564a6 100644 --- a/openfga_sdk/models/write_request.py +++ b/openfga_sdk/models/write_request.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,13 +30,13 @@ class WriteRequest: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { + openapi_types: dict[str, str] = { "writes": "WriteRequestWrites", "deletes": "WriteRequestDeletes", "authorization_model_id": "str", } - attribute_map = { + attribute_map: dict[str, str] = { "writes": "writes", "deletes": "deletes", "authorization_model_id": "authorization_model_id", diff --git a/openfga_sdk/models/write_request_deletes.py b/openfga_sdk/models/write_request_deletes.py index 6b4b961..0a44d0c 100644 --- a/openfga_sdk/models/write_request_deletes.py +++ b/openfga_sdk/models/write_request_deletes.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class WriteRequestDeletes: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tuple_keys": "list[TupleKeyWithoutCondition]"} + openapi_types: dict[str, str] = {"tuple_keys": "list[TupleKeyWithoutCondition]"} - attribute_map = {"tuple_keys": "tuple_keys"} + attribute_map: dict[str, str] = {"tuple_keys": "tuple_keys"} def __init__(self, tuple_keys=None, local_vars_configuration=None): """WriteRequestDeletes - a model defined in OpenAPI""" diff --git a/openfga_sdk/models/write_request_writes.py b/openfga_sdk/models/write_request_writes.py index a2533ce..d06ed1e 100644 --- a/openfga_sdk/models/write_request_writes.py +++ b/openfga_sdk/models/write_request_writes.py @@ -10,10 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -try: - from inspect import getfullargspec -except ImportError: - from inspect import getargspec as getfullargspec +from inspect import getfullargspec import pprint from openfga_sdk.configuration import Configuration @@ -33,9 +30,9 @@ class WriteRequestWrites: attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = {"tuple_keys": "list[TupleKey]"} + openapi_types: dict[str, str] = {"tuple_keys": "list[TupleKey]"} - attribute_map = {"tuple_keys": "tuple_keys"} + attribute_map: dict[str, str] = {"tuple_keys": "tuple_keys"} def __init__(self, tuple_keys=None, local_vars_configuration=None): """WriteRequestWrites - a model defined in OpenAPI""" diff --git a/openfga_sdk/rest.py b/openfga_sdk/rest.py index 809999f..5f60bfd 100644 --- a/openfga_sdk/rest.py +++ b/openfga_sdk/rest.py @@ -16,7 +16,7 @@ import re import ssl import urllib -from typing import Any, List, Optional, Tuple +from typing import Any import aiohttp @@ -36,28 +36,37 @@ class RESTResponse(io.IOBase): """ - Represents an HTTP response object. + Represents an HTTP response object in the asynchronous client. """ - def __init__(self, resp: aiohttp.ClientResponse, data: bytes) -> None: + response: aiohttp.ClientResponse + status: int + reason: str | None + data: bytes + + def __init__( + self, + resp: aiohttp.ClientResponse, + data: bytes, + ) -> None: """ - Initializes a RESTResponse with an aiohttp response and corresponding data. + Initializes a RESTResponse with an aiohttp.ClientResponse and corresponding data. :param resp: The aiohttp.ClientResponse object. :param data: The raw byte data read from the response. """ - self.aiohttp_response = resp + self.response = resp self.status = resp.status self.reason = resp.reason self.data = data - def getheaders(self) -> aiohttp.typedefs.LooseHeaders: + def getheaders(self) -> dict[str, str]: """ Returns the response headers. """ - return self.aiohttp_response.headers + return dict(self.response.headers) - def getheader(self, name: str, default: Optional[str] = None) -> Optional[str]: + def getheader(self, name: str, default: str | None = None) -> str | None: """ Returns a specific header value by name. @@ -65,7 +74,7 @@ def getheader(self, name: str, default: Optional[str] = None) -> Optional[str]: :param default: The default value if header is not found. :return: The header value, or default if not present. """ - return self.aiohttp_response.headers.get(name, default) + return self.response.headers.get(name, default) class RESTClientObject: @@ -74,7 +83,7 @@ class RESTClientObject: """ def __init__( - self, configuration: Any, pools_size: int = 4, maxsize: Optional[int] = None + self, configuration: Any, pools_size: int = 4, maxsize: int | None = None ) -> None: """ Creates a new RESTClientObject. @@ -112,12 +121,12 @@ async def build_request( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[List[Tuple[str, Any]]] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: list[tuple[str, Any]] | None = None, _preload_content: bool = True, - _request_timeout: Optional[float] = None, + _request_timeout: float | None = None, ) -> dict: """ Builds a dictionary of request arguments suitable for aiohttp. @@ -160,7 +169,8 @@ async def build_request( args["proxy_headers"] = self.proxy_headers if query_params: - args["url"] += "?" + urllib.parse.urlencode(query_params) + encoded_qs = urllib.parse.urlencode(query_params) + args["url"] = f"{url}?{encoded_qs}" if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]: if re.search("json", headers["Content-Type"], re.IGNORECASE): @@ -226,7 +236,7 @@ async def handle_response_exception( def _accumulate_json_lines( self, leftover: bytes, data: bytes, buffer: bytearray - ) -> Tuple[bytes, List[Any]]: + ) -> tuple[bytes, list[Any]]: """ Processes a chunk of data and leftover bytes. Splits on newlines, decodes valid JSON, and returns leftover bytes and a list of decoded JSON objects. @@ -236,7 +246,7 @@ def _accumulate_json_lines( :param buffer: The main bytearray buffer for all data. :return: Updated leftover bytes and a list of decoded JSON objects. """ - objects: List[Any] = [] + objects: list[Any] = [] leftover += data lines = leftover.split( b"\n" @@ -255,11 +265,11 @@ async def stream( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[List[Tuple[str, Any]]] = None, - _request_timeout: Optional[float] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: list[tuple[str, Any]] | None = None, + _request_timeout: float | None = None, ): """ Streams JSON objects from a specified endpoint, handling partial chunks @@ -290,7 +300,7 @@ async def stream( # Initialize buffers for data chunks buffer = bytearray() leftover = b"" - response: Optional[aiohttp.ClientResponse] = None + response: aiohttp.ClientResponse | None = None try: # Send request, collect response handler @@ -331,7 +341,7 @@ async def stream( # Decode the complete/buffered data for logging purposes if isinstance(response, aiohttp.ClientResponse): - response.data = buffer.decode("utf-8") + logger.debug("response body: %s", buffer.decode("utf-8")) # Handle any HTTP errors that may have occurred await self.handle_response_exception(response) @@ -346,12 +356,12 @@ async def request( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[List[Tuple[str, Any]]] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: list[tuple[str, Any]] | None = None, _preload_content: bool = True, - _request_timeout: Optional[float] = None, + _request_timeout: float | None = None, ) -> RESTResponse | aiohttp.ClientResponse: """ Executes a request and returns the response object. @@ -380,20 +390,21 @@ async def request( ) # Send request, collect response handler - resp = await self.pool_manager.request(**args) + wrapped_response: RESTResponse | None = None + raw_response: aiohttp.ClientResponse = await self.pool_manager.request(**args) # If we want to preload the response, read it if _preload_content: # Collect response data - data = await resp.read() + data = await raw_response.read() # Transform response JSON data into RESTResponse object - resp = RESTResponse(resp, data) + wrapped_response = RESTResponse(raw_response, data) # Log the response body - logger.debug(f"response body: {resp.data}") + logger.debug("response body: %s", data.decode("utf-8")) # Handle any errors that may have occurred - await self.handle_response_exception(resp) + await self.handle_response_exception(raw_response) - return resp + return wrapped_response or raw_response diff --git a/openfga_sdk/sync/api_client.py b/openfga_sdk/sync/api_client.py index f4e137a..16aca0e 100644 --- a/openfga_sdk/sync/api_client.py +++ b/openfga_sdk/sync/api_client.py @@ -20,7 +20,7 @@ import urllib from multiprocessing.pool import ThreadPool -from dateutil.parser import parse +from dateutil.parser import parse # type: ignore[import-untyped] import openfga_sdk.models from openfga_sdk.sync import rest, oauth2 @@ -38,12 +38,13 @@ DEFAULT_USER_AGENT = "openfga-sdk python/0.9.1" -def random_time(loop_count, min_wait_in_ms): +def random_time(loop_count, min_wait_in_ms) -> float: """ Helper function to return the time (in s) to wait before retry """ minimum = math.ceil(2**loop_count * min_wait_in_ms) maximum = math.ceil(2 ** (loop_count + 1) * min_wait_in_ms) + return random.randrange(minimum, maximum) / 1000 @@ -120,11 +121,12 @@ def close(self): self._pool.close() self._pool.join() self._pool = None - if hasattr(atexit, "unregister"): + + if hasattr(atexit, "unregister") and callable(atexit.unregister): atexit.unregister(self.close) @property - def pool(self): + def pool(self) -> ThreadPool: """Create thread pool on first request avoids instantiating unused threadpool for blocking clients. """ @@ -164,7 +166,8 @@ def __call_api( _request_auth=None, _retry_params=None, _oauth2_client=None, - _telemetry_attributes: dict[TelemetryAttribute, str | int] = None, + _telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] + | None = None, _streaming: bool = False, ): self.configuration.is_valid() @@ -509,7 +512,8 @@ def call_api( _request_auth=None, _retry_params=None, _oauth2_client=None, - _telemetry_attributes: dict[TelemetryAttribute, str | int] = None, + _telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] + | None = None, _streaming: bool = False, ): """Makes the HTTP request (synchronous) and returns deserialized data. diff --git a/openfga_sdk/sync/client/client.py b/openfga_sdk/sync/client/client.py index 498f04f..2eeae4e 100644 --- a/openfga_sdk/sync/client/client.py +++ b/openfga_sdk/sync/client/client.py @@ -89,22 +89,31 @@ def _chuck_array(array, max_size): ] -def set_heading_if_not_set(options: dict[str, int | str], name: str, value: str): +def set_heading_if_not_set( + options: dict[str, int | str | dict[str, int | str]] | None, + name: str, + value: str, +) -> dict[str, int | str | dict[str, int | str]]: """ Set heading to the value if it is not set """ - if options is None: - options = {} - headers = options.get("headers") - if headers is None: - headers = {} - if headers.get(name) is None: - headers[name] = value - options["headers"] = headers - return options - - -def options_to_kwargs(options: dict[str, int | str] = None): + _options: dict[str, int | str | dict[str, int | str]] = ( + options if options is not None else {} + ) + + if type(_options.get("headers")) is not dict: + _options["headers"] = {} + + if type(_options["headers"]) is dict: + if type(_options["headers"].get(name)) not in [int, str]: + _options["headers"][name] = value + + return _options + + +def options_to_kwargs( + options: dict[str, int | str | dict[str, int | str]] | None = None, +) -> dict[str, int | str | dict[str, int | str]]: """ Return kwargs with continuation_token and page_size """ @@ -121,7 +130,9 @@ def options_to_kwargs(options: dict[str, int | str] = None): return kwargs -def options_to_transaction_info(options: dict[str, int | str] = None): +def options_to_transaction_info( + options: dict[str, int | str | dict[str, int | str]] | None = None, +): """ Return the transaction info """ @@ -142,7 +153,7 @@ class OpenFgaClient: OpenFgaClient is the entry point for invoking calls against the OpenFGA API. """ - def __init__(self, configuration: ClientConfiguration): + def __init__(self, configuration: ClientConfiguration) -> None: self._client_configuration = configuration self._api_client = ApiClient(configuration) self._api = OpenFgaApi(self._api_client) @@ -150,13 +161,16 @@ def __init__(self, configuration: ClientConfiguration): def __enter__(self): return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__(self, exc_type, exc_value, traceback) -> None: self.close() - def close(self): + def close(self) -> None: self._api.close() - def _get_authorization_model_id(self, options: object) -> str | None: + def _get_authorization_model_id( + self, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ) -> str | None: """ Return the authorization model ID if specified in the options. Otherwise, return the authorization model ID stored in the client's configuration @@ -173,13 +187,21 @@ def _get_authorization_model_id(self, options: object) -> str | None: ) return authorization_model_id - def _get_consistency(self, options: object) -> str | None: + def _get_consistency( + self, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ) -> str | None: """ Returns the consistency requested if specified in the options. Otherwise, returns None. """ - if options is not None and "consistency" in options: - return options["consistency"] + consistency: int | str | dict[str, int | str] | None = ( + options.get("consistency", None) if options is not None else None + ) + + if type(consistency) is str: + return consistency + return None def set_store_id(self, value): @@ -210,7 +232,9 @@ def get_authorization_model_id(self): # Stores ################# - def list_stores(self, options: dict[str, int | str] = None): + def list_stores( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ List the stores in the system :param page_size(options) - Number of items returned per request @@ -228,7 +252,9 @@ def list_stores(self, options: dict[str, int | str] = None): return api_response def create_store( - self, body: CreateStoreRequest, options: dict[str, int | str] = None + self, + body: CreateStoreRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Create the stores in the system @@ -241,7 +267,9 @@ def create_store( api_response = self._api.create_store(body, **kwargs) return api_response - def get_store(self, options: dict[str, int | str] = None): + def get_store( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Get the store info in the system. Store id is from the configuration. :param header(options) - Custom headers to send alongside the request @@ -255,7 +283,9 @@ def get_store(self, options: dict[str, int | str] = None): ) return api_response - def delete_store(self, options: dict[str, int | str] = None): + def delete_store( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Delete the store from the system. Store id is from the configuration. :param header(options) - Custom headers to send alongside the request @@ -273,7 +303,9 @@ def delete_store(self, options: dict[str, int | str] = None): # Authorization Models ####################### - def read_authorization_models(self, options: dict[str, int | str] = None): + def read_authorization_models( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Return all the authorization models for a particular store. :param header(options) - Custom headers to send alongside the request @@ -288,7 +320,9 @@ def read_authorization_models(self, options: dict[str, int | str] = None): return api_response def write_authorization_model( - self, body: WriteAuthorizationModelRequest, options: dict[str, int | str] = None + self, + body: WriteAuthorizationModelRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Write authorization model. @@ -305,7 +339,9 @@ def write_authorization_model( ) return api_response - def read_authorization_model(self, options: dict[str, int | str] = None): + def read_authorization_model( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Read an authorization model. :param header(options) - Custom headers to send alongside the request @@ -321,7 +357,9 @@ def read_authorization_model(self, options: dict[str, int | str] = None): ) return api_response - def read_latest_authorization_model(self, options: dict[str, int | str] = None): + def read_latest_authorization_model( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Convenient method of reading the latest authorization model :param header(options) - Custom headers to send alongside the request @@ -346,7 +384,9 @@ def read_latest_authorization_model(self, options: dict[str, int | str] = None): ####################### def read_changes( - self, body: ClientReadChangesRequest, options: dict[str, str] = None + self, + body: ClientReadChangesRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Read changes for specified type @@ -359,14 +399,23 @@ def read_changes( :param retryParams.minWaitInMs(options) - Override the minimum wait before a retry is initiated """ kwargs = options_to_kwargs(options) - kwargs["type"] = body.type - kwargs["start_time"] = body.start_time + + if body.type is not None: + kwargs["type"] = body.type + + if body.start_time is not None: + kwargs["start_time"] = body.start_time + api_response = self._api.read_changes( **kwargs, ) return api_response - def read(self, body: ReadRequestTupleKey, options: dict[str, str] = None): + def read( + self, + body: ReadRequestTupleKey, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Read changes for specified type :param body - the tuples we want to read @@ -408,7 +457,10 @@ def read(self, body: ReadRequestTupleKey, options: dict[str, str] = None): return api_response def _write_single_batch( - self, batch: list[ClientTuple], is_write: bool, options: dict[str, str] = None + self, + batch: list[ClientTuple], + is_write: bool, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): try: write_batch = None @@ -431,7 +483,7 @@ def _write_batches( tuple_keys: list[ClientTuple], transaction: WriteTransactionOpts, is_write: bool, - options: dict[str, str] = None, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Internal function for write/delete batches @@ -454,7 +506,9 @@ def _write_batches( return batch_write_responses def _write_with_transaction( - self, body: ClientWriteRequest, options: dict[str, str] = None + self, + body: ClientWriteRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Write or deletes tuples @@ -488,7 +542,11 @@ def _write_with_transaction( ] return ClientWriteResponse(writes=writes_response, deletes=deletes_response) - def write(self, body: ClientWriteRequest, options: dict[str, str] = None): + def write( + self, + body: ClientWriteRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Write or deletes tuples :param body - the write request @@ -520,7 +578,11 @@ def write(self, body: ClientWriteRequest, options: dict[str, str] = None): ) return ClientWriteResponse(writes=writes_response, deletes=deletes_response) - def write_tuples(self, body: list[ClientTuple], options: dict[str, str] = None): + def write_tuples( + self, + body: list[ClientTuple], + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Convenient method for writing tuples :param body - the list of tuples we want to write @@ -533,7 +595,11 @@ def write_tuples(self, body: list[ClientTuple], options: dict[str, str] = None): result = self.write(ClientWriteRequest(body, None), options) return result - def delete_tuples(self, body: list[ClientTuple], options: dict[str, str] = None): + def delete_tuples( + self, + body: list[ClientTuple], + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Convenient method for deleteing tuples :param body - the list of tuples we want to delete @@ -549,7 +615,11 @@ def delete_tuples(self, body: list[ClientTuple], options: dict[str, str] = None) ####################### # Relationship Queries ####################### - def check(self, body: ClientCheckRequest, options: dict[str, str] = None): + def check( + self, + body: ClientCheckRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Check whether a user is authorized to access an object :param body - ClientCheckRequest defining check request @@ -580,7 +650,9 @@ def check(self, body: ClientCheckRequest, options: dict[str, str] = None): return api_response def _single_client_batch_check( - self, body: ClientCheckRequest, options: dict[str, str] = None + self, + body: ClientCheckRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a single batch request and return body in a SingleBatchCheckResponse @@ -603,7 +675,9 @@ def _single_client_batch_check( ) def client_batch_check( - self, body: list[ClientCheckRequest], options: dict[str, str | int] = None + self, + body: list[ClientCheckRequest], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a set of checks @@ -645,7 +719,7 @@ def single_batch_check(request): def _single_batch_check( self, body: BatchCheckRequest, - options: dict[str, str] = None, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run a single BatchCheck request @@ -660,7 +734,11 @@ def _single_batch_check( except Exception as err: raise err - def batch_check(self, body: ClientBatchCheckRequest, options=None): + def batch_check( + self, + body: ClientBatchCheckRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Run a batchcheck request :param body - BatchCheck request @@ -755,7 +833,11 @@ def single_batch_check(checks): return ClientBatchCheckResponse(result) - def expand(self, body: ClientExpandRequest, options: dict[str, str] = None): + def expand( + self, + body: ClientExpandRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Run expand request :param body - list of ClientExpandRequest defining expand request @@ -784,7 +866,9 @@ def expand(self, body: ClientExpandRequest, options: dict[str, str] = None): return api_response def list_objects( - self, body: ClientListObjectsRequest, options: dict[str, str] = None + self, + body: ClientListObjectsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Run list object request @@ -814,7 +898,9 @@ def list_objects( return api_response def streamed_list_objects( - self, body: ClientListObjectsRequest, options: dict[str, str] = None + self, + body: ClientListObjectsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Retrieve all objects of the given type that the user has a relation with, using the streaming ListObjects API. @@ -851,7 +937,9 @@ def streamed_list_objects( return def list_relations( - self, body: ClientListRelationsRequest, options: dict[str, str] = None + self, + body: ClientListRelationsRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Return all the relations for which user has a relationship with the object @@ -884,7 +972,11 @@ def list_relations( result_list = list(result_iterator) return [i.request.relation for i in result_list] - def list_users(self, body: ClientListUsersRequest, options: dict[str, str] = None): + def list_users( + self, + body: ClientListUsersRequest, + options: dict[str, int | str | dict[str, int | str]] | None = None, + ): """ Run list users request :param body - list user parameters @@ -917,7 +1009,9 @@ def list_users(self, body: ClientListUsersRequest, options: dict[str, str] = Non ####################### # Assertions ####################### - def read_assertions(self, options: dict[str, str] = None): + def read_assertions( + self, options: dict[str, int | str | dict[str, int | str]] | None = None + ): """ Return the assertions :param authorization_model_id(options) - Overrides the authorization model id in the configuration @@ -933,7 +1027,9 @@ def read_assertions(self, options: dict[str, str] = None): return api_response def write_assertions( - self, body: list[ClientAssertion], options: dict[str, str] = None + self, + body: list[ClientAssertion], + options: dict[str, int | str | dict[str, int | str]] | None = None, ): """ Upsert the assertions @@ -947,7 +1043,7 @@ def write_assertions( kwargs = options_to_kwargs(options) authorization_model_id = self._get_authorization_model_id(options) - def map_to_assertion(client_assertion: ClientAssertion): + def map_to_assertion(client_assertion: ClientAssertion) -> Assertion: return Assertion( TupleKey( user=client_assertion.user, diff --git a/openfga_sdk/sync/open_fga_api.py b/openfga_sdk/sync/open_fga_api.py index 6305591..0213d93 100644 --- a/openfga_sdk/sync/open_fga_api.py +++ b/openfga_sdk/sync/open_fga_api.py @@ -192,7 +192,7 @@ def batch_check_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "batch_check", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -373,7 +373,7 @@ def check_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "check", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -541,7 +541,7 @@ def create_store_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "create_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -690,7 +690,7 @@ def delete_store_with_http_info(self, **kwargs): response_types_map = {} - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "delete_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -871,7 +871,7 @@ def expand_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "expand", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1028,7 +1028,7 @@ def get_store_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "get_store", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1210,7 +1210,7 @@ def list_objects_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_objects", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1376,7 +1376,7 @@ def list_stores_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_stores", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1557,7 +1557,7 @@ def list_users_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "list_users", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1738,7 +1738,7 @@ def read_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -1913,7 +1913,7 @@ def read_assertions_with_http_info(self, authorization_model_id, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_assertions", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2088,7 +2088,7 @@ def read_authorization_model_with_http_info(self, id, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_authorization_model", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2262,7 +2262,7 @@ def read_authorization_models_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_authorization_models", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2446,7 +2446,7 @@ def read_changes_with_http_info(self, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "read_changes", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2628,7 +2628,7 @@ def streamed_list_objects_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "streamed_list_objects", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -2809,7 +2809,7 @@ def write_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -3001,7 +3001,7 @@ def write_assertions_with_http_info(self, authorization_model_id, body, **kwargs response_types_map = {} - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write_assertions", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( @@ -3185,7 +3185,7 @@ def write_authorization_model_with_http_info(self, body, **kwargs): 500: "InternalErrorMessageResponse", } - telemetry_attributes: dict[TelemetryAttribute, str | int] = { + telemetry_attributes: dict[TelemetryAttribute, str | bool | int | float] = { TelemetryAttributes.fga_client_request_method: "write_authorization_model", TelemetryAttributes.fga_client_request_store_id: self.api_client.get_store_id(), TelemetryAttributes.fga_client_request_model_id: local_var_params.get( diff --git a/openfga_sdk/sync/rest.py b/openfga_sdk/sync/rest.py index 397dd06..1384a4e 100644 --- a/openfga_sdk/sync/rest.py +++ b/openfga_sdk/sync/rest.py @@ -16,7 +16,7 @@ import re import ssl import urllib -from typing import Any, List, Optional, Tuple +from typing import Any import urllib3 @@ -36,28 +36,37 @@ class RESTResponse(io.IOBase): """ - Represents an HTTP response object in the non-async client. + Represents an HTTP response object in the synchronous client. """ - def __init__(self, resp: urllib3.HTTPResponse, data: bytes) -> None: + response: urllib3.BaseHTTPResponse + status: int + reason: str | None + data: bytes + + def __init__( + self, + resp: urllib3.BaseHTTPResponse, + data: bytes, + ) -> None: """ - Initializes a RESTResponse with a urllib3.HTTPResponse and corresponding data. + Initializes a RESTResponse with a urllib3.BaseHTTPResponse and corresponding data. - :param resp: The urllib3.HTTPResponse object. + :param resp: The urllib3.BaseHTTPResponse object. :param data: The raw byte data read from the response. """ - self.urllib3_response = resp + self.response = resp self.status = resp.status self.reason = resp.reason self.data = data - def getheaders(self) -> dict: + def getheaders(self) -> dict[str, str]: """ Returns a dictionary of the response headers. """ - return self.urllib3_response.headers + return dict(self.response.headers) - def getheader(self, name: str, default: Optional[str] = None) -> Optional[str]: + def getheader(self, name: str, default: str | None = None) -> str | None: """ Returns a specific header value by name. @@ -65,7 +74,7 @@ def getheader(self, name: str, default: Optional[str] = None) -> Optional[str]: :param default: The default value if header is not found. :return: The header value, or default if not present. """ - return self.urllib3_response.headers.get(name, default) + return self.response.headers.get(name, default) class RESTClientObject: @@ -74,7 +83,10 @@ class RESTClientObject: """ def __init__( - self, configuration: Any, pools_size: int = 4, maxsize: Optional[int] = None + self, + configuration: Any, + pools_size: int = 4, + maxsize: int | None = None, ) -> None: """ Creates a new RESTClientObject using urllib3. @@ -117,16 +129,18 @@ def __init__( self._timeout_millisec = configuration.timeout_millisec if hasattr(configuration, "proxy") and configuration.proxy is not None: - self.pool_manager = urllib3.ProxyManager( - num_pools=pools_size, - maxsize=maxsize, - cert_reqs=cert_reqs, - ca_certs=configuration.ssl_ca_cert, - cert_file=configuration.cert_file, - key_file=configuration.key_file, - proxy_url=configuration.proxy, - proxy_headers=configuration.proxy_headers, - **addition_pool_args, + self.pool_manager: urllib3.ProxyManager | urllib3.PoolManager = ( + urllib3.ProxyManager( + num_pools=pools_size, + maxsize=maxsize, + cert_reqs=cert_reqs, + ca_certs=configuration.ssl_ca_cert, + cert_file=configuration.cert_file, + key_file=configuration.key_file, + proxy_url=configuration.proxy, + proxy_headers=configuration.proxy_headers, + **addition_pool_args, + ) ) return @@ -151,12 +165,12 @@ def build_request( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[dict] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: dict | None = None, _preload_content: bool = True, - _request_timeout: Optional[float | tuple] = None, + _request_timeout: float | tuple | None = None, ) -> dict: """ Builds a dictionary of request arguments suitable for urllib3. @@ -244,7 +258,7 @@ def build_request( return args def handle_response_exception( - self, response: RESTResponse | urllib3.HTTPResponse + self, response: RESTResponse | urllib3.BaseHTTPResponse ) -> None: """ Raises exceptions if response status indicates an error. @@ -272,7 +286,7 @@ def handle_response_exception( def _accumulate_json_lines( self, leftover: bytes, data: bytes, buffer: bytearray - ) -> Tuple[bytes, List[Any]]: + ) -> tuple[bytes, list[Any]]: """ Processes a chunk of data plus any leftover bytes from a previous iteration. Splits on newlines, decodes valid JSON lines, and returns updated leftover bytes @@ -283,7 +297,7 @@ def _accumulate_json_lines( :param buffer: The main bytearray buffer for all data in this request. :return: A tuple of (updated leftover bytes, list of decoded objects). """ - objects: List[Any] = [] + objects: list[Any] = [] leftover += data lines = leftover.split( b"\n" @@ -305,11 +319,11 @@ def stream( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[dict] = None, - _request_timeout: Optional[float | tuple] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: dict | None = None, + _request_timeout: float | tuple | None = None, ): """ Streams JSON objects from a specified endpoint, reassembling partial chunks @@ -386,13 +400,13 @@ def request( self, method: str, url: str, - query_params: Optional[dict] = None, - headers: Optional[dict] = None, - body: Optional[Any] = None, - post_params: Optional[dict] = None, + query_params: dict | None = None, + headers: dict | None = None, + body: Any | None = None, + post_params: dict | None = None, _preload_content: bool = True, - _request_timeout: Optional[float | tuple] = None, - ) -> RESTResponse | urllib3.HTTPResponse: + _request_timeout: float | tuple | None = None, + ) -> RESTResponse | urllib3.BaseHTTPResponse: """ Executes a request and returns the response object. @@ -422,20 +436,21 @@ def request( ) # Send request, collect response handler - resp = self.pool_manager.request(**args) + wrapped_response: RESTResponse | None = None + raw_response: urllib3.BaseHTTPResponse = self.pool_manager.request(**args) # If we want to preload the response, read it if _preload_content: # Collect response data and transform response (JSON) into RESTResponse object - resp = RESTResponse(resp, resp.data) + wrapped_response = RESTResponse(raw_response, raw_response.data) # Log the response body - logger.debug("response body: %s", resp.data) + logger.debug("response body: %s", wrapped_response.data.decode("utf-8")) # Handle any errors that may have occurred - self.handle_response_exception(resp) + self.handle_response_exception(raw_response) # Release the connection back to the pool self.close() - return resp + return wrapped_response or raw_response diff --git a/openfga_sdk/telemetry/attributes.py b/openfga_sdk/telemetry/attributes.py index f543348..55b74d2 100644 --- a/openfga_sdk/telemetry/attributes.py +++ b/openfga_sdk/telemetry/attributes.py @@ -20,9 +20,6 @@ from openfga_sdk.credentials import Credentials from openfga_sdk.exceptions import ApiException from openfga_sdk.rest import RESTResponse -from openfga_sdk.telemetry.utilities import ( - doesInstanceHaveCallable, -) class TelemetryAttribute(NamedTuple): @@ -103,13 +100,14 @@ class TelemetryAttributes: user_agent_original, ] + @staticmethod + def getAll() -> list[TelemetryAttribute]: + return TelemetryAttributes._attributes + @staticmethod def get( name: str | None = None, - ) -> list[TelemetryAttribute] | TelemetryAttribute | None: - if name is None: - return TelemetryAttributes._attributes - + ) -> TelemetryAttribute | None: for attribute in TelemetryAttributes._attributes: if attribute.name == name: return attribute @@ -118,10 +116,10 @@ def get( @staticmethod def prepare( - attributes: dict[TelemetryAttribute, str | int] | None, - filter: list[TelemetryAttribute] | None = None, - ) -> dict[str, str | int]: - response = {} + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, + filter: list[TelemetryAttribute] | dict[TelemetryAttribute, bool] | None = None, + ) -> dict[str, str | bool | int | float]: + response: dict[str, str | bool | int | float] = {} if filter is None or filter == []: return response @@ -182,7 +180,10 @@ def prepare( return response @staticmethod - def fromBody(body: Any, attributes: dict[TelemetryAttribute, str | int] = None): + def fromBody( + body: Any, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, + ): from openfga_sdk.models.batch_check_request import BatchCheckRequest if attributes is None: @@ -200,90 +201,104 @@ def fromBody(body: Any, attributes: dict[TelemetryAttribute, str | int] = None): @staticmethod def fromRequest( - user_agent: str = None, - fga_method: str = None, - http_method: str = None, - url: str = None, - resend_count: int = None, - start: float = None, - credentials: Credentials = None, - attributes: dict[TelemetryAttribute, str | int] = None, - ) -> dict[TelemetryAttribute, str | int]: - if attributes is None: - attributes = {} + user_agent: str | None = None, + fga_method: str | None = None, + http_method: str | None = None, + url: str | None = None, + resend_count: int | None = None, + start: float | None = None, + credentials: Credentials | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, + ) -> dict[TelemetryAttribute, str | bool | int | float]: + _attributes: dict[TelemetryAttribute, str | bool | int | float] = {} + + if attributes is not None: + _attributes = attributes if ( - TelemetryAttributes.fga_client_request_method not in attributes + TelemetryAttributes.fga_client_request_method not in _attributes and fga_method is not None ): fga_method = fga_method.rsplit("/", 1)[-1] if fga_method: - attributes[TelemetryAttributes.fga_client_request_method] = ( + _attributes[TelemetryAttributes.fga_client_request_method] = ( fga_method.rsplit("/", 1)[-1] ) - if TelemetryAttributes.fga_client_request_method in attributes: - fga_method = attributes[TelemetryAttributes.fga_client_request_method] - fga_method = ( - fga_method.lower().replace("_", " ").title().replace(" ", "").strip() - ) + if TelemetryAttributes.fga_client_request_method in _attributes: + _attr_fga_method = _attributes[ + TelemetryAttributes.fga_client_request_method + ] + + if type(_attr_fga_method) is str: + _attr_fga_method = ( + _attr_fga_method.lower() + .replace("_", " ") + .title() + .replace(" ", "") + .strip() + ) - if fga_method: - attributes[TelemetryAttributes.fga_client_request_method] = fga_method - else: - del attributes[TelemetryAttributes.fga_client_request_method] + if _attr_fga_method: + _attributes[TelemetryAttributes.fga_client_request_method] = ( + _attr_fga_method + ) + else: + del _attributes[TelemetryAttributes.fga_client_request_method] if user_agent is not None: - attributes[TelemetryAttributes.user_agent_original] = user_agent + _attributes[TelemetryAttributes.user_agent_original] = user_agent if http_method is not None: - attributes[TelemetryAttributes.http_request_method] = http_method + _attributes[TelemetryAttributes.http_request_method] = http_method if url is not None: - attributes[TelemetryAttributes.http_host] = urllib.parse.urlparse( - url - ).hostname - attributes[TelemetryAttributes.url_scheme] = urllib.parse.urlparse( - url - ).scheme - attributes[TelemetryAttributes.url_full] = url + _hostname = urllib.parse.urlparse(url).hostname + _scheme = urllib.parse.urlparse(url).scheme + + if type(_hostname) is str: + _attributes[TelemetryAttributes.http_host] = _hostname + + if type(_scheme) is str: + _attributes[TelemetryAttributes.url_scheme] = _scheme + + _attributes[TelemetryAttributes.url_full] = url if start is not None and start > 0: - attributes[TelemetryAttributes.http_client_request_duration] = int( + _attributes[TelemetryAttributes.http_client_request_duration] = int( (time.time() - start) * 1000 ) if resend_count is not None and resend_count > 0: - attributes[TelemetryAttributes.http_request_resend_count] = resend_count + _attributes[TelemetryAttributes.http_request_resend_count] = resend_count if credentials is not None: if credentials.method == "client_credentials": - attributes[TelemetryAttributes.fga_client_request_client_id] = ( + _attributes[TelemetryAttributes.fga_client_request_client_id] = ( credentials.configuration.client_id ) - return attributes + return _attributes @staticmethod def fromResponse( - response: HTTPResponse - | RESTResponse - | ClientResponse - | ApiException - | None = None, + response: ( + HTTPResponse | RESTResponse | ClientResponse | ApiException | None + ) = None, credentials: Credentials | None = None, - attributes: dict[TelemetryAttribute, str | int] | None = None, - ) -> dict[TelemetryAttribute, str | int]: + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, + ) -> dict[TelemetryAttribute, str | bool | int | float]: response_model_id = None response_query_duration = None + _attributes: dict[TelemetryAttribute, str | bool | int | float] = {} - if attributes is None: - attributes = {} + if attributes is not None: + _attributes = attributes if isinstance(response, ApiException): if response.status is not None: - attributes[TelemetryAttributes.http_response_status_code] = int( + _attributes[TelemetryAttributes.http_response_status_code] = int( response.status ) @@ -295,62 +310,67 @@ def fromResponse( if response is not None: if hasattr(response, "status"): - attributes[TelemetryAttributes.http_response_status_code] = int( + _attributes[TelemetryAttributes.http_response_status_code] = int( response.status ) - if doesInstanceHaveCallable(response, "getheader"): + if hasattr(response, "getheader") and callable(response.getheader): response_model_id = response.getheader("openfga-authorization-model-id") response_query_duration = response.getheader("fga-query-duration-ms") - if doesInstanceHaveCallable(response, "headers"): + if hasattr(response, "headers"): response_model_id = response.headers.get( "openfga-authorization-model-id" ) response_query_duration = response.headers.get("fga-query-duration-ms") if response_model_id is not None: - attributes[TelemetryAttributes.fga_client_response_model_id] = ( + _attributes[TelemetryAttributes.fga_client_response_model_id] = ( response_model_id ) if response_query_duration is not None: - attributes[TelemetryAttributes.http_server_request_duration] = ( + _attributes[TelemetryAttributes.http_server_request_duration] = ( response_query_duration ) if isinstance(credentials, Credentials): if credentials.method == "client_credentials": - attributes[TelemetryAttributes.fga_client_request_client_id] = ( + _attributes[TelemetryAttributes.fga_client_request_client_id] = ( credentials.configuration.client_id ) - return attributes + return _attributes @staticmethod def coalesceAttributeValue( attribute: TelemetryAttribute, - value: int | float | None = None, - attributes: dict[TelemetryAttribute, str | int] | None = None, - ) -> int | float | None: - if value is None: - if attribute in attributes: - value = attributes[attribute] + value: str | bool | int | float | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, + ) -> str | bool | int | float | None: + _value: str | bool | int | float | None = None if value is not None: + _value = value + else: + if attributes is not None and attribute in attributes.keys(): + _value = attributes.get(attribute) + + if _value is not None: if attribute.format == "int": try: - value = int(value) - except ValueError: - value = None - - if attribute.format == "float": + return int(_value) + except Exception: + pass + elif attribute.format == "float": try: - value = float(value) - except ValueError: - value = None - - if attribute.format == "string": - value = str(value) + return float(_value) + except Exception: + pass + elif attribute.format == "string": + try: + return str(_value) + except Exception: + pass - return value + return None diff --git a/openfga_sdk/telemetry/configuration.py b/openfga_sdk/telemetry/configuration.py index beaba28..b7114f4 100644 --- a/openfga_sdk/telemetry/configuration.py +++ b/openfga_sdk/telemetry/configuration.py @@ -10,7 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -from typing import NamedTuple +from typing import NamedTuple, Protocol, Type, runtime_checkable from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes from openfga_sdk.telemetry.counters import TelemetryCounter, TelemetryCounters @@ -28,7 +28,7 @@ class TelemetryMetricConfiguration: def __init__( self, - config: dict[TelemetryAttribute, bool] | None = None, + config: dict[TelemetryAttribute | str, bool] | None = None, fga_client_request_client_id: bool | None = None, fga_client_request_method: bool | None = None, fga_client_request_model_id: bool | None = None, @@ -521,10 +521,14 @@ def configure( # Apply an incoming configuration, if provided if isinstance(config, dict): for attribute, enabled in config.items(): - if isinstance(attribute, str): - attribute = TelemetryAttributes.get(name=attribute) + _attribute: TelemetryAttribute | None = None + + if isinstance(attribute, TelemetryAttribute): + _attribute = attribute + elif isinstance(attribute, str): + _attribute = TelemetryAttributes.get(name=attribute) - if not isinstance(attribute, TelemetryAttribute): + if not isinstance(_attribute, TelemetryAttribute): raise ValueError( f"Invalid attribute type provided in `TelemetryMetricConfiguration`; `TelemetryAttribute` expected, but `{type(attribute)}` was provided.", attribute, @@ -536,13 +540,13 @@ def configure( attribute, ) - if attribute not in self._state: + if _attribute not in self._state: raise ValueError( - f"Invalid attribute provided in `TelemetryMetricConfiguration`; `{attribute.name}` is not a supported attribute type for this context.", - attribute, + f"Invalid attribute provided in `TelemetryMetricConfiguration`; `{_attribute.name}` is not a supported attribute type for this context.", + _attribute, ) - self._state[attribute] = enabled + self._state[_attribute] = enabled # Reset the validation state self._valid = None @@ -561,11 +565,11 @@ def getAttributes( attributes = self._state if filter_enabled is True: - return [ - attribute + return { + attribute: enabled for attribute, enabled in attributes.items() if enabled is True - ] + } return attributes @@ -610,7 +614,7 @@ def isValid(self, raise_exception: bool = False) -> bool: return self._valid @staticmethod - def getSdkDefaults() -> dict[TelemetryAttribute, bool]: + def getSdkDefaults() -> dict[TelemetryAttribute | str, bool]: """ Get the default SDK configuration for the telemetry metric. @@ -636,18 +640,56 @@ def getSdkDefaults() -> dict[TelemetryAttribute, bool]: } -class TelemetryMetricsConfiguration: +@runtime_checkable +class TelemetryMetricsConfigurationProtocol(Protocol): + def clear(self) -> None: ... + + def configure( + self, + config: ( + dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None + ) = None, + clear: bool = False, + ) -> None: ... + + def getMetrics( + self, filter_enabled: bool = True + ) -> dict[ + TelemetryHistogram | TelemetryCounter, + TelemetryMetricConfiguration | dict[TelemetryAttribute | str, bool] | None, + ]: ... + + def isEnabled( + self, metric: TelemetryCounter | TelemetryHistogram | None = None + ) -> bool: ... + + def isValid(self, raise_exception: bool = False) -> bool: ... + + +class TelemetryMetricsConfiguration(TelemetryMetricsConfigurationProtocol): _state: dict[ - TelemetryHistogram | TelemetryCounter, TelemetryMetricConfiguration | None + TelemetryHistogram | TelemetryCounter, + TelemetryMetricConfiguration | dict[TelemetryAttribute | str, bool] | None, ] = {} _valid: bool | None = None def __init__( self, - config: dict[ - TelemetryHistogram | TelemetryCounter, TelemetryMetricConfiguration | None - ] - | None = None, + config: ( + dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None + ) = None, fga_client_credentials_request: TelemetryMetricConfiguration | None = None, fga_client_request_duration: TelemetryMetricConfiguration | None = None, fga_client_query_duration: TelemetryMetricConfiguration | None = None, @@ -694,8 +736,12 @@ def fga_client_request(self) -> TelemetryMetricConfiguration | None: :return: The configuration for the `fga-client.request` counter. """ + state = self._state[TelemetryCounters.fga_client_request] + + if isinstance(state, TelemetryMetricConfiguration): + return state - return self._state[TelemetryCounters.fga_client_request] + return None @fga_client_request.setter def fga_client_request(self, value: TelemetryMetricConfiguration | None): @@ -715,8 +761,12 @@ def fga_client_credentials_request(self) -> TelemetryMetricConfiguration | None: :return: The configuration for the `fga-client.credentials.request` counter. """ + state = self._state[TelemetryCounters.fga_client_credentials_request] + + if isinstance(state, TelemetryMetricConfiguration): + return state - return self._state[TelemetryCounters.fga_client_credentials_request] + return None @fga_client_credentials_request.setter def fga_client_credentials_request( @@ -738,8 +788,12 @@ def fga_client_request_duration(self) -> TelemetryMetricConfiguration | None: :return: The configuration for the `fga-client.query.duration` histogram. """ + state = self._state[TelemetryHistograms.fga_client_request_duration] - return self._state[TelemetryHistograms.fga_client_request_duration] + if isinstance(state, TelemetryMetricConfiguration): + return state + + return None @fga_client_request_duration.setter def fga_client_request_duration(self, value: TelemetryMetricConfiguration | None): @@ -759,8 +813,12 @@ def fga_client_query_duration(self) -> TelemetryMetricConfiguration | None: :return: The configuration for the `fga-client.request.duration` histogram. """ + state = self._state[TelemetryHistograms.fga_client_query_duration] - return self._state[TelemetryHistograms.fga_client_query_duration] + if isinstance(state, TelemetryMetricConfiguration): + return state + + return None @fga_client_query_duration.setter def fga_client_query_duration(self, value: TelemetryMetricConfiguration | None): @@ -787,11 +845,15 @@ def clear(self) -> None: def configure( self, - config: dict[ - TelemetryHistogram | TelemetryCounter | str, - TelemetryMetricConfiguration | dict[TelemetryAttribute, bool] | None, - ] - | None = None, + config: ( + dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None + ) = None, clear: bool = False, ) -> None: """ @@ -802,13 +864,19 @@ def configure( if isinstance(config, dict): for metric, configuration in config.items(): - if isinstance(metric, str): - metric = TelemetryCounters.get( - name=metric - ) or TelemetryHistograms.get(name=metric) + _metric: TelemetryHistogram | TelemetryCounter | None = None - if not isinstance(metric, TelemetryCounter) and not isinstance( + if isinstance(metric, TelemetryCounter) or isinstance( metric, TelemetryHistogram + ): + _metric = metric + elif isinstance(metric, str): + _metric = TelemetryCounters.get(metric) or TelemetryHistograms.get( + metric + ) + + if not isinstance(_metric, TelemetryCounter) and not isinstance( + _metric, TelemetryHistogram ): raise ValueError( f"Invalid metric type provided in `TelemetryMetricsConfiguration`; `TelemetryHistogram` or `TelemetryCounter` was expected, but `{type(metric)}` was provided.", @@ -827,20 +895,21 @@ def configure( configuration, ) - if metric not in self._state: + if _metric not in self._state: raise ValueError( - f"Invalid metric provided in `TelemetryMetricsConfiguration`; `{metric.name}` is not a supported metric type for this context.", - metric, + f"Invalid metric provided in `TelemetryMetricsConfiguration`; `{_metric.name}` is not a supported metric type for this context.", + _metric, ) - self._state[metric] = configuration + self._state[_metric] = configuration self._valid = None def getMetrics( self, filter_enabled: bool = True ) -> dict[ - TelemetryHistogram | TelemetryCounter, TelemetryMetricConfiguration | None + TelemetryHistogram | TelemetryCounter, + TelemetryMetricConfiguration | dict[TelemetryAttribute | str, bool] | None, ]: """ Returns a list of supported metrics. If `filter_enabled` is `True`, only enabled metrics are returned. @@ -853,11 +922,12 @@ def getMetrics( metrics = self._state if filter_enabled is True: - return [ - metric + return { + metric: configuration for metric, configuration in metrics.items() - if configuration is not None and configuration.isEnabled() - ] + if isinstance(configuration, TelemetryMetricConfiguration) + and configuration.isEnabled() + } return metrics @@ -876,9 +946,11 @@ def isEnabled( # Check if the specified metric is enabled if metric in self._state: + state = self._state[metric] + if ( - self._state[metric] is not None - and self._state[metric].isEnabled() is True + isinstance(state, TelemetryMetricConfiguration) + and state.isEnabled() is True ): return True @@ -892,26 +964,34 @@ def isValid(self, raise_exception: bool = False) -> bool: :return: A boolean indicating whether the metrics configuration is valid, including all sub-configurations. """ - - # Check if the validation state is already cached if self._valid is not None: return self._valid enabled = self.getMetrics(filter_enabled=True) # Validate all sub-configurations and cache the result - self._valid = [configuration.isValid() for configuration in enabled.values()] + for configuration in enabled.values(): + if ( + isinstance(configuration, TelemetryMetricConfiguration) + and not configuration.isValid() + ): + self._valid = False + break # If requested, raise an exception if the configuration is invalid if self._valid is False and raise_exception is True: raise ValueError("Invalid TelemetryMetricsConfiguration.") + if self._valid is None: + self._valid = True + # Return the validation state return self._valid @staticmethod def getSdkDefaults() -> dict[ - TelemetryHistogram | TelemetryCounter, TelemetryMetricConfiguration | None + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration | dict[TelemetryAttribute | str, bool] | None, ]: """ Get the default SDK configuration for telemetry metrics. @@ -927,7 +1007,7 @@ def getSdkDefaults() -> dict[ class TelemetryConfigurationType(NamedTuple): name: str - configurationClass: object + configurationClass: Type[TelemetryMetricsConfigurationProtocol] class TelemetryConfigurations: @@ -939,12 +1019,13 @@ class TelemetryConfigurations: _configurations: list[TelemetryConfigurationType] = [metrics] @staticmethod - def get( - name: str | None = None, - ) -> list[TelemetryConfigurationType] | TelemetryConfigurationType | None: - if name is None: - return TelemetryConfigurations._configurations + def getAll() -> list[TelemetryConfigurationType]: + return TelemetryConfigurations._configurations + @staticmethod + def get( + name: str, + ) -> TelemetryConfigurationType | None: for configuration in TelemetryConfigurations._configurations: if configuration.name == name: return configuration @@ -953,12 +1034,25 @@ def get( class TelemetryConfiguration: - _state: dict[str, TelemetryMetricsConfiguration | None] = {} + _state: dict[TelemetryConfigurationType, TelemetryMetricsConfiguration | None] = {} _valid: bool | None = None def __init__( self, - config: dict[str, TelemetryMetricsConfiguration | None] | None = None, + config: ( + dict[ + TelemetryConfigurationType | str, + TelemetryMetricsConfiguration + | dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None, + ] + | None + ) = None, metrics: TelemetryMetricsConfiguration | None = None, ): """ @@ -967,7 +1061,6 @@ def __init__( :param config: A dictionary containing the configuration for telemetry. :param metrics: Customize which metrics and attributes are included in telemetry collection. """ - # Instantiate with default state, and apply the incoming configuration, if one was provided self.configure(config=config, clear=True) @@ -981,7 +1074,6 @@ def metrics(self) -> TelemetryMetricsConfiguration | None: :return: The metrics configuration for telemetry. """ - return self._state[TelemetryConfigurations.metrics] @metrics.setter @@ -991,7 +1083,6 @@ def metrics(self, value: TelemetryMetricsConfiguration | None): :param value: The metrics configuration for telemetry. """ - if value is not None and not isinstance(value, TelemetryMetricsConfiguration): raise ValueError( "A `metrics` configuration must be an instance of `TelemetryMetricsConfiguration` or `None`." @@ -1011,16 +1102,20 @@ def clear(self) -> None: def configure( self, - config: dict[ - TelemetryConfigurationType | str, - TelemetryMetricsConfiguration - | dict[ - TelemetryHistogram | TelemetryCounter, - TelemetryMetricConfiguration | dict[TelemetryAttribute, bool] | None, + config: ( + dict[ + TelemetryConfigurationType | str, + TelemetryMetricsConfiguration + | dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration + | dict[TelemetryAttribute | str, bool] + | None, + ] + | None, ] - | None, - ] - | None = None, + | None + ) = None, clear: bool = False, ) -> None: """ @@ -1031,34 +1126,39 @@ def configure( if isinstance(config, dict): for context, configuration in config.items(): - if isinstance(context, str): - context = TelemetryConfigurations.get(context) - - if not isinstance(context, TelemetryConfigurationType): - raise ValueError( - f"Invalid context provided in `TelemetryConfiguration`; a valid string or an `TelemetryConfigurationType` instance was expected, but `{type(context)}` was provided.", - context, - ) - - if isinstance(configuration, dict): - configuration = TelemetryMetricsConfiguration(configuration) - - if ( - not isinstance(configuration, context.configurationClass) - and configuration is not None - ): - raise ValueError( - f"Invalid context configuration provided in `TelemetryConfiguration`; a {type(context.configurationClass)} was expected, but `{type(configuration)}` was provided.", - configuration, - ) - - if context not in self._state: - raise ValueError( - f"Invalid context provided in `TelemetryConfiguration`; `{context.name}` is not a supported context type for this configuration context.", - context, - ) - - self._state[context] = configuration + _context: TelemetryConfigurationType | None = None + + if isinstance(context, TelemetryConfigurationType): + _context = context + elif isinstance(context, str): + _context = TelemetryConfigurations.get(context) + + if not isinstance(_context, TelemetryConfigurationType): + raise ValueError( + f"Invalid context provided in `TelemetryConfiguration`; a valid string or an `TelemetryConfigurationType` instance was expected, but `{context}` was provided.", + context, + ) + + if isinstance(_context, TelemetryConfigurationType): + if isinstance(configuration, dict): + configuration = TelemetryMetricsConfiguration(configuration) + + if ( + not isinstance(configuration, _context.configurationClass) + and configuration is not None + ): + raise ValueError( + f"Invalid context configuration provided in `TelemetryConfiguration`; a {type(_context.configurationClass)} was expected, but `{type(configuration)}` was provided.", + configuration, + ) + + if _context not in self._state: + raise ValueError( + f"Invalid context provided in `TelemetryConfiguration`; `{_context.name}` is not a supported context type for this configuration context.", + _context, + ) + + self._state[_context] = configuration self._valid = None @@ -1072,7 +1172,6 @@ def getConfigurations( :return: A list of enabled contexts. """ - contexts = self._state if filter_enabled is True: @@ -1092,16 +1191,25 @@ def isEnabled( :return: A boolean indicating whether telemetry is enabled. """ + _configuration: TelemetryConfigurationType | None = None - if configuration is None: + if isinstance(configuration, TelemetryConfigurationType): + _configuration = configuration + + if isinstance(configuration, str): + _configuration = TelemetryConfigurations.get(name=configuration) + + if _configuration is None: return True if any(self.getConfigurations(filter_enabled=True)) else False - if configuration in self._state: + if _configuration in self._state: + state = self._state[_configuration] + if ( - self._state[configuration] is not None - or self._state[configuration].isEnabled() is True + isinstance(state, TelemetryMetricsConfiguration) + and state.isEnabled() is True ): - return self._state[configuration].isEnabled() + return True return False @@ -1113,24 +1221,33 @@ def isValid(self, raise_exception: bool = False) -> bool: :return: A boolean indicating whether the telemetry configuration is valid, including all sub-configurations. """ - if self._valid is not None: return self._valid enabled = self.getConfigurations(filter_enabled=True) - self._valid = all( - [configuration.isValid() for configuration in enabled.values()] - ) + for configuration in enabled.values(): + if configuration is not None and not configuration.isValid(): + self._valid = False + break if self._valid is False and raise_exception is True: raise ValueError("Invalid TelemetryConfiguration.") + if self._valid is None: + self._valid = True + return self._valid @staticmethod def getSdkDefaults() -> dict[ - TelemetryConfigurationType, TelemetryMetricsConfiguration | None + TelemetryConfigurationType | str, + TelemetryMetricsConfiguration + | dict[ + TelemetryHistogram | TelemetryCounter | str, + TelemetryMetricConfiguration | dict[TelemetryAttribute | str, bool] | None, + ] + | None, ]: """ Get the default SDK configuration for telemetry. @@ -1143,13 +1260,12 @@ def getSdkDefaults() -> dict[ def isMetricEnabled( - config: TelemetryConfiguration | TelemetryMetricsConfiguration, + config: TelemetryConfiguration | TelemetryMetricsConfiguration | None, metric: TelemetryCounter | TelemetryHistogram, ) -> bool: """ Check if a particular metric is enabled for telemetry collection. """ - if config is not None and metric is not None: if isinstance(config, TelemetryConfiguration): config = config.metrics diff --git a/openfga_sdk/telemetry/counters.py b/openfga_sdk/telemetry/counters.py index 01c9545..03091aa 100644 --- a/openfga_sdk/telemetry/counters.py +++ b/openfga_sdk/telemetry/counters.py @@ -35,13 +35,14 @@ class TelemetryCounters: fga_client_request, ] + @staticmethod + def getAll() -> list[TelemetryCounter]: + return TelemetryCounters._counters + @staticmethod def get( name: str | None = None, - ) -> list[TelemetryCounter] | TelemetryCounter | None: - if name is None: - return TelemetryCounters._counters - + ) -> TelemetryCounter | None: for counter in TelemetryCounters._counters: if counter.name == name: return counter diff --git a/openfga_sdk/telemetry/histograms.py b/openfga_sdk/telemetry/histograms.py index 8a5b3fb..e12a928 100644 --- a/openfga_sdk/telemetry/histograms.py +++ b/openfga_sdk/telemetry/histograms.py @@ -34,13 +34,14 @@ class TelemetryHistograms: fga_client_query_duration, ] + @staticmethod + def getAll() -> list[TelemetryHistogram]: + return TelemetryHistograms._histograms + @staticmethod def get( name: str | None = None, - ) -> list[TelemetryHistogram] | TelemetryHistogram | None: - if name is None: - return TelemetryHistograms._histograms - + ) -> TelemetryHistogram | None: for histogram in TelemetryHistograms._histograms: if histogram.name == name: return histogram diff --git a/openfga_sdk/telemetry/metrics.py b/openfga_sdk/telemetry/metrics.py index 63ed27c..0891ced 100644 --- a/openfga_sdk/telemetry/metrics.py +++ b/openfga_sdk/telemetry/metrics.py @@ -18,6 +18,7 @@ ) from openfga_sdk.telemetry.configuration import ( TelemetryConfiguration, + TelemetryMetricConfiguration, isMetricEnabled, ) from openfga_sdk.telemetry.counters import TelemetryCounter, TelemetryCounters @@ -25,7 +26,7 @@ class TelemetryMetrics: - _meter: Meter = None + _meter: Meter | None = None _histograms: dict[str, Histogram] = {} _counters: dict[str, Counter] = {} @@ -76,7 +77,7 @@ def histogram(self, histogram: TelemetryHistogram) -> Histogram: def request( self, value: int = 1, - attributes: dict[TelemetryAttribute, str | int] | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, configuration: TelemetryConfiguration | None = None, ) -> Counter: """ @@ -85,20 +86,33 @@ def request( counter = self.counter(TelemetryCounters.fga_client_request) if isMetricEnabled(configuration, TelemetryCounters.fga_client_request): - attributes = TelemetryAttributes.prepare( + attribute_filters = None + + if ( + isinstance(configuration, TelemetryConfiguration) + and isinstance(configuration.metrics, TelemetryMetricConfiguration) + and isinstance( + configuration.metrics.fga_client_request, + TelemetryMetricConfiguration, + ) + ): + attribute_filters = ( + configuration.metrics.fga_client_request.getAttributes() + ) + + prepared_attributes = TelemetryAttributes.prepare( attributes, - filter=configuration.metrics.fga_client_request.getAttributes(), + filter=attribute_filters, ) - if value is not None: - counter.add(amount=value, attributes=attributes) + counter.add(amount=value, attributes=prepared_attributes) return counter def credentialsRequest( self, value: int = 1, - attributes: dict[TelemetryAttribute, str | int] | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, configuration: TelemetryConfiguration | None = None, ) -> Counter: """ @@ -109,76 +123,125 @@ def credentialsRequest( if isMetricEnabled( configuration, TelemetryCounters.fga_client_credentials_request ): - attributes = TelemetryAttributes.prepare( + attribute_filters = None + + if ( + isinstance(configuration, TelemetryConfiguration) + and isinstance(configuration.metrics, TelemetryMetricConfiguration) + and isinstance( + configuration.metrics.fga_client_credentials_request, + TelemetryMetricConfiguration, + ) + ): + attribute_filters = ( + configuration.metrics.fga_client_credentials_request.getAttributes() + ) + + prepared_attributes = TelemetryAttributes.prepare( attributes, - filter=configuration.metrics.fga_client_credentials_request.getAttributes(), + filter=attribute_filters, ) - if value is not None: - counter.add(amount=value, attributes=attributes) + counter.add(amount=value, attributes=prepared_attributes) # type: ignore[arg-type] return counter def requestDuration( self, value: int | float | None = None, - attributes: dict[TelemetryAttribute, str | int] | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, configuration: TelemetryConfiguration | None = None, ) -> Histogram: """ Record the duration of a request made by the client. """ histogram = self.histogram(TelemetryHistograms.fga_client_request_duration) + _attributes: dict[TelemetryAttribute, str | bool | int | float] = ( + attributes or {} + ) if isMetricEnabled( configuration, TelemetryHistograms.fga_client_request_duration ): - attributes[TelemetryAttributes.http_client_request_duration] = value = ( - TelemetryAttributes.coalesceAttributeValue( - TelemetryAttributes.http_client_request_duration, - value, - attributes, - ) + coalesced_value = TelemetryAttributes.coalesceAttributeValue( + TelemetryAttributes.http_client_request_duration, + value, + _attributes, ) - attributes = TelemetryAttributes.prepare( - attributes, - filter=configuration.metrics.fga_client_request_duration.getAttributes(), - ) + if type(coalesced_value) is int or type(coalesced_value) is float: + _attributes[TelemetryAttributes.http_client_request_duration] = ( + value + ) = coalesced_value + + attribute_filters = None + + if ( + isinstance(configuration, TelemetryConfiguration) + and isinstance(configuration.metrics, TelemetryMetricConfiguration) + and isinstance( + configuration.metrics.fga_client_request_duration, + TelemetryMetricConfiguration, + ) + ): + attribute_filters = configuration.metrics.fga_client_request_duration.getAttributes() + + prepared_attributes = TelemetryAttributes.prepare( + _attributes, + filter=attribute_filters, + ) - if value is not None: - histogram.record(amount=value, attributes=attributes) + histogram.record(amount=value, attributes=prepared_attributes) # type: ignore[arg-type] return histogram def queryDuration( self, value: int | float | None = None, - attributes: dict[TelemetryAttribute, str | int] | None = None, + attributes: dict[TelemetryAttribute, str | bool | int | float] | None = None, configuration: TelemetryConfiguration | None = None, ) -> Histogram: """ Record the duration of a query made by the client, as reported by the server. """ histogram = self.histogram(TelemetryHistograms.fga_client_query_duration) + _attributes: dict[TelemetryAttribute, str | bool | int | float] = ( + attributes or {} + ) if isMetricEnabled( configuration, TelemetryHistograms.fga_client_query_duration ): - attributes[TelemetryAttributes.http_server_request_duration] = value = ( - TelemetryAttributes.coalesceAttributeValue( - TelemetryAttributes.http_server_request_duration, - value, - attributes, - ) + coalesced_value = TelemetryAttributes.coalesceAttributeValue( + TelemetryAttributes.http_server_request_duration, + value, + _attributes, ) - attributes = TelemetryAttributes.prepare( - attributes, - filter=configuration.metrics.fga_client_query_duration.getAttributes(), - ) + if type(coalesced_value) is int or type(coalesced_value) is float: + _attributes[TelemetryAttributes.http_server_request_duration] = ( + value + ) = coalesced_value + + attribute_filters = None + + if ( + isinstance(configuration, TelemetryConfiguration) + and isinstance(configuration.metrics, TelemetryMetricConfiguration) + and isinstance( + configuration.metrics.fga_client_query_duration, + TelemetryMetricConfiguration, + ) + ): + attribute_filters = ( + configuration.metrics.fga_client_query_duration.getAttributes() + ) + + prepared_attributes = TelemetryAttributes.prepare( + _attributes, + filter=attribute_filters, + ) - if value is not None: - histogram.record(amount=value, attributes=attributes) + histogram.record(amount=value, attributes=prepared_attributes) # type: ignore[arg-type] return histogram diff --git a/openfga_sdk/telemetry/utilities.py b/openfga_sdk/telemetry/utilities.py deleted file mode 100644 index 6edbcf6..0000000 --- a/openfga_sdk/telemetry/utilities.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Python SDK for OpenFGA - -API version: 1.x -Website: https://openfga.dev -Documentation: https://openfga.dev/docs -Support: https://openfga.dev/community -License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE) - -NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. -""" - - -def doesInstanceHaveCallable(instance: object, callableName: str) -> bool: - instanceCallable = getattr(instance, callableName, None) - - if instanceCallable is None: - return False - - return callable(instanceCallable) diff --git a/pyproject.toml b/pyproject.toml index 74966dc..ca06cb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ indent-width = 4 target-version = "py310" -[lint] +[tool.ruff.lint] select = ["E4", "E7", "E9", "F"] ignore = [] @@ -42,7 +42,7 @@ unfixable = [] dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -[format] +[tool.ruff.format] quote-style = "double" indent-style = "space" skip-magic-trailing-comma = false @@ -50,7 +50,7 @@ line-ending = "auto" [tool.pytest.ini_options] testpaths = [ - "tests", + "test", "integration", ] @@ -58,4 +58,13 @@ addopts = "--cov=openfga_sdk --cov-report term-missing --cov-report xml --cov-re asyncio_mode = "strict" asyncio_default_fixture_loop_scope = "function" -asyncio_default_test_loop_scope = "function" + +[tool.mypy] +python_version = "3.10" +packages = "openfga_sdk" +exclude = [ + "openfa_sdk/models", +] +#warn_return_any = "True" +#warn_unused_configs = "True" +#disallow_untyped_defs = "True" diff --git a/requirements.txt b/requirements.txt index 4eef03d..8cda195 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ setuptools >= 69.1.1 build >= 1.2.1, < 2 urllib3 >= 1.25.11, < 3 opentelemetry-api >= 1.25.0, < 2 +python-dateutil >= 2.9.0, < 3 diff --git a/test-requirements.txt b/test-requirements.txt index 2757011..b39447e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,3 +5,4 @@ mock >= 5.1.0, < 6 pytest-asyncio >= 0.25, < 1 pytest-cov >= 5, < 7 ruff >= 0.9, < 1 +mypy >= 1.14.1, < 2 diff --git a/test/rest_test.py b/test/rest_test.py index 127c9ba..6b08463 100644 --- a/test/rest_test.py +++ b/test/rest_test.py @@ -32,12 +32,14 @@ async def test_restresponse_init(): mock_resp = MagicMock() mock_resp.status = 200 mock_resp.reason = "OK" + resp_data = b'{"test":"data"}' rest_resp = RESTResponse(mock_resp, resp_data) + assert rest_resp.status == 200 assert rest_resp.reason == "OK" assert rest_resp.data == resp_data - assert rest_resp.aiohttp_response == mock_resp + assert rest_resp.response == mock_resp def test_restresponse_getheaders(): diff --git a/test/sync/rest_test.py b/test/sync/rest_test.py index cba753d..1ab058f 100644 --- a/test/sync/rest_test.py +++ b/test/sync/rest_test.py @@ -31,13 +31,14 @@ def test_restresponse_init(): mock_resp = MagicMock() mock_resp.status = 200 mock_resp.reason = "OK" - resp_data = b'{"test":"data"}' + resp_data = b'{"test":"data"}' rest_resp = RESTResponse(mock_resp, resp_data) + assert rest_resp.status == 200 assert rest_resp.reason == "OK" assert rest_resp.data == resp_data - assert rest_resp.urllib3_response == mock_resp + assert rest_resp.response == mock_resp def test_restresponse_getheaders(): diff --git a/test/telemetry/utilities_test.py b/test/telemetry/utilities_test.py deleted file mode 100644 index 08387a8..0000000 --- a/test/telemetry/utilities_test.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -Python SDK for OpenFGA - -API version: 1.x -Website: https://openfga.dev -Documentation: https://openfga.dev/docs -Support: https://openfga.dev/community -License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE) - -NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. -""" - -from mock import MagicMock - -from openfga_sdk.telemetry.utilities import doesInstanceHaveCallable - - -def test_instance_has_callable(): - mock_instance = MagicMock(spec_set=["some_callable", "some_attribute"]) - mock_instance.some_callable = lambda: "I am callable" - - assert doesInstanceHaveCallable(mock_instance, "some_callable") - - assert not doesInstanceHaveCallable(mock_instance, "missing_callable") - - mock_instance.some_attribute = "not callable" - assert not doesInstanceHaveCallable(mock_instance, "some_attribute")