Consul: Add support for copy/paste, export/import of K/V store folders in Consul native UI

Created on 13 Jan 2016  路  7Comments  路  Source: hashicorp/consul

Hi,

We are using Consul extensively in our project, including using it for our service centralized configuration management via Consul K/V store. We don't yet developed our own UI for configuration management but just use Consul embedded UI for configuration changes. We found it is cumbersome to add the K/V pairs one by one, especially we are separating the services' configuration in different folders.

It would be really great if Consul UI could support copy and paste a whole directory to a new directory (and even can select the keys to copy over), and also export/import the key-value pairs into/from a file.

typenhancement

Most helpful comment

Since this shows up on google, and since I've spent the last 3 hours trying to accomplish a recursive copy of a KV directory, I'll post my terrible bash script here:

curl http://consul.mycompany.com/v1/kv/$FROM\?recurse 2>/dev/null |
jq -r '.[] | [.Key, .Value] | join(" ")' |
while read line; do
    KEY=$(echo $line | awk '{print $1}' | sed "s/$FROM/$TO/")
    VAL=$(echo $line | awk '{print $2}' | base64 --decode)
    curl -XPUT -d "$VAL" "http://consul.mycompany.com/v1/kv/$KEY"
    echo
done;

Set $FROM and $TO to the absolute paths, and change the URL for your consul server.

Caveat: jq >= 1.4 must be installed on your system.

Hope this helps someone.

All 7 comments

HI @quickwind thanks for opening an issue. Something like https://github.com/Cimpress-MCP/git2consul is probably a better way to go for this use case. We are thinking of adding a multi-KV API, but we don't have plans to add that to the UI at this time.

Since this shows up on google, and since I've spent the last 3 hours trying to accomplish a recursive copy of a KV directory, I'll post my terrible bash script here:

curl http://consul.mycompany.com/v1/kv/$FROM\?recurse 2>/dev/null |
jq -r '.[] | [.Key, .Value] | join(" ")' |
while read line; do
    KEY=$(echo $line | awk '{print $1}' | sed "s/$FROM/$TO/")
    VAL=$(echo $line | awk '{print $2}' | base64 --decode)
    curl -XPUT -d "$VAL" "http://consul.mycompany.com/v1/kv/$KEY"
    echo
done;

Set $FROM and $TO to the absolute paths, and change the URL for your consul server.

Caveat: jq >= 1.4 must be installed on your system.

Hope this helps someone.

Is there a way to have consul load key/value from /etc/consul.d/somefile.json, similar how it can load service config ?

@jsr88f there's currently no way to statically configure keys similar to service definitions. Take a look at git2consul referenced above - it can load KV data based on input files.

hey guys i have written an application that is basically a tree for consul kv store which support cut, copy, paste, delete , create functions, check it out and let me know if it helps

https://github.com/vagharsh/consul-tree

@vagharsh honestly I don't have much will to configure apache + php, but it looks very nice.

you could use the docker ready-made docker container and not configure anything.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eshujiushiwo picture eshujiushiwo  路  3Comments

atomantic picture atomantic  路  4Comments

nschoe picture nschoe  路  4Comments

pritam97 picture pritam97  路  3Comments

matteoturra picture matteoturra  路  4Comments