Does Consul differentiate between a folder and leaf keys ?

638 views
Skip to first unread message

Amit Kumar

unread,
Aug 20, 2016, 11:44:51 PM8/20/16
to Consul
Does Consul differentiate between a normal KV vs a folder ? i.e. When I fetch "keys" using consul under a prefix, it just returns array of strings. Could it return array of objects where each object in the array indicates the key name and its type (folder or leaf) ?

David Adams

unread,
Aug 21, 2016, 9:02:14 AM8/21/16
to consu...@googlegroups.com
I believe "folders" are implicitly indicated with a trailing slash character. At least, that's how the UI interprets such keys. Creating a "folder" in the UI creates a null-value key at that location.

However, it's really important to note that the paths "config/secrets" and "config/secrets/" are separate items in the KV store. It's also important to note that you don't need to pre-create the "folders". You can just write something to x/y/z/p/q. I don't recall off the top of my head how Consul's API will handle the intermediate keys in your example, though.

On Sat, Aug 20, 2016 at 10:44 PM, Amit Kumar <alla...@gmail.com> wrote:
Does Consul differentiate between a normal KV vs a folder ? i.e. When I fetch "keys" using consul under a prefix, it just returns array of strings. Could it return array of objects where each object in the array indicates the key name and its type (folder or leaf) ?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/96877054-0f45-4eff-926f-809dc2b9d1f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Fischer

unread,
Aug 21, 2016, 8:08:04 PM8/21/16
to consu...@googlegroups.com
There's not really such a thing as a "folder" in Consul K/V. You
don't need to create a parent path in its namespace, and any arbitrary
path can have a value. The only thing that makes them folder-like is
that you can recurse the namespace.

On Sun, Aug 21, 2016 at 6:02 AM, David Adams <dave...@gmail.com> wrote:
> I believe "folders" are implicitly indicated with a trailing slash
> character. At least, that's how the UI interprets such keys. Creating a
> "folder" in the UI creates a null-value key at that location.
>
> However, it's really important to note that the paths "config/secrets" and
> "config/secrets/" are separate items in the KV store. It's also important to
> note that you don't need to pre-create the "folders". You can just write
> something to x/y/z/p/q. I don't recall off the top of my head how Consul's
> API will handle the intermediate keys in your example, though.
>
> On Sat, Aug 20, 2016 at 10:44 PM, Amit Kumar <alla...@gmail.com> wrote:
>>
>> Does Consul differentiate between a normal KV vs a folder ? i.e. When I
>> fetch "keys" using consul under a prefix, it just returns array of strings.
>> Could it return array of objects where each object in the array indicates
>> the key name and its type (folder or leaf) ?
>>
>> --
>> This mailing list is governed under the HashiCorp Community Guidelines -
>> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
>> of those guidelines may result in your removal from this mailing list.
>>
>> GitHub Issues: https://github.com/hashicorp/consul/issues
>> IRC: #consul on Freenode
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Consul" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to consul-tool...@googlegroups.com.
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/consul/issues
> IRC: #consul on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Consul" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to consul-tool...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/consul-tool/CAN3s8zZ2op%3DjSPq0e5QmUWuNve9UTic3-Z73vk1483wX0DOCkA%40mail.gmail.com.

Amit Kumar

unread,
Aug 22, 2016, 2:48:53 PM8/22/16
to Consul
I see. Thanks for your reply. It would have been much better if there was a type differentiation provided by Consul itself rather than everyone trying to work with endsWith('/') things.

Deept Shukla

unread,
Apr 24, 2020, 8:12:07 AM4/24/20
to Consul
True that David.
Infact, if you try creating a folder first, and later create kv inside it, it creates a key with the folder name itself and put a null value to it.
If you create the key in a recursive way as folder/kv, only the key will be created inside the folder and the folder won't have any value, which is actually the correct way of doing it.


On Sunday, August 21, 2016 at 6:32:14 PM UTC+5:30, David Adams wrote:
I believe "folders" are implicitly indicated with a trailing slash character. At least, that's how the UI interprets such keys. Creating a "folder" in the UI creates a null-value key at that location.

However, it's really important to note that the paths "config/secrets" and "config/secrets/" are separate items in the KV store. It's also important to note that you don't need to pre-create the "folders". You can just write something to x/y/z/p/q. I don't recall off the top of my head how Consul's API will handle the intermediate keys in your example, though.
On Sat, Aug 20, 2016 at 10:44 PM, Amit Kumar <alla...@gmail.com> wrote:
Does Consul differentiate between a normal KV vs a folder ? i.e. When I fetch "keys" using consul under a prefix, it just returns array of strings. Could it return array of objects where each object in the array indicates the key name and its type (folder or leaf) ?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages