Ravi Nori has uploaded a new change for review. Change subject: sdk: unclear error message when logging into cli with bad formatted url ......................................................................
sdk: unclear error message when logging into cli with bad formatted url ovirt-shell -c -d -l localhost -u admin@internal -I throws an unclear error message. Error happens only when connecting to engine with out specifying the http protocol Change-Id: Ib3665d8714258ad8e449638fbf0b86105f813e3e Bug-Url: https://bugzilla.redhat.com/960876 Signed-off-by: Ravi Nori <[email protected]> --- M src/cli/messages.py M src/ovirtcli/command/connect.py 2 files changed, 18 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/21/18621/1 diff --git a/src/cli/messages.py b/src/cli/messages.py index 1ce9a05..55ec281 100644 --- a/src/cli/messages.py +++ b/src/cli/messages.py @@ -50,6 +50,7 @@ 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' + INVALID_URL_SEGMENT = '"%s" is invalid url format. valid format is http[s]://server:port/api.' 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/ovirtcli/command/connect.py b/src/ovirtcli/command/connect.py index 71f693a..6afffd9 100644 --- a/src/ovirtcli/command/connect.py +++ b/src/ovirtcli/command/connect.py @@ -15,6 +15,8 @@ # +import re + from ovirtcli.command.command import OvirtCommand from ovirtsdk.api import API from ovirtcli.settings import OvirtCliSettings @@ -93,6 +95,9 @@ if not password: self.error(Messages.Error.MISSING_CONFIGURATION_VARIABLE % 'password') + if not self.is_valid_url(url): + self.error(Messages.Error.INVALID_URL_SEGMENT % url) + try: self.context.set_connection (API(url=url, username=username, @@ -143,6 +148,18 @@ # a subject for password stealing or DOS attack self.__remove_history_entry() + def is_valid_url(self, url): + regex = re.compile( + r'^(?:http)s?://' # http:// or https:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... + r'localhost|' # localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4 + r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6 + r'(?::\d+)?' # optional port + r'(/api)' # /api + , re.IGNORECASE) + return url is not None and regex.search(url) + def __normalize_typeerror(self, exception): err = str(exception) error = err[1:len(err) - 1] -- To view, visit http://gerrit.ovirt.org/18621 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib3665d8714258ad8e449638fbf0b86105f813e3e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
