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

feat: support TLS for session pool #360

Merged
merged 3 commits into from
Aug 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
pip install pip-tools pytest
- name: Test with pytest
run: |
docker-compose -f docker-compose.yaml up -d
docker compose -f docker-compose.yaml up -d
sleep 20
pytest -s -v -k "not SSL"
working-directory: tests
Expand Down
38 changes: 25 additions & 13 deletions nebula3/gclient/net/SessionPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket

from threading import RLock, Timer
from typing import List
from typing import List, Optional
import time

from nebula3.common.ttypes import ErrorCode
Expand All @@ -23,7 +23,7 @@
from nebula3.gclient.net.Connection import Connection
from nebula3.gclient.net.base import BaseExecutor
from nebula3.logger import logger
from nebula3.Config import SessionPoolConfig
from nebula3.Config import SessionPoolConfig, SSL_config


class SessionPool(BaseExecutor, object):
Expand Down Expand Up @@ -72,7 +72,11 @@ def __init__(self, username, password, space_name, addresses):
def __del__(self):
self.close()

def init(self, configs=None):
def init(
self,
configs: Optional[SessionPoolConfig] = None,
ssl_configs: Optional[SSL_config] = None,
):
"""init the session pool

:param username: the username of the session
Expand All @@ -90,6 +94,7 @@ def init(self, configs=None):
self._configs = configs
else:
self._configs = SessionPoolConfig()
self._ssl_configs = ssl_configs
# check configs
try:
self._check_configs()
Expand Down Expand Up @@ -388,9 +393,6 @@ def _new_session(self):

:return: Session
"""
if self._ssl_configs is not None:
raise RuntimeError("SSL is not supported yet")

self._pos = (self._pos + 1) % len(self._addresses)
next_addr_index = self._pos

Expand All @@ -410,13 +412,23 @@ def _new_session(self):
# connect to the valid service
connection = Connection()
try:
connection.open(
addr[0],
addr[1],
self._configs.timeout,
self._configs.use_http2,
self._configs.http_headers,
)
if self._ssl_configs is None:
connection.open(
addr[0],
addr[1],
self._configs.timeout,
self._configs.use_http2,
self._configs.http_headers,
)
else:
connection.open_SSL(
addr[0],
addr[1],
self._configs.timeout,
self._ssl_configs,
self._configs.use_http2,
self._configs.http_headers,
)
auth_result = connection.authenticate(self._username, self._password)
session = Session(connection, auth_result, self, False)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nebula3-python"
version = "3.8.1"
version = "3.8.2"
description = "Python client for NebulaGraph v3"
authors = [
{name = "vesoft-inc", email = "[email protected]"},
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name="nebula3-python",
version="3.8.1",
version="3.8.2",
license="Apache 2.0",
author="vesoft-inc",
author_email="[email protected]",
Expand Down
Loading