Fix client init to work with URL and (host,port)
[osm/osmclient.git] / osmclient / sol005 / client.py
index 70d5c13..a106c49 100644 (file)
@@ -48,7 +48,7 @@ class Client(object):
     def __init__(
         self,
         host=None,
-        so_port=9999,
+        so_port=443,
         user="admin",
         password="admin",
         project="admin",
@@ -63,17 +63,17 @@ class Client(object):
         self._auth_endpoint = "/admin/v1/tokens"
         self._headers = {}
         self._token = None
-        if len(host.split(":")) > 1:
-            # backwards compatible, port provided as part of host
-            self._host = host.split(":")[0]
-            self._so_port = host.split(":")[1]
+        self._url = None
+        if host.startswith("http://") or host.startswith("https://"):
+            self._url = host
         else:
-            self._host = host
-            self._so_port = so_port
-
-        self._http_client = http.Http(
-            "https://{}:{}/osm".format(self._host, self._so_port), **kwargs
-        )
+            host_fields = host.split(":")
+            if len(host_fields) > 1:
+                # backwards compatible, port provided as part of host
+                host = host_fields[0]
+                so_port = host_fields[1]
+            self._url = "https://{}:{}/osm".format(host, so_port)
+        self._http_client = http.Http(self._url, **kwargs)
         self._headers["Accept"] = "application/json"
         self._headers["Content-Type"] = "application/yaml"
         self._http_client.set_http_header(self._headers)
@@ -103,7 +103,7 @@ class Client(object):
         self.utils = utils.Utils(http_client, **kwargs)
         """
 
-    def get_token(self, pwd_change=None):
+    def get_token(self, pwd_change=False):
         self._logger.debug("")
         if self._token is None:
             postfields_dict = {