Skip to content

Commit

Permalink
ENG-4971: Extending client object creation to support either a full U…
Browse files Browse the repository at this point in the history
…RL or a tenant
  • Loading branch information
JMkrish committed Mar 27, 2024
1 parent 24f49f6 commit 7bd38d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
15 changes: 1 addition & 14 deletions smsdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ def dict_to_df(data, normalize=True):
class Client(ClientV0):
"""Connection point to the Sight Machine platform to retrieve data"""

session = None
tenant = None
config = None

def __init__(
self, tenant: str, site_domain: str = "sightmachine.io", protocol: str = "https"
):
Expand All @@ -143,16 +139,7 @@ def __init__(
:type site_domain: :class:`string`
"""

self.tenant = tenant

# Handle internal configuration
self.config = {}
self.config["protocol"] = protocol
self.config["site.domain"] = site_domain

# Setup Authenticator
self.auth = Authenticator(self)
self.session = self.auth.session
super().__init__(tenant, site_domain=site_domain, protocol=protocol)

@version_check_decorator
def select_db_schema(self, schema_name):
Expand Down
30 changes: 23 additions & 7 deletions smsdk/client_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class ClientV0(object):
tenant = None
config = None

def __init__(self, tenant, site_domain="sightmachine.io"):
def __init__(
self, tenant: str, site_domain: str = "sightmachine.io", protocol: str = "https"
):
"""
Initialize the client.
Expand All @@ -117,12 +119,26 @@ def __init__(self, tenant, site_domain="sightmachine.io"):
:type site_domain: :class:`string`
"""

self.tenant = tenant

# Handle internal configuration
self.config = {}
self.config["protocol"] = "https"
self.config["site.domain"] = site_domain
if "://" in tenant: # Full URL provided eg. "https://demo.sightmachine.io"
protocol, domain = tenant.split("://")[0], tenant.split("://")[1]
self.tenant = domain.split(".")[0]
self.config = {
"protocol": protocol,
"site.domain": ".".join(domain.split(".")[-2:]),
}
else:
tenant_parts = tenant.split(".")
if (
len(tenant_parts) > 1
): # Tenant with domain provided but missing protocol eg. "demo.sightmachine.io"
self.tenant = tenant_parts[0]
self.config = {
"protocol": protocol,
"site.domain": ".".join(tenant_parts[1:]),
}
else: # Only tenant name provided eg. "demo"
self.tenant = tenant
self.config = {"protocol": protocol, "site.domain": site_domain}

# Setup Authenticator
self.auth = Authenticator(self)
Expand Down

0 comments on commit 7bd38d6

Please sign in to comment.