diff --git a/etcd3gw/client.py b/etcd3gw/client.py index 6a88ba1..0f43ea4 100644 --- a/etcd3gw/client.py +++ b/etcd3gw/client.py @@ -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) diff --git a/etcd3gw/tests/test_client.py b/etcd3gw/tests/test_client.py index d4bfc5c..39a6df3 100644 --- a/etcd3gw/tests/test_client.py +++ b/etcd3gw/tests/test_client.py @@ -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")) diff --git a/releasenotes/notes/configurable-api-path-7652e756b6837e0b.yaml b/releasenotes/notes/configurable-api-path-7652e756b6837e0b.yaml new file mode 100644 index 0000000..9a60946 --- /dev/null +++ b/releasenotes/notes/configurable-api-path-7652e756b6837e0b.yaml @@ -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.