Skip to content

Commit 87ea660

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Make python fail properly when invalid key is passed (#350)
* Raise error when auth token is None * Regenerate client from commit 6bab119 of spec repo * Always set a key value Co-authored-by: Thomas Hervé <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent fb2de2b commit 87ea660

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.4.1.dev6",
7-
"regenerated": "2021-03-30 07:00:01.825212",
8-
"spec_repo_commit": "55a2c8a"
7+
"regenerated": "2021-03-30 13:18:25.700382",
8+
"spec_repo_commit": "6bab119"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev6",
12-
"regenerated": "2021-03-30 07:00:44.784406",
13-
"spec_repo_commit": "55a2c8a"
12+
"regenerated": "2021-03-30 13:19:05.062981",
13+
"spec_repo_commit": "6bab119"
1414
}
1515
}
1616
}

.generator/templates/api_client.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ class ApiClient(object):
623623
headers['Cookie'] = auth_setting['value']
624624
elif auth_setting['in'] == 'header':
625625
if auth_setting['type'] != 'http-signature':
626+
if auth_setting["value"] is None:
627+
raise ApiValueError("Invalid authentication token for {}".format(auth_setting["key"]))
626628
headers[auth_setting['key']] = auth_setting['value']
627629
{{#hasHttpSignatureMethods}}
628630
else:

src/datadog_api_client/v1/api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ def update_params_for_auth(self, headers, querys, auth_settings, resource_path,
622622
headers["Cookie"] = auth_setting["value"]
623623
elif auth_setting["in"] == "header":
624624
if auth_setting["type"] != "http-signature":
625+
if auth_setting["value"] is None:
626+
raise ApiValueError("Invalid authentication token for {}".format(auth_setting["key"]))
625627
headers[auth_setting["key"]] = auth_setting["value"]
626628
elif auth_setting["in"] == "query":
627629
querys.append((auth_setting["key"], auth_setting["value"]))

src/datadog_api_client/v2/api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ def update_params_for_auth(self, headers, querys, auth_settings, resource_path,
622622
headers["Cookie"] = auth_setting["value"]
623623
elif auth_setting["in"] == "header":
624624
if auth_setting["type"] != "http-signature":
625+
if auth_setting["value"] is None:
626+
raise ApiValueError("Invalid authentication token for {}".format(auth_setting["key"]))
625627
headers[auth_setting["key"]] = auth_setting["value"]
626628
elif auth_setting["in"] == "query":
627629
querys.append((auth_setting["key"], auth_setting["value"]))

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ def freezer(default_cassette_name, record_mode, vcr):
276276
@given('a valid "apiKeyAuth" key in the system')
277277
def a_valid_api_key(configuration):
278278
"""a valid API key."""
279-
configuration.api_key["apiKeyAuth"] = os.getenv("DD_TEST_CLIENT_API_KEY", "")
279+
configuration.api_key["apiKeyAuth"] = os.getenv("DD_TEST_CLIENT_API_KEY", "fake")
280280

281281

282282
@given('a valid "appKeyAuth" key in the system')
283283
def a_valid_application_key(configuration):
284284
"""a valid Application key."""
285-
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "")
285+
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "fake")
286286

287287

288288
@pytest.fixture
@@ -388,8 +388,8 @@ def wrapper(context, undo):
388388

389389
# make sure we have a fresh instance of API client and configuration
390390
configuration = build_configuration(importlib.import_module(package_name))
391-
configuration.api_key["apiKeyAuth"] = os.getenv("DD_TEST_CLIENT_API_KEY", "")
392-
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "")
391+
configuration.api_key["apiKeyAuth"] = os.getenv("DD_TEST_CLIENT_API_KEY", "fake")
392+
configuration.api_key["appKeyAuth"] = os.getenv("DD_TEST_CLIENT_APP_KEY", "fake")
393393

394394
# enable unstable operation
395395
configuration.unstable_operations[operation_name] = True

0 commit comments

Comments
 (0)