Fabian Deutsch has uploaded a new change for review. Change subject: Add console.size, and shorten the password message on a small term ......................................................................
Add console.size, and shorten the password message on a small term If we don't have enough rows, keep the message shorter, but still warn that it's a weak password. Also add a convenience function to check the rows/columns of the terminal in case it's useful anywhere else. Change-Id: Ifa580235f545e41dd25236b5dca2e6310b68ccca Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1214611 Signed-off-by: Ryan Barry <[email protected]> --- M src/ovirt/node/utils/console.py M src/ovirt/node/utils/security.py 2 files changed, 30 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/28/49028/1 diff --git a/src/ovirt/node/utils/console.py b/src/ovirt/node/utils/console.py old mode 100644 new mode 100755 index 672571b..3fdb636 --- a/src/ovirt/node/utils/console.py +++ b/src/ovirt/node/utils/console.py @@ -20,6 +20,7 @@ # also available at http://www.gnu.org/copyleft/gpl.html. from ovirt.node import base from ovirt.node.utils import Transaction, process +from collections import namedtuple import StringIO import sys import os @@ -69,6 +70,25 @@ process.call(["reset"]) +def isatty(): + """Check whether or not it's an actual terminal, so unit tests go through + jenkins ok""" + + return sys.stdin.isatty() and sys.stdout.isatty() + + +def size(): + """Returns the size of the console as a tuple + """ + + size = namedtuple("consolesize", ["rows", "columns"]) + + rows, cols = ([int(x) for x in process.check_output(['stty', + 'size']).split()]) + + return size(rows, cols) + + def writeln(txts): """Write something to stdout A wrapper if we want to do this differently in future diff --git a/src/ovirt/node/utils/security.py b/src/ovirt/node/utils/security.py index 1a22bc1..23a2cf8 100644 --- a/src/ovirt/node/utils/security.py +++ b/src/ovirt/node/utils/security.py @@ -19,7 +19,7 @@ # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. from ovirt.node import base, valid, utils -from ovirt.node.utils import system +from ovirt.node.utils import console, system from ovirt.node.utils.fs import File import PAM as _PAM # @UnresolvedImport import cracklib @@ -84,12 +84,15 @@ try: cracklib.FascistCheck(password) except ValueError as e: - message = "You have provided a weak password! " - message += "Strong passwords contain a mix of uppercase, " - message += "lowercase, numeric and punctuation characters. " - message += "They are six or more characters long and " - message += "do not contain dictionary words. " - message += "Reason: %s" % e + console_size = console.size() if console.isatty() else None + message = "You have provided a weak password!" + + if console_size and console_size.rows > 24: + message += "Strong passwords contain a mix of uppercase, " + message += "lowercase, numeric and punctuation characters. " + message += "They are six or more characters long and " + message += "do not contain dictionary words. " + message += "Reason: %s" % e return message -- To view, visit https://gerrit.ovirt.org/49028 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifa580235f545e41dd25236b5dca2e6310b68ccca Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: ovirt-3.6 Gerrit-Owner: Fabian Deutsch <[email protected]> Gerrit-Reviewer: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
