Pass api_path thru etcd3gw.client
Change-Id: I49c480f573a4ba8294627a3ce730b816ded10aed
This commit is contained in:
parent
e3553a32f9
commit
2a7f392a80
@ -37,11 +37,13 @@ _EXCEPTIONS_BY_CODE = {
|
||||
requests.codes['precondition_failed']: exceptions.PreconditionFailedError,
|
||||
}
|
||||
|
||||
DEFAULT_API_PATH = '/v3alpha/'
|
||||
|
||||
|
||||
class Etcd3Client(object):
|
||||
def __init__(self, host='localhost', port=2379, protocol="http",
|
||||
ca_cert=None, cert_key=None, cert_cert=None, timeout=None,
|
||||
api_path='/v3alpha/'):
|
||||
api_path=DEFAULT_API_PATH):
|
||||
"""Construct an client to talk to etcd3's grpc-gateway's /v3 HTTP API
|
||||
|
||||
:param host:
|
||||
@ -409,7 +411,7 @@ class Etcd3Client(object):
|
||||
|
||||
def client(host='localhost', port=2379,
|
||||
ca_cert=None, cert_key=None, cert_cert=None,
|
||||
timeout=None, protocol="http"):
|
||||
timeout=None, protocol="http", api_path=DEFAULT_API_PATH):
|
||||
"""Return an instance of an Etcd3Client."""
|
||||
return Etcd3Client(host=host,
|
||||
port=port,
|
||||
@ -417,4 +419,5 @@ def client(host='localhost', port=2379,
|
||||
cert_key=cert_key,
|
||||
cert_cert=cert_cert,
|
||||
timeout=timeout,
|
||||
api_path=api_path,
|
||||
protocol=protocol)
|
||||
|
@ -74,3 +74,8 @@ class TestEtcd3Gateway(base.TestCase):
|
||||
self.assertEqual(e.detail_text, '''{
|
||||
"error": "etcdserver: unable to reach quorum"
|
||||
}''')
|
||||
|
||||
def test_client_api_path(self):
|
||||
client = Etcd3Client(host="127.0.0.1", api_path='/v3/')
|
||||
self.assertEqual("http://127.0.0.1:2379/v3/lease/grant",
|
||||
client.get_url("/lease/grant"))
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The client adds support for specifying the etcd grpc-gateway's API path.
|
||||
For backward compatibility, the path defaults to '/v3alpha/', but may
|
||||
be overriden (e.g. '/v3') for newer versions of etcd that no longer support
|
||||
the v3alpha API.
|
Loading…
Reference in New Issue
Block a user