1616# under the License. 
1717
1818import  sys 
19+ import  os 
20+ import  ssl 
1921
2022sys .path .append (".." )
2123
2224from  gremlin_python .process .anonymous_traversal  import  traversal 
2325from  gremlin_python .process .strategies  import  * 
2426from  gremlin_python .driver .driver_remote_connection  import  DriverRemoteConnection 
2527from  gremlin_python .driver .serializer  import  GraphBinarySerializersV1 
28+ from  gremlin_python .driver .aiohttp .transport  import  AiohttpTransport 
2629
2730
2831def  main ():
@@ -40,7 +43,8 @@ def with_remote():
4043    # 
4144    # which starts it in "console" mode with an empty in-memory TinkerGraph ready to go bound to a 
4245    # variable named "g" as referenced in the following line. 
43-     rc  =  DriverRemoteConnection ('ws://localhost:8182/gremlin' , 'g' )
46+     server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45940 )
47+     rc  =  DriverRemoteConnection (server_url , 'g' )
4448    g  =  traversal ().with_remote (rc )
4549
4650    # drop existing vertices 
@@ -57,32 +61,57 @@ def with_remote():
5761
5862# connecting with plain text authentication 
5963def  with_auth ():
60-     rc  =  DriverRemoteConnection ('ws://localhost:8182/gremlin' , 'g' , username = 'stephen' , password = 'password' )
64+     server_url  =  os .getenv ('GREMLIN_SERVER_BASIC_AUTH_URL' , 'ws://localhost:8182/gremlin' ).format (45941 )
65+     # turn off certificate verification for testing purposes only 
66+     ssl_opts  =  ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
67+     ssl_opts .check_hostname  =  False 
68+     ssl_opts .verify_mode  =  ssl .CERT_NONE 
69+     rc  =  DriverRemoteConnection (server_url , 'g' , username = 'stephen' , password = 'password' ,
70+                                 transport_factory = lambda : AiohttpTransport (ssl_options = ssl_opts ))
6171    g  =  traversal ().with_remote (rc )
6272
73+     # drop existing vertices 
74+     g .V ().drop ().iterate ()
75+ 
6376    v  =  g .add_v ().iterate ()
6477    count  =  g .V ().count ().next ()
6578    print ("Vertex count: "  +  str (count ))
6679
80+     # clean added data 
81+     g .V ().drop ().iterate ()
6782    rc .close ()
6883
6984
7085# connecting with Kerberos SASL authentication 
7186def  with_kerberos ():
72-     rc  =  DriverRemoteConnection (
'ws://localhost:8182/gremlin' , 
'g' , 
kerberized_service = '[email protected] ' )
 73-     g  =  traversal ().with_remote (rc )
87+     server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45942 )
88+     kerberos_hostname  =  os .getenv ('KRB_HOSTNAME' , 'gremlin-server-test' )
89+     kerberized_service  =  f'test-service@{ kerberos_hostname }  
90+     
91+     try :
92+         rc  =  DriverRemoteConnection (server_url , 'g' , kerberized_service = kerberized_service )
93+         g  =  traversal ().with_remote (rc )
7494
75-     v  =  g .add_v ().iterate ()
76-     count  =  g .V ().count ().next ()
77-     print ("Vertex count: "  +  str (count ))
95+         # drop existing vertices 
96+         g .V ().drop ().iterate ()
7897
79-     rc .close ()
98+         v  =  g .add_v ().iterate ()
99+         count  =  g .V ().count ().next ()
100+         print ("Vertex count: "  +  str (count ))
101+ 
102+         # clean added data 
103+         g .V ().drop ().iterate ()
104+         rc .close ()
105+     except  Exception  as  e :
106+         print (f"Kerberos authentication failed (expected in test environment): { e }  )
107+         # This is expected to fail in CI without proper Kerberos setup 
80108
81109
82110# connecting with customized configurations 
83111def  with_configs ():
112+     server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45940 )
84113    rc  =  DriverRemoteConnection (
85-         'ws://localhost:8182/gremlin' , 'g' ,
114+         server_url , 'g' ,
86115        username = "" , password = "" , kerberized_service = '' ,
87116        message_serializer = GraphBinarySerializersV1 (), graphson_reader = None ,
88117        graphson_writer = None , headers = None , session = None ,
@@ -94,6 +123,9 @@ def with_configs():
94123    count  =  g .V ().count ().next ()
95124    print ("Vertex count: "  +  str (count ))
96125
126+     # clean added data 
127+     g .V ().drop ().iterate ()
128+ 
97129    rc .close ()
98130
99131
0 commit comments