Skip to content

Commit

Permalink
Merge pull request #1 from praveen-elastic/kv-add-query-params-ns-par…
Browse files Browse the repository at this point in the history
…tition

Add query params 'ns' and 'partition' to KV store
  • Loading branch information
praveen-kukreja authored Nov 7, 2024
2 parents daac265 + 3d42188 commit 4ec7bac
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion consul/api/kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def get(
keys=False,
separator=None,
dc=None,
ns=None,
partition=None,
connections_timeout=None,
):
"""
Expand All @@ -43,6 +45,14 @@ def get(
*dc* is the optional datacenter that you wish to communicate with.
If None is provided, defaults to the agent's datacenter.
*ns* is the optional namespace to use for the request.
If None is provided, the namespace is inherited from the namespace
of request's ACL token, or defaults to the default namespace.
*partition* is the optional Admin Partition to use for the request.
If None is provided, the partition is inferred from the
request's ACL token, or defaults to the default partition.
The *value* returned is for the specified key, or if *recurse* is
True a list of *values* for all keys with the given prefix is
returned.
Expand Down Expand Up @@ -81,6 +91,10 @@ def get(
consistency = consistency or self.agent.consistency
if consistency in ("consistent", "stale"):
params.append((consistency, "1"))
if ns:
params.append(("ns", ns))
if partition:
params.append(("partition", partition))

one = False
decode = False
Expand Down Expand Up @@ -108,6 +122,8 @@ def put(
release=None,
token=None,
dc=None,
ns=None,
partition=None,
connections_timeout=None,
):
"""
Expand Down Expand Up @@ -140,6 +156,14 @@ def put(
*dc* is the optional datacenter that you wish to communicate with.
If None is provided, defaults to the agent's datacenter.
*ns* is the optional namespace to use for the request.
If None is provided, the namespace is inherited from the namespace
of request's ACL token, or defaults to the default namespace.
*partition* is the optional Admin Partition to use for the request.
If None is provided, the partition is inferred from the
request's ACL token, or defaults to the default partition.
The return value is simply either True or False. If False is
returned, then the update has not taken place.
"""
Expand All @@ -158,6 +182,10 @@ def put(
dc = dc or self.agent.dc
if dc:
params.append(("dc", dc))
if ns:
params.append(("ns", ns))
if partition:
params.append(("partition", partition))
http_kwargs = {}
if connections_timeout:
http_kwargs["connections_timeout"] = connections_timeout
Expand All @@ -166,7 +194,16 @@ def put(
CB.json(), f"/v1/kv/{key}", params=params, headers=headers, data=value, **http_kwargs
)

def delete(self, key, recurse=None, cas=None, token=None, dc=None, connections_timeout=None):
def delete(
self,
key,
recurse=None,
cas=None,
token=None,
dc=None,
ns=None,
partition=None,
connections_timeout=None):
"""
Deletes a single key or if *recurse* is True, all keys sharing a
prefix.
Expand All @@ -184,6 +221,14 @@ def delete(self, key, recurse=None, cas=None, token=None, dc=None, connections_t
*dc* is the optional datacenter that you wish to communicate with.
If None is provided, defaults to the agent's datacenter.
*ns* is the optional namespace to use for the request.
If None is provided, the namespace is inherited from the namespace
of request's ACL token, or defaults to the default namespace.
*partition* is the optional Admin Partition to use for the request.
If None is provided, the partition is inferred from the
request's ACL token, or defaults to the default partition.
"""
assert not key.startswith("/"), "keys should not start with a forward slash"

Expand All @@ -195,6 +240,10 @@ def delete(self, key, recurse=None, cas=None, token=None, dc=None, connections_t
dc = dc or self.agent.dc
if dc:
params.append(("dc", dc))
if ns:
params.append(("ns", ns))
if partition:
params.append(("partition", partition))
http_kwargs = {}
if connections_timeout:
http_kwargs["connections_timeout"] = connections_timeout
Expand Down

0 comments on commit 4ec7bac

Please sign in to comment.