Skip to content

Commit dcd18be

Browse files
author
David Bouchare
authored
Fix keys in headers for some endpoints (#468)
* Remove keys in headers for some endpoints * Add tests
1 parent a690ced commit dcd18be

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

datadog/api/api_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ def submit(cls, method, path, api_version=None, body=None, attach_host_name=Fals
105105
if not api_version:
106106
api_version = _api_version
107107

108-
# set api and app keys in params only for some endpoints
108+
# set api and app keys in params only for some endpoints and thus remove keys from headers
109+
# as they cannot be set in both params and headers
109110
if cls._set_api_and_app_keys_in_params(api_version, path):
110111
params['api_key'] = _api_key
112+
del headers['DD-API-KEY']
111113
if _application_key:
112114
params['application_key'] = _application_key
115+
del headers['DD-APPLICATION-KEY']
113116

114117
# Attach host name to body
115118
if attach_host_name and body:

tests/unit/api/test_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def test_request_parameters(self):
148148
self.assertEqual(options['headers']['Content-Type'], 'application/json')
149149
self.assertEqual(options['headers']['DD-API-KEY'], API_KEY)
150150
self.assertEqual(options['headers']['DD-APPLICATION-KEY'], APP_KEY)
151-
151+
assert "api_key" not in options['params']
152+
assert "application_key" not in options['params']
152153

153154
def test_request_parameters_api_keys_in_params(self):
154155
"""
@@ -172,8 +173,8 @@ def test_request_parameters_api_keys_in_params(self):
172173
self.assertEqual(options['headers']['Content-Type'], 'application/json')
173174
self.assertEqual(options['params']['api_key'], API_KEY)
174175
self.assertEqual(options['params']['application_key'], APP_KEY)
175-
176-
176+
assert "DD-API-KEY" not in options['headers']
177+
assert "DD-APPLICATION-KEY" not in options['headers']
177178

178179
def test_initialize_options(self):
179180
"""

0 commit comments

Comments
 (0)