Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support auth for scan #321

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions example/ScanVertexEdgeExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def scan_person_vertex(graph_storage_client):
print("======== Scan vertexes in ScanSpace ======")
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)
if result is not None:
for vertex_data in result:
print(vertex_data)


def scan_person_edge(graph_storage_client):
Expand All @@ -70,8 +71,9 @@ def scan_person_edge(graph_storage_client):
print("======== Scan edges in ScanSpace ======")
while resp.has_next():
result = resp.next()
for edge_data in result:
print(edge_data)
if result is not None:
for edge_data in result:
print(edge_data)


"""
Expand Down Expand Up @@ -129,6 +131,7 @@ def scan_person_edge(graph_storage_client):
[("172.28.1.1", 9559), ("172.28.1.2", 9559), ("172.28.1.3", 9559)], 50000
)
graph_storage_client = GraphStorageClient(meta_cache)
graph_storage_client.set_user_passwd("root", "nebula")
prepare_data()
scan_person_vertex(graph_storage_client)
scan_person_edge(graph_storage_client)
Expand Down
15 changes: 15 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,13 @@ def __init__(self, meta_cache, storage_addrs=None, time_out=60000):
self._connections = []
self._create_connection()

def set_user_passwd(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 +234,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hard code true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need_authenticate is useful for storaged to distinguish the request source is graphd or clients. if the request source is clients, it will config true, and if the request source is graphd, it does not need to auth.

return ScanResult(
self,
req=req,
Expand Down Expand Up @@ -368,6 +380,9 @@ def _scan_edge(
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
77 changes: 77 additions & 0 deletions nebula3/storage/ttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5316,6 +5316,9 @@ class ScanVertexRequest:
- only_latest_version
- enable_read_from_follower
- common
- username
- password
- need_authenticate
"""

thrift_spec = None
Expand Down Expand Up @@ -5413,6 +5416,14 @@ def read(self, iprot):
if ftype == TType.STRUCT:
self.common = RequestCommon()
self.common.read(iprot)
elif fid == 12:
if ftype == TType.STRING:
self.password = iprot.readString()
else:
iprot.skip(ftype)
elif fid == 13:
if ftype == TType.BOOL:
self.need_authenticate = iprot.readBool()
else:
iprot.skip(ftype)
else:
Expand Down Expand Up @@ -5475,6 +5486,18 @@ def write(self, oprot):
oprot.writeFieldBegin('common', TType.STRUCT, 10)
self.common.write(oprot)
oprot.writeFieldEnd()
if self.username != None:
oprot.writeFieldBegin('username', TType.STRING, 11)
oprot.writeString(self.username)
oprot.writeFieldEnd()
if self.password != None:
oprot.writeFieldBegin('password', TType.STRING, 12)
oprot.writeString(self.password)
oprot.writeFieldEnd()
if self.need_authenticate != None:
oprot.writeFieldBegin('need_authenticate', TType.BOOL, 13)
oprot.writeBool(self.need_authenticate)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()

Expand Down Expand Up @@ -5521,6 +5544,18 @@ def __repr__(self):
value = pprint.pformat(self.common, indent=0)
value = padding.join(value.splitlines(True))
L.append(' common=%s' % (value))
if self.username is not None:
value = pprint.pformat(self.username, indent=0)
value = padding.join(value.splitlines(True))
L.append(' username=%s' % (value))
if self.password is not None:
value = pprint.pformat(self.password, indent=0)
value = padding.join(value.splitlines(True))
L.append(' password=%s' % (value))
if self.need_authenticate is not None:
value = pprint.pformat(self.need_authenticate, indent=0)
value = padding.join(value.splitlines(True))
L.append(' need_authenticate=%s' % (value))
return "%s(%s)" % (self.__class__.__name__, "\n" + ",\n".join(L) if L else '')

def __eq__(self, other):
Expand Down Expand Up @@ -5548,6 +5583,9 @@ class ScanEdgeRequest:
- only_latest_version
- enable_read_from_follower
- common
- username
- password
- need_authenticate
"""

thrift_spec = None
Expand Down Expand Up @@ -5647,6 +5685,21 @@ def read(self, iprot):
self.common.read(iprot)
else:
iprot.skip(ftype)
elif fid == 11:
if ftype == TType.STRING:
self.username = iprot.readString()
else:
iprot.skip(ftype)
elif fid == 12:
if ftype == TType.STRING:
self.password = iprot.readString()
else:
iprot.skip(ftype)
elif fid == 13:
if ftype == TType.BOOL:
self.need_authenticate = iprot.readBool()
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
Expand Down Expand Up @@ -5707,6 +5760,18 @@ def write(self, oprot):
oprot.writeFieldBegin('common', TType.STRUCT, 10)
self.common.write(oprot)
oprot.writeFieldEnd()
if self.username != None:
oprot.writeFieldBegin('username', TType.STRING, 11)
oprot.writeString(self.username)
oprot.writeFieldEnd()
if self.password != None:
oprot.writeFieldBegin('password', TType.STRING, 12)
oprot.writeString(self.password)
oprot.writeFieldEnd()
if self.need_authenticate != None:
oprot.writeFieldBegin('need_authenticate', TType.BOOL, 13)
oprot.writeBool(self.need_authenticate)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()

Expand Down Expand Up @@ -5753,6 +5818,18 @@ def __repr__(self):
value = pprint.pformat(self.common, indent=0)
value = padding.join(value.splitlines(True))
L.append(' common=%s' % (value))
if self.username is not None:
value = pprint.pformat(self.username, indent=0)
value = padding.join(value.splitlines(True))
L.append(' username=%s' % (value))
if self.password is not None:
value = pprint.pformat(self.password, indent=0)
value = padding.join(value.splitlines(True))
L.append(' password=%s' % (value))
if self.need_authenticate is not None:
value = pprint.pformat(self.need_authenticate, indent=0)
value = padding.join(value.splitlines(True))
L.append(' need_authenticate=%s' % (value))
return "%s(%s)" % (self.__class__.__name__, "\n" + ",\n".join(L) if L else '')

def __eq__(self, other):
Expand Down
Loading