Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query params 'ns' and 'partition' to KV store #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading