Make API path configurable
v3alpha was removed since v3.4 etcd, v3beta will be removed in v3.5. Use v3beta as default for now as compatible with both v3.3 and v3.4 versions. Signed-off-by: George Melikov <mail@gmelikov.ru>
This commit is contained in:

committed by
Davanum Srinivas

parent
2c039f8256
commit
20b4fca364
@@ -6,4 +6,4 @@
|
||||
[](https://pypi.python.org/pypi/etcd3gw)
|
||||
[](https://pypi.python.org/pypi/etcd3gw)
|
||||
|
||||
A python client for etcd3 grpc-gateway v3alpha API
|
||||
A python client for etcd3 grpc-gateway v3 API
|
||||
|
@@ -41,8 +41,9 @@ _EXCEPTIONS_BY_CODE = {
|
||||
|
||||
class Etcd3Client(object):
|
||||
def __init__(self, host='localhost', port=2379, protocol="http",
|
||||
ca_cert=None, cert_key=None, cert_cert=None, timeout=None):
|
||||
"""Construct an client to talk to etcd3's grpc-gateway's /v3alpha HTTP API
|
||||
ca_cert=None, cert_key=None, cert_cert=None, timeout=None,
|
||||
api_path='/v3beta/'):
|
||||
"""Construct an client to talk to etcd3's grpc-gateway's /v3 HTTP API
|
||||
|
||||
:param host:
|
||||
:param port:
|
||||
@@ -59,9 +60,10 @@ class Etcd3Client(object):
|
||||
self.session.verify = ca_cert
|
||||
if cert_cert is not None and cert_key is not None:
|
||||
self.session.cert = (cert_cert, cert_key)
|
||||
self.api_path = api_path
|
||||
|
||||
def get_url(self, path):
|
||||
"""Construct a full url to the v3alpha API given a specific path
|
||||
"""Construct a full url to the v3 API given a specific path
|
||||
|
||||
:param path:
|
||||
:return: url
|
||||
@@ -69,7 +71,7 @@ class Etcd3Client(object):
|
||||
host = ('[' + self.host + ']' if (self.host.find(':') != -1)
|
||||
else self.host)
|
||||
base_url = self.protocol + '://' + host + ':' + str(self.port)
|
||||
return base_url + '/v3alpha/' + path.lstrip("/")
|
||||
return base_url + self.api_path + path.lstrip("/")
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
"""helper method for HTTP POST
|
||||
|
@@ -22,17 +22,17 @@ class TestEtcd3Gateway(base.TestCase):
|
||||
|
||||
def test_client_default(self):
|
||||
client = Etcd3Client()
|
||||
self.assertEqual("http://localhost:2379/v3alpha/lease/grant",
|
||||
self.assertEqual("http://localhost:2379/v3beta/lease/grant",
|
||||
client.get_url("/lease/grant"))
|
||||
|
||||
def test_client_ipv4(self):
|
||||
client = Etcd3Client(host="127.0.0.1")
|
||||
self.assertEqual("http://127.0.0.1:2379/v3alpha/lease/grant",
|
||||
self.assertEqual("http://127.0.0.1:2379/v3beta/lease/grant",
|
||||
client.get_url("/lease/grant"))
|
||||
|
||||
def test_client_ipv6(self):
|
||||
client = Etcd3Client(host="::1")
|
||||
self.assertEqual("http://[::1]:2379/v3alpha/lease/grant",
|
||||
self.assertEqual("http://[::1]:2379/v3beta/lease/grant",
|
||||
client.get_url("/lease/grant"))
|
||||
|
||||
def test_client_bad_request(self):
|
||||
|
Reference in New Issue
Block a user