Skip to content

Commit

Permalink
GML-1660 add dbversion to set authMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Zhou authored and Lu Zhou committed May 10, 2024
1 parent e3aac00 commit 5537745
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pyTigerGraph/pyTigerGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
tgCloud: bool = False, restppPort: Union[int, str] = "9000",
gsPort: Union[int, str] = "14240", gsqlVersion: str = "", version: str = "",
apiToken: str = "", useCert: bool = None, certPath: str = None, debug: bool = None,
sslPort: Union[int, str] = "443", gcp: bool = False, jwtToken: str = ""):
sslPort: Union[int, str] = "443", gcp: bool = False, jwtToken: str = "", dbVersion: str = ""):
super().__init__(host, graphname, gsqlSecret, username, password, tgCloud, restppPort,
gsPort, gsqlVersion, version, apiToken, useCert, certPath, debug, sslPort, gcp, jwtToken)
gsPort, gsqlVersion, version, apiToken, useCert, certPath, debug, sslPort, gcp, jwtToken, dbVersion)

self.gds = None
self.ai = None
Expand Down
11 changes: 7 additions & 4 deletions pyTigerGraph/pyTigerGraphBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import warnings
from typing import Union
from urllib.parse import urlparse

from distutils.version import StrictVersion
import requests

from pyTigerGraph.pyTigerGraphException import TigerGraphException
Expand All @@ -36,7 +36,7 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
tgCloud: bool = False, restppPort: Union[int, str] = "9000",
gsPort: Union[int, str] = "14240", gsqlVersion: str = "", version: str = "",
apiToken: str = "", useCert: bool = None, certPath: str = None, debug: bool = None,
sslPort: Union[int, str] = "443", gcp: bool = False, jwtToken: str = ""):
sslPort: Union[int, str] = "443", gcp: bool = False, jwtToken: str = "", dbVersion: str = ""):
"""Initiate a connection object.
Args:
Expand Down Expand Up @@ -78,6 +78,8 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
DEPRECATED. Previously used for connecting to databases provisioned on GCP in TigerGraph Cloud.
jwtToken:
The JWT token generated from customer side for authentication
dbVersion:
The TigerGraph database version being connected to.
Raises:
TigerGraphException: In case on invalid URL scheme.
Expand Down Expand Up @@ -126,9 +128,10 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
else:
self.authHeader = {"Authorization": "Basic {0}".format(self.base64_credential)}

# If JWT token is provided, set authMode to "token", and overwrite authMode = "pwd" for GSQL authentication as well
# If JWT token is provided, set authMode to "token", and overwrite authMode = "pwd" for GSQL authentication as well if version is newer than 4.1.0
if jwtToken:
self.authMode = "token"
if dbVersion and StrictVersion(dbVersion) >= StrictVersion("4.1.0"):
self.authMode = "token"
self.jwtToken = jwtToken
self.authHeader = {"Authorization": "Bearer " + self.jwtToken}

Expand Down
4 changes: 4 additions & 0 deletions tests/pyTigerGraphUnitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def make_connection(graphname: str = None):
"sslPort": "443",
"tgCloud": False,
"gcp": False,
"jwtToken": "",
"dbVersion": ""
}

path = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -42,6 +44,8 @@ def make_connection(graphname: str = None):
certPath=server_config["certPath"],
sslPort=server_config["sslPort"],
gcp=server_config["gcp"],
jwtToken=server_config["jwtToken"],
dbVersion=server_config["dbVersion"]
)
if server_config.get("getToken", False):
conn.getToken(conn.createSecret())
Expand Down

0 comments on commit 5537745

Please sign in to comment.