From 847a853e988194cfc01b98c859fda1f0422ae177 Mon Sep 17 00:00:00 2001 From: Ujjwal Nasra <125353741+unasra@users.noreply.github.com> Date: Wed, 20 Nov 2024 00:34:49 +0530 Subject: [PATCH] added headers to client --- src/bloxone_client/api_client.py | 22 +++++++++++++++++--- src/bloxone_client/api_client_test.py | 4 ---- src/bloxone_client/configuration.py | 30 --------------------------- 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/bloxone_client/api_client.py b/src/bloxone_client/api_client.py index c092510..f9e482b 100644 --- a/src/bloxone_client/api_client.py +++ b/src/bloxone_client/api_client.py @@ -25,6 +25,12 @@ RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]] +header_client = "x-infoblox-client" +header_sdk = "x-infoblox-sdk" +sdk_identifier = "python-sdk" + +VERSION = 0.1 + class ApiClient: """Generic API client for OpenAPI client library builds. @@ -60,9 +66,9 @@ def __init__( self.configuration = configuration self.rest_client = RESTClientObject(configuration) - self.default_headers = configuration.default_headers + self.default_headers = {} # Set default User-Agent. - self.user_agent = 'OpenAPI-Generator/0.1.0/python' + self.user_agent = f"bloxone-{sdk_identifier}/{VERSION}" self.client_side_validation = configuration.client_side_validation def __enter__(self): @@ -184,7 +190,17 @@ def param_serialize(self, # header parameters header_params = header_params or {} - header_params.update(self.default_headers) + headers = { + header_client: self.configuration.client_name, + header_sdk: sdk_identifier, + 'Authorization': 'f"Token {self.configuration.api_key}"', + "Content-Type": "application/json", + "Accept": "application/json", + } + #header_params = {**headers, **header_params, **self.default_headers} + headers.update(header_params) + headers.update(self.default_headers) + header_params = headers if header_params: header_params = self.sanitize_for_serialization(header_params) header_params = dict( diff --git a/src/bloxone_client/api_client_test.py b/src/bloxone_client/api_client_test.py index ef8aa79..3d72701 100644 --- a/src/bloxone_client/api_client_test.py +++ b/src/bloxone_client/api_client_test.py @@ -17,10 +17,6 @@ def test_default_client(self): 'https://csp.infoblox.com') self.assertEqual(self.api_client.configuration.client_name, 'bloxone-python-client') - self.assertEqual(self.api_client.configuration.default_headers['Accept'],'application/json') - self.assertEqual(self.api_client.configuration.default_headers['Content-Type'],'application/json') - self.assertRegex(self.api_client.configuration.default_headers['Authorization'],'Token \w*',"Invalid Authorization header") - def test_path_param_value_with_resource_id_type(self): result = self.api_client.path_param_value('id', 'app/type/id', diff --git a/src/bloxone_client/configuration.py b/src/bloxone_client/configuration.py index 1da664c..f8408c0 100644 --- a/src/bloxone_client/configuration.py +++ b/src/bloxone_client/configuration.py @@ -14,10 +14,6 @@ 'maxLength', 'minLength', 'pattern', 'maxItems', 'minItems' } -header_client = "x-infoblox-client" -header_sdk = "x-infoblox-sdk" -sdk_identifier = "python-sdk" - class Configuration: """This class contains various settings of the API client. @@ -150,16 +146,6 @@ def __init__( """date format """ - self.default_headers = { - header_client: self.client_name, - header_sdk: sdk_identifier, - 'Authorization': 'f"Token {self.api_key}"', - "Content-Type": "application/json", - "Accept": "application/json", - } - """Default headers - """ - self.default_tags = {} """Default tags """ @@ -348,22 +334,6 @@ def client_name(self, value): """ self.__client_name = value - @property - def default_headers(self): - """Get the default headers. - - :return: The default headers. - """ - return self.__default_headers - - @default_headers.setter - def default_headers(self, value): - """Set the default headers. - - :param value: The default headers. - """ - self.__default_headers = value - @property def default_tags(self): """Get the default tags.