Michael Pasternak has uploaded a new change for review. Change subject: sdk: throw error when connecting to ssl site using http protocol ......................................................................
sdk: throw error when connecting to ssl site using http protocol Change-Id: I4a486f0b6dd8b2136d4cee911b9cea18b589e74b Signed-off-by: Michael Pasternak <mpast...@redhat.com> --- M src/codegen/entrypoint/entrypoint.py M src/ovirtsdk/api.py M src/ovirtsdk/infrastructure/errors.py 3 files changed, 32 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/04/7904/1 diff --git a/src/codegen/entrypoint/entrypoint.py b/src/codegen/entrypoint/entrypoint.py index 95b6d48..12d0c7d 100644 --- a/src/codegen/entrypoint/entrypoint.py +++ b/src/codegen/entrypoint/entrypoint.py @@ -41,6 +41,8 @@ "############ GENERATED CODE ############\n" + \ "########################################\n\n" + \ "'''Generated at: " + str(datetime.datetime.now()) + "'''\n\n" + \ + "import types\n" + \ + "from ovirtsdk.infrastructure.errors import UnsecuredConnectionAttemptError\n" + \ "from ovirtsdk.infrastructure import contextmanager\n" + \ "from ovirtsdk.infrastructure.connectionspool import ConnectionsPool\n" + \ "from ovirtsdk.infrastructure.proxy import Proxy\n" + \ @@ -179,12 +181,18 @@ # Create the proxy: proxy = Proxy(pool, persistent_auth) + # Get entry point + entry_point = proxy.request(method='GET', + url='/api', + headers={'Filter': filter}) + + # If server returns no response for the root resource, this is sign + # that used http protocol against SSL secured site + if type(entry_point) == types.StringType and entry_point == '': + raise UnsecuredConnectionAttemptError + # Store entry point to the context - contextmanager.add('entry_point', - proxy.request(method='GET', - url='/api', - headers={'Filter': filter}), - Mode.R) + contextmanager.add('entry_point', entry_point, Mode.R) # Store proxy to the context: contextmanager.add('proxy', proxy, Mode.R) diff --git a/src/ovirtsdk/api.py b/src/ovirtsdk/api.py index 34f5a55..30a930c 100644 --- a/src/ovirtsdk/api.py +++ b/src/ovirtsdk/api.py @@ -19,8 +19,10 @@ ############ GENERATED CODE ############ ######################################## -'''Generated at: 2012-08-23 18:08:16.950916''' +'''Generated at: 2012-09-10 16:40:27.979965''' +import types +from ovirtsdk.infrastructure.errors import UnsecuredConnectionAttemptError from ovirtsdk.infrastructure import contextmanager from ovirtsdk.infrastructure.connectionspool import ConnectionsPool from ovirtsdk.infrastructure.proxy import Proxy @@ -79,12 +81,18 @@ # Create the proxy: proxy = Proxy(pool, persistent_auth) + # Get entry point + entry_point = proxy.request(method='GET', + url='/api', + headers={'Filter': filter}) + + # If server returns no response for the root resource, this is sign + # that used http protocol against SSL secured site + if type(entry_point) == types.StringType and entry_point == '': + raise UnsecuredConnectionAttemptError + # Store entry point to the context - contextmanager.add('entry_point', - proxy.request(method='GET', - url='/api', - headers={'Filter': filter}), - Mode.R) + contextmanager.add('entry_point', entry_point, Mode.R) # Store proxy to the context: contextmanager.add('proxy', proxy, Mode.R) diff --git a/src/ovirtsdk/infrastructure/errors.py b/src/ovirtsdk/infrastructure/errors.py index f51c8be..fa08a0c 100644 --- a/src/ovirtsdk/infrastructure/errors.py +++ b/src/ovirtsdk/infrastructure/errors.py @@ -29,6 +29,11 @@ def __init__(self): Exception.__init__(self, '[ERROR]::ca_file (CA certificate) must be specified for SSL connection.') +class UnsecuredConnectionAttemptError(Exception): + def __init__(self): + Exception.__init__(self, "[ERROR]::server returned no response, this may happen if you trying\n" + + "connect to SSL secured site using http protocol.") + class RequestError(Exception): def __init__(self, response): self.detail = None -- To view, visit http://gerrit.ovirt.org/7904 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4a486f0b6dd8b2136d4cee911b9cea18b589e74b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <mpast...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches