Skip to content

Commit

Permalink
Echo warning for unnecessary params used (DataDog#10053)
Browse files Browse the repository at this point in the history
* echo warning for unnecessary params used

* Format for readability

* Improve readability

* Fix style

* Skip validation on warnings for valid use
  • Loading branch information
ChristineTChen authored Sep 13, 2021
1 parent 634d567 commit 3901cbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_oauth_token(self):
try:
res = self.http.get(
join_url(self._uaa_url, "oauth/token"),
auth=(self._client_id, self._client_secret),
auth=(self._client_id, self._client_secret), # SKIP_HTTP_VALIDATION`
params={"grant_type": "client_credentials"},
)
except RequestException:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
import re

import click

from datadog_checks.dev.tooling.annotations import annotate_error
from datadog_checks.dev.tooling.utils import complete_valid_checks, get_check_files, get_default_config_spec

from ...testing import process_checks_option
from ..console import CONTEXT_SETTINGS, abort, echo_failure, echo_info, echo_success
from ..console import CONTEXT_SETTINGS, abort, echo_failure, echo_info, echo_success, echo_warning

# Integrations that are not fully updated to http wrapper class but is owned partially by a different organization

Expand Down Expand Up @@ -84,7 +85,10 @@ def validate_use_http_wrapper_file(file, check):
with open(file, 'r', encoding='utf-8') as f:
for num, line in enumerate(f):
if ('self.http' in line or 'OpenMetricsBaseCheck' in line) and 'SKIP_HTTP_VALIDATION' not in line:
return True, has_failed
file = f.read()
found_match = re.search(r"auth=|header=", file)

return True, has_failed, found_match

for http_func in REQUEST_LIBRARY_FUNCTIONS:
if http_func in line:
Expand All @@ -97,9 +101,9 @@ def validate_use_http_wrapper_file(file, check):
"Detected use of `{}`, please use the HTTP wrapper instead".format(http_func),
line=num + 1,
)
has_failed = True
return False, True, None

return file_uses_http_wrapper, has_failed
return file_uses_http_wrapper, has_failed, None


def validate_use_http_wrapper(check):
Expand All @@ -112,9 +116,19 @@ def validate_use_http_wrapper(check):
check_uses_http_wrapper = False
for file in get_check_files(check, include_tests=False):
if file.endswith('.py'):
file_uses_http_wrapper, file_uses_request_lib = validate_use_http_wrapper_file(file, check)
file_uses_http_wrapper, file_uses_request_lib, has_arg_warning = validate_use_http_wrapper_file(file, check)
has_failed = has_failed or file_uses_request_lib
check_uses_http_wrapper = check_uses_http_wrapper or file_uses_http_wrapper
if check_uses_http_wrapper and has_arg_warning:
# Check for headers= or auth=
echo_warning(
f"{check}: \n"
f" The HTTP wrapper contains parameter `{has_arg_warning.group().replace('=', '')}`, "
f"this configuration is handled by the wrapper automatically.\n"
f" If this a genuine usage of the parameters, "
f"please inline comment `# SKIP_HTTP_VALIDATION`"
)
pass

if has_failed:
abort()
Expand Down
2 changes: 1 addition & 1 deletion voltdb/datadog_checks/voltdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def request(self, procedure, parameters=None):
parameters = json.dumps(parameters)
params['Parameters'] = parameters

return self._http_get(url, auth=auth, params=params)
return self._http_get(url, auth=auth, params=params) # SKIP_HTTP_VALIDATION


class VoltDBAuth(requests.auth.AuthBase):
Expand Down

0 comments on commit 3901cbc

Please sign in to comment.