Skip to content

Commit

Permalink
Merge pull request #49 from melexis/ask_username_and_pwd
Browse files Browse the repository at this point in the history
Ask for username and/or password if undefined as env variable
  • Loading branch information
Letme committed Aug 29, 2019
2 parents d9a133a + d58682b commit 8bfa85e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 0 additions & 2 deletions example/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
Welcome to Sphinx Coverity extension example's documentation!
=============================================================

Contents:

.. toctree::
:maxdepth: 1
:glob:
Expand Down
24 changes: 23 additions & 1 deletion mlx/coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
See README.rst for more details.
'''
from __future__ import print_function
from getpass import getpass
from sys import version_info

import pkg_resources

Expand Down Expand Up @@ -54,6 +56,7 @@ def initialize_environment(self, app):

# Login to Coverity and obtain stream information
try:
self.input_credentials(app.config.coverity_credentials)
report_info(env, 'Login to Coverity server... ', True)
coverity_conf_service = CoverityConfigurationService(app.config.coverity_credentials['transport'],
app.config.coverity_credentials['hostname'],
Expand All @@ -77,7 +80,10 @@ def initialize_environment(self, app):
self.coverity_service.login(app.config.coverity_credentials['username'],
app.config.coverity_credentials['password'])
except (URLError, HTTPError, Exception, ValueError) as error_info: # pylint: disable=broad-except
self.coverity_login_error_msg = error_info
if isinstance(error_info, EOFError):
self.coverity_login_error_msg = "Coverity credentials are not configured."
else:
self.coverity_login_error_msg = str(error_info)
report_info(env, 'failed with: %s' % error_info)
self.coverity_login_error = True

Expand Down Expand Up @@ -113,6 +119,22 @@ def process_coverity_nodes(self, app, doctree, fromdocname):

# -----------------------------------------------------------------------------
# Helper functions of event handlers
@staticmethod
def input_credentials(config_credentials):
""" Ask user to input username and/or password if they haven't been configured yet.
Args:
config_credentials (dict): Dictionary to store the user's credentials.
"""
if not config_credentials['username']:
if version_info.major < 3:
get_input = raw_input # noqa, pylint: disable=undefined-variable
else:
get_input = input
config_credentials['username'] = get_input("Coverity username: ")
if not config_credentials['password']:
config_credentials['password'] = getpass("Coverity password: ")

def get_filtered_defects(self, node, env):
""" Fetch defects from suds using filters stored in the given CoverityDefect object.
Expand Down

0 comments on commit 8bfa85e

Please sign in to comment.