Skip to content

Commit

Permalink
added headers to client
Browse files Browse the repository at this point in the history
  • Loading branch information
unasra committed Nov 19, 2024
1 parent 0083826 commit 847a853
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
22 changes: 19 additions & 3 deletions src/bloxone_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 0 additions & 4 deletions src/bloxone_client/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
30 changes: 0 additions & 30 deletions src/bloxone_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 847a853

Please sign in to comment.