-
Notifications
You must be signed in to change notification settings - Fork 841
Integrate Python driver examples into automated build process (master) #3280
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
Changes from all commits
6058249
55009fe
1f71af8
0968ca0
61c0e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,21 +14,23 @@ | |
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import ssl | ||
| import sys | ||
| import os | ||
|
|
||
| sys.path.append("..") | ||
|
|
||
| from gremlin_python.process.anonymous_traversal import traversal | ||
| from gremlin_python.process.strategies import * | ||
| from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection | ||
| from gremlin_python.driver.serializer import GraphBinarySerializersV1 | ||
| from gremlin_python.driver.aiohttp.transport import AiohttpHTTPTransport | ||
| from gremlin_python.driver.auth import basic | ||
| from gremlin_python.driver.serializer import GraphBinarySerializersV4 | ||
|
|
||
| VERTEX_LABEL = os.getenv('VERTEX_LABEL', 'connection') | ||
|
|
||
| def main(): | ||
| with_remote() | ||
| with_auth() | ||
| with_kerberos() | ||
| with_configs() | ||
|
|
||
|
|
||
|
|
@@ -40,15 +42,14 @@ def with_remote(): | |
| # | ||
| # which starts it in "console" mode with an empty in-memory TinkerGraph ready to go bound to a | ||
| # variable named "g" as referenced in the following line. | ||
| rc = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g') | ||
| # if there is a port placeholder in the env var then we are running with docker so set appropriate port | ||
| server_url = os.getenv('GREMLIN_SERVER_URL', 'http://localhost:8182/gremlin').format(45940) | ||
| rc = DriverRemoteConnection(server_url, 'g') | ||
| g = traversal().with_remote(rc) | ||
|
|
||
| # drop existing vertices | ||
| g.V().drop().iterate() | ||
|
|
||
| # simple query to verify connection | ||
| v = g.add_v().iterate() | ||
| count = g.V().count().next() | ||
| v = g.add_v(VERTEX_LABEL).iterate() | ||
| count = g.V().has_label(VERTEX_LABEL).count().next() | ||
| print("Vertex count: " + str(count)) | ||
|
|
||
| # cleanup | ||
|
|
@@ -57,45 +58,42 @@ def with_remote(): | |
|
|
||
| # connecting with plain text authentication | ||
| def with_auth(): | ||
| rc = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g', username='stephen', password='password') | ||
| # if there is a port placeholder in the env var then we are running with docker so set appropriate port | ||
| server_url = os.getenv('GREMLIN_SERVER_BASIC_AUTH_URL', 'http://localhost:8182/gremlin').format(45941) | ||
|
|
||
| # disable SSL certificate verification for CI environments | ||
| if ':45941' in server_url: | ||
| ssl_opts = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
| ssl_opts.check_hostname = False | ||
| ssl_opts.verify_mode = ssl.CERT_NONE | ||
| rc = DriverRemoteConnection(server_url, 'g', auth=basic('stephen', 'password'), | ||
| transport_factory=lambda: AiohttpHTTPTransport(ssl_options=ssl_opts)) | ||
| else: | ||
| rc = DriverRemoteConnection(server_url, 'g', auth=basic('stephen', 'password')) | ||
|
|
||
| g = traversal().with_remote(rc) | ||
|
|
||
| v = g.add_v().iterate() | ||
| count = g.V().count().next() | ||
| v = g.add_v(VERTEX_LABEL).iterate() | ||
| count = g.V().has_label(VERTEX_LABEL).count().next() | ||
| print("Vertex count: " + str(count)) | ||
|
|
||
| rc.close() | ||
|
|
||
|
|
||
| # connecting with Kerberos SASL authentication | ||
| def with_kerberos(): | ||
| rc = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g', kerberized_service='gremlin@hostname.your.org') | ||
| g = traversal().with_remote(rc) | ||
|
|
||
| v = g.add_v().iterate() | ||
| count = g.V().count().next() | ||
| print("Vertex count: " + str(count)) | ||
|
|
||
| rc.close() | ||
|
|
||
|
|
||
| # connecting with customized configurations | ||
| def with_configs(): | ||
| server_url = os.getenv('GREMLIN_SERVER_URL', 'http://localhost:8182/gremlin').format(45940) | ||
| rc = DriverRemoteConnection( | ||
| 'ws://localhost:8182/gremlin', 'g', | ||
| username="", password="", kerberized_service='', | ||
| message_serializer=GraphBinarySerializersV1(), graphson_reader=None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this example be retained which is demonstrating how the graph binary serializer can be configured?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| graphson_writer=None, headers=None, session=None, | ||
| enable_user_agent_on_connect=True | ||
| server_url, 'g', | ||
| request_serializer=GraphBinarySerializersV4(), | ||
| headers=None, | ||
| ) | ||
| g = traversal().with_remote(rc) | ||
|
|
||
| v = g.add_v().iterate() | ||
| count = g.V().count().next() | ||
| v = g.add_v(VERTEX_LABEL).iterate() | ||
| count = g.V().has_label(VERTEX_LABEL).count().next() | ||
| print("Vertex count: " + str(count)) | ||
|
|
||
| rc.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Uh oh!
There was an error while loading. Please reload this page.