Skip to content

Commit e6dc67d

Browse files
committed
Merge pull request #69 from ytjohn/version_prefix
adding configurable version_prefix
2 parents 2a4e720 + cc71fa2 commit e6dc67d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Create a client object
4141
client = etcd.Client(port=4002)
4242
client = etcd.Client(host='127.0.0.1', port=4003)
4343
client = etcd.Client(host='127.0.0.1', port=4003, allow_redirect=False) # wont let you run sensitive commands on non-leader machines, default is true
44-
44+
# create a client against https://api.example.com:443/etcd
45+
client = etcd.Client(host='api.example.com', protocol='https', port=443, version_prefix='/etcd')
4546
Write a key
4647
~~~~~~~~~
4748

src/etcd/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
self,
3131
host='127.0.0.1',
3232
port=4001,
33+
version_prefix='/v2',
3334
read_timeout=60,
3435
allow_redirect=True,
3536
protocol='http',
@@ -47,6 +48,8 @@ def __init__(
4748
4849
port (int): Port used to connect to etcd.
4950
51+
version_prefix (str): Url or version prefix in etcd url (default=/v2).
52+
5053
read_timeout (int): max seconds to wait for a read.
5154
5255
allow_redirect (bool): allow the client to connect to other nodes.
@@ -81,7 +84,7 @@ def uri(protocol, host, port):
8184

8285
self._base_uri = uri(self._protocol, self._host, self._port)
8386

84-
self.version_prefix = '/v2'
87+
self.version_prefix = version_prefix
8588

8689
self._read_timeout = read_timeout
8790
self._allow_redirect = allow_redirect

src/etcd/tests/unit/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def test_default_port(self):
1919
client = etcd.Client()
2020
assert client.port == 4001
2121

22+
def test_default_prefix(self):
23+
client = etcd.Client()
24+
assert client.version_prefix == '/v2'
25+
2226
def test_default_protocol(self):
2327
""" default protocol is http"""
2428
client = etcd.Client()
@@ -44,6 +48,10 @@ def test_set_port(self):
4448
client = etcd.Client(port=4002)
4549
assert client.port == 4002
4650

51+
def test_default_prefix(self):
52+
client = etcd.Client(version_prefix='/etcd')
53+
assert client.version_prefix == '/etcd'
54+
4755
def test_set_protocol(self):
4856
""" can change protocol """
4957
client = etcd.Client(protocol='https')

0 commit comments

Comments
 (0)