Skip to content

Commit

Permalink
support auth for scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 committed Mar 4, 2024
1 parent 7d77354 commit 0084e4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions nebula3/sclient/GraphStorageClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GraphStorageClient(object):
DEFAULT_START_TIME = 0
DEFAULT_END_TIME = sys.maxsize
DEFAULT_LIMIT = 1000
user = ""
passwd = ""

def __init__(self, meta_cache, storage_addrs=None, time_out=60000):
self._meta_cache = meta_cache
Expand All @@ -42,6 +44,15 @@ def __init__(self, meta_cache, storage_addrs=None, time_out=60000):
self._connections = []
self._create_connection()

def set_userPasswd(self, user, passwd):
"""set user and password for scan. only useful for enterprise
:return:
"""
self.user = user
self.passwd = passwd


def get_conns(self):
"""get all connections which connect to storaged, the ScanResult use it
Expand Down Expand Up @@ -225,6 +236,9 @@ def _scan_vertex(
req.filter = where
req.only_latest_version = only_latest_version
req.enable_read_from_follower = enable_read_from_follower
req.username = self.user.encode('utf-8')
req.password = self.passwd.encode('utf-8')
req.need_authenticate = True
return ScanResult(
self,
req=req,
Expand Down Expand Up @@ -368,6 +382,11 @@ def _scan_edge(
req.filter = where
req.only_latest_version = only_latest_version
req.enable_read_from_follower = enable_read_from_follower
if self.user is not "":
req.username = self.user.encode('utf-8')
if self.passwd is not "":
req.password = self.passwd.encode('utf-8')
req.need_authenticate = True
return ScanResult(
self,
req=req,
Expand Down
1 change: 1 addition & 0 deletions tests/test_graph_storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def setup_class(cls):
50000,
)
cls.graph_storage_client = GraphStorageClient(meta_cache)
cls.graph_storage_client.set_userPasswd("root", "nebula")

except Exception:
import traceback
Expand Down

0 comments on commit 0084e4e

Please sign in to comment.