Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo warning for unnecessary params used #10053

Merged
merged 5 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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