diff --git a/example/ScanVertexEdgeExample.py b/example/ScanVertexEdgeExample.py index 2366169c..ec2cf388 100644 --- a/example/ScanVertexEdgeExample.py +++ b/example/ScanVertexEdgeExample.py @@ -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): @@ -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) """ @@ -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) diff --git a/nebula3/sclient/GraphStorageClient.py b/nebula3/sclient/GraphStorageClient.py index dbf6b888..c1e73c4a 100644 --- a/nebula3/sclient/GraphStorageClient.py +++ b/nebula3/sclient/GraphStorageClient.py @@ -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 @@ -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 @@ -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 return ScanResult( self, req=req, @@ -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, diff --git a/nebula3/storage/ttypes.py b/nebula3/storage/ttypes.py index 331d3205..9dd5a5cb 100644 --- a/nebula3/storage/ttypes.py +++ b/nebula3/storage/ttypes.py @@ -5316,6 +5316,9 @@ class ScanVertexRequest: - only_latest_version - enable_read_from_follower - common + - username + - password + - need_authenticate """ thrift_spec = None @@ -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: @@ -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() @@ -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): @@ -5548,6 +5583,9 @@ class ScanEdgeRequest: - only_latest_version - enable_read_from_follower - common + - username + - password + - need_authenticate """ thrift_spec = None @@ -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() @@ -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() @@ -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):