Skip to content

Commit ff78d9a

Browse files
Merge pull request #67 from vgupta-mickey/feature-OBJREQ-524-allow-X-EMC-Header-to-add
Allow X-EMC-Override header to add into API calls.
2 parents 37685e9 + b55730d commit ff78d9a

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

README.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ arguments:
7070
+-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7171
| ``cache_token`` | No | True | Whether to cache the token, by default this is true you should only switch this to false when you want to directly fetch a token for a user |
7272
+-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
73-
73+
| ``override_header`` | No | None | Add X-EMC-Override header with the header value in API request only if it is not None
74+
|
75+
+-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7476
This is how you can instantiate the ``Client`` class and use the library.
7577

7678
.. code-block:: python
@@ -120,6 +122,20 @@ to obtain a new token on the next call. To do so, you can remove the cached toke
120122
121123
client.remove_cached_token()
122124
125+
Add X-EMC-Override: "true" header
126+
~~~~~~~~~~~~~~
127+
You can pass override_header to the client which means the user wants to add custom
128+
X-EMC-Override header into API request
129+
130+
.. code-block:: python
131+
132+
client = Client('3',
133+
username='someone',
134+
password='password',
135+
token_endpoint='https://192.168.1.146:4443/login',
136+
ecs_endpoint='https://192.168.1.146:4443',
137+
override_header='true')
138+
123139
124140
Supported endpoints
125141
-------------------

ecsclient/baseclient.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Client(object):
2323
def __init__(self, username=None, password=None, token=None,
2424
ecs_endpoint=None, token_endpoint=None, verify_ssl=False,
2525
token_path='/tmp/ecsclient.tkn',
26-
request_timeout=15.0, cache_token=True):
26+
request_timeout=15.0, cache_token=True, override_header=None):
2727
"""
2828
Creates the ECSClient class that the client will directly work with
2929
@@ -39,6 +39,7 @@ def __init__(self, username=None, password=None, token=None,
3939
:param cache_token: Whether to cache the token, by default this is true
4040
you should only switch this to false when you want to directly fetch
4141
a token for a user
42+
:param override_header: X-EMC-Override header value into API calls
4243
"""
4344
if not ecs_endpoint:
4445
raise ECSClientException("Missing 'ecs_endpoint'")
@@ -53,6 +54,7 @@ def __init__(self, username=None, password=None, token=None,
5354
if not (token or os.path.isfile(token_path)):
5455
raise ECSClientException("'token_endpoint' not provided and missing 'token'|'token_path'")
5556

57+
self.override_header = override_header
5658
self.username = username
5759
self.password = password
5860
self.token = token
@@ -104,9 +106,12 @@ def remove_cached_token(self):
104106

105107
def _fetch_headers(self):
106108
token = self.token if self.token else self._token_request.get_token()
107-
return {'Accept': 'application/json',
108-
'Content-Type': 'application/json',
109-
'x-sds-auth-token': token}
109+
headers = {'Accept': 'application/json',
110+
'Content-Type': 'application/json',
111+
'x-sds-auth-token': token}
112+
if self.override_header != None:
113+
headers['X-EMC-Override'] = self.override_header
114+
return headers
110115

111116
def _construct_url(self, path):
112117
url = '{0}/{1}'.format(self.ecs_endpoint, path)

0 commit comments

Comments
 (0)