-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from betaboon/feat-basic-connection-string-support
feat: add basic connection-string-support
- Loading branch information
Showing
8 changed files
with
171 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from eventstoredb.client.client import Client | ||
from eventstoredb.client.types import ClientOptions | ||
from eventstoredb.client.options import ClientOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from yarl import URL | ||
|
||
|
||
class MalformedConnectionString(ValueError): | ||
def __init__(self, message: str): | ||
super().__init__(message) | ||
|
||
|
||
@dataclass | ||
class ClientOptions: | ||
host: str | ||
port: int = 2113 | ||
username: str | None = None | ||
password: str | None = None | ||
tls: bool = True | ||
dns_discovery: bool = False | ||
keep_alive_timeout: int = 10000 | ||
keep_alive_interval: int = 10000 | ||
|
||
@classmethod | ||
def from_connection_string(cls, connection_string: str) -> ClientOptions: | ||
url = URL(connection_string) | ||
if not url.host: | ||
raise MalformedConnectionString("'host' is undefined") | ||
|
||
options = ClientOptions(host=url.host) | ||
|
||
if url.scheme == "esdb": | ||
options.dns_discovery = False | ||
elif url.scheme == "esdb+discovery": | ||
options.dns_discovery = True | ||
|
||
if url.port: | ||
options.port = url.port | ||
|
||
options.username = url.user | ||
options.password = url.password | ||
|
||
return options |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
|
||
from eventstoredb import ClientOptions | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"connection_string,client_options", | ||
[ | ||
( | ||
"esdb://host", | ||
ClientOptions( | ||
host="host", | ||
port=2113, | ||
tls=True, | ||
dns_discovery=False, | ||
), | ||
), | ||
( | ||
"esdb://host:1234", | ||
ClientOptions( | ||
host="host", | ||
port=1234, | ||
tls=True, | ||
dns_discovery=False, | ||
), | ||
), | ||
( | ||
"esdb+discovery://host", | ||
ClientOptions( | ||
host="host", | ||
tls=True, | ||
dns_discovery=True, | ||
), | ||
), | ||
( | ||
"esdb://user:pass@host", | ||
ClientOptions( | ||
host="host", | ||
username="user", | ||
password="pass", | ||
), | ||
), | ||
], | ||
) | ||
def test_from_url(connection_string: str, client_options: ClientOptions) -> None: | ||
assert ClientOptions.from_connection_string(connection_string) == client_options |