Michael Pasternak has uploaded a new change for review. Change subject: cli: certificate file keys are not exposed in .ovirtshellrc #960983 ......................................................................
cli: certificate file keys are not exposed in .ovirtshellrc #960983 Change-Id: I365d72d31602a765c5ce25a5293277d052885350 BugUrl: https://bugzilla.redhat.com/show_bug.cgi?id=960983 Signed-off-by: Michael pasternak <[email protected]> --- M src/cli/context.py M src/cli/messages.py M src/cli/settings.py M src/ovirtcli/command/connect.py M src/ovirtcli/settings.py 5 files changed, 52 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/29/15129/1 diff --git a/src/cli/context.py b/src/cli/context.py index ffe5bd9..7d7733f 100644 --- a/src/cli/context.py +++ b/src/cli/context.py @@ -71,6 +71,7 @@ self._setup_logging() self._load_settings() self.setup_commands() + self.__setup_pager() def _setup_logging(self): """Configure logging.""" @@ -255,6 +256,12 @@ break return command + def __setup_pager(self): + pager = self.settings.get('cli:pager') + if not pager: + pager = platform.get_pager() + self.__pager = pager + def _execute_command(self, parsed): """INTERNAL: execute a command.""" # if parsed[0] == '!': @@ -262,11 +269,10 @@ # return name, args, opts, redirections, pipeline = parsed if self.settings.get('cli:autopage'): - pager = self.settings.get('cli:pager', platform.get_pager()) if pipeline: - pipeline += '| %s' % pager + pipeline += '| %s' % self.__pager else: - pipeline = pager + pipeline = self.__pager command = self._create_command(name, args, opts) self.command = command self._setup_pipeline(pipeline) diff --git a/src/cli/messages.py b/src/cli/messages.py index c0bfce3..3870554 100644 --- a/src/cli/messages.py +++ b/src/cli/messages.py @@ -49,6 +49,7 @@ INVALID_OPTION_SEGMENT = '"%s" is invalid segment at option "--%s".' INVALID_KWARGS_FORMAT = '"%s" is invalid --kwargs argument, valid format is "x=y;z=q;...".' INVALID_KWARGS_CONTENT = '--kwargs constraint cannot be empty.' + INVALID_ARGUMENT_TYPE = 'value used for the \"%s\" is \"%s\", while %s' MISSING_CONFIGURATION_VARIABLE = 'missing configuration variable: %s.' UNSUPPORTED_ATTRIBUTE = 'object construction failure, this could happen if you using unsupported option, please see help for the given command for more details.' class Warning(): diff --git a/src/cli/settings.py b/src/cli/settings.py index 773cf7b..53c58b3 100644 --- a/src/cli/settings.py +++ b/src/cli/settings.py @@ -22,6 +22,8 @@ from fnmatch import fnmatch from ConfigParser import ConfigParser from cli import platform +import types +import sys class enum(object): @@ -85,7 +87,13 @@ for pattern, validator, default in self.settings: if not fnmatch(key, pattern): continue - value = validator(value) + value = self.__normalazie_value(value) + if value: + try: + value = validator(value) + except ValueError: + # delegate type related errors handling to SDK + pass found = True if not found: raise KeyError, 'unknown setting: %s' % key @@ -95,10 +103,17 @@ callback(key, value) super(Settings, self).__setitem__(key, value) + def __normalazie_value(self, value): + """Converts string value to python type """ + if value: + if type(value) == types.StringType and value == 'None': + return None + return value + def get_defaults(self): """Return a dictionary with the default settings.""" return dict(((p, d) for p, t, d in self.settings - if d is not None and '*' not in p)) + if '*' not in p)) def load_config_file(self): """ diff --git a/src/ovirtcli/command/connect.py b/src/ovirtcli/command/connect.py index 9620268..932163c 100644 --- a/src/ovirtcli/command/connect.py +++ b/src/ovirtcli/command/connect.py @@ -127,6 +127,15 @@ self.__cleanContext() self.context._clean_settings() self.error(str(e)) + except TypeError, e: + self.__cleanContext() + option, value, expected = self.__normalize_typeerror(e) + self.error( + Messages.Error.INVALID_ARGUMENT_TYPE % ( + option, + value, + expected) + ) except Exception, e: self.__cleanContext() self.error(str(e)) @@ -135,6 +144,19 @@ # a subject for password stealing or DOS attack self.__remove_history_entry() + def __normalize_typeerror(self, exception): + err = str(exception) + error = err[1:len(err) - 1] + error = error.replace("\"", "") + error = error.replace("'", "") + splitted = error.split(', ') + option_value = splitted[0].split('=') + option = option_value[0].upper() + value = option_value[1] + expected = splitted[1] + + return option, value, expected + def __test_connectivity(self): return self.context.connection.test(throw_exception=True) diff --git a/src/ovirtcli/settings.py b/src/ovirtcli/settings.py index f0ac0dd..ba7a9ed 100644 --- a/src/ovirtcli/settings.py +++ b/src/ovirtcli/settings.py @@ -56,9 +56,9 @@ ('ovirt-shell:insecure', boolean, False), ('ovirt-shell:dont_validate_cert_chain', boolean, False), ('ovirt-shell:filter', boolean, False), - ('ovirt-shell:port', int, -1), - ('ovirt-shell:timeout', int, -1), - ('ovirt-shell:session_timeout', int, -1), + ('ovirt-shell:port', int, None), + ('ovirt-shell:timeout', int, None), + ('ovirt-shell:session_timeout', int, None), ('ovirt-shell:input_format', enum('xml'), 'xml'), ('ovirt-shell:output_format', enum('xml', 'text'), 'text'), ('ovirt-shell:wide', boolean, False), -- To view, visit http://gerrit.ovirt.org/15129 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I365d72d31602a765c5ce25a5293277d052885350 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: cli_3.2 Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
