Giter VIP home page Giter VIP logo

Comments (4)

mfkl avatar mfkl commented on August 25, 2024

consuldotnet/Consul/KV.cs

Lines 354 to 362 in 269b5bd

/// <summary>
/// DeleteTree is used to delete all keys under a prefix
/// </summary>
/// <param name="prefix">The key prefix to delete from</param>
/// <returns>A write result indicating if the recursive delete attempt succeeded</returns>
public Task<WriteResult<bool>> DeleteTree(string prefix, CancellationToken ct = default(CancellationToken))
{
return DeleteTree(prefix, WriteOptions.Default, ct);
}

Is that what you're looking for?

from consuldotnet.

christopher7694 avatar christopher7694 commented on August 25, 2024

Thanks for the reply!

That call goes to here:

consuldotnet/Consul/KV.cs

Lines 370 to 376 in 269b5bd

public Task<WriteResult<bool>> DeleteTree(string prefix, WriteOptions q, CancellationToken ct = default(CancellationToken))
{
KVPair.ValidatePath(prefix);
var req = _client.DeleteReturning<bool>(string.Format("/v1/kv/{0}", prefix.TrimStart('/')), q);
req.Params.Add("recurse", string.Empty);
return req.Execute(ct);
}

which calls:

KVPair.ValidatePath(prefix);

which in turn calls:

static internal void ValidatePath(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new InvalidKeyPairException("Invalid key. Key path is empty.");
}
else if (path[0] == '/')
{
throw new InvalidKeyPairException(string.Format("Invalid key. Key must not begin with a '/': {0}", path));
}
}
}

When calling List() I am able to pass in "" for prefix to get all the entries and assumed (which could be the problem!) that passing "" into DeleteTree would "delete all", instead it throws an exception as shown above.

Is there another option (other than calling List and deleting one by one?) or is this a bug or perhaps an intentional restriction or something else?

from consuldotnet.

mfkl avatar mfkl commented on August 25, 2024

I don't see a way to drop all the keys without specifying a prefix from the docs https://www.consul.io/commands/kv/delete

How would you achieve this with Consul CLI?

from consuldotnet.

christopher7694 avatar christopher7694 commented on August 25, 2024

I don't see a way either. Ok. I'll use the workaround for now of getting all the keys and deleting them one by one.

Thanks!

from consuldotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.