Do not display InsecurePlatformWarning

The current requests module issues InsecurePlatformWarning on what
seems like every request.  Perform duplicate suppresion on all
warning messages.  Additionally, never display this message to the
user because there is almost nothing the user can do about it,
and annoying them is not going to help.  Log the message once.

Also move the InsecureRequestWarning suppression to use the same
new system.  Log it once if ssl verification is disabled.  Display
the warning if it is not disabled.

Change-Id: Icc84596dbc5f0e36a1af5c56215380b0f405613f
This commit is contained in:
James E. Blair 2015-03-18 08:00:45 -07:00
parent f9bce34e4a
commit a5d049e20b
3 changed files with 44 additions and 3 deletions

View File

@ -36,6 +36,7 @@ from gertty import mywid
from gertty import palette
from gertty import sync
from gertty import search
from gertty import requestsexceptions
from gertty.view import change_list as view_change_list
from gertty.view import project_list as view_project_list
from gertty.view import change as view_change
@ -207,6 +208,7 @@ class App(object):
self.sync_pipe = self.loop.watch_pipe(self.refresh)
self.error_queue = Queue.Queue()
self.error_pipe = self.loop.watch_pipe(self._errorPipeInput)
self.logged_warnings = set()
warnings.showwarning = self._showWarning
@ -469,7 +471,20 @@ class App(object):
def _showWarning(self, message, category, filename, lineno,
file=None, line=None):
# Don't display repeat warnings
if str(message) in self.logged_warnings:
return
m = warnings.formatwarning(message, category, filename, lineno, line)
self.log.warning(m)
self.logged_warnings.add(str(message))
# Log this warning, but never display it to the user; it is
# nearly un-actionable.
if category == requestsexceptions.InsecurePlatformWarning:
return
# Disable InsecureRequestWarning when certificate validation is disabled
if not self.config.verify_ssl:
if category == requestsexceptions.InsecureRequestWarning:
return
self.error_queue.put(('Warning', m))
os.write(self.error_pipe, 'error\n')

View File

@ -0,0 +1,29 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
try:
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
except ImportError:
try:
from urllib3.exceptions import InsecurePlatformWarning
except ImportError:
InsecurePlatformWarning = None
try:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
except ImportError:
try:
from urllib3.exceptions import InsecureRequestWarning
except ImportError:
InsecureRequestWarning = None

View File

@ -887,9 +887,6 @@ class Sync(object):
self.log = logging.getLogger('gertty.sync')
self.queue = MultiQueue([HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY])
self.result_queue = Queue.Queue()
# Disable InsecureRequestWarning when certificate validation is disabled
if not self.app.config.verify_ssl:
requests.packages.urllib3.disable_warnings()
self.session = requests.Session()
if self.app.config.auth_type == 'basic':
authclass = requests.auth.HTTPBasicAuth