etcdtool
etcdtool copied to clipboard
Problem with list convertions
Hi there!
I'm facing a problem trying to import/export some data into etcd using etcdtool. Since lists are converted into json objects creating directories using the index as the key, when I load a json file with a list and then try to export the destination key, both json files differ.
Example: # cat test.json { "mylist": [ { "one": "uno"}, {"two": "dos"} ] } # ./etcdtool-3.4 --peers="https://myetcd:2379" import -y /test ./test.json # ./etcdtool-3.4 --peers="https://myetcd:2379" export /test { "mylist": { "0": { "one": "uno" }, "1": { "two": "dos" } } }
It would be great to export the directory so the resulting json file is the same that was loaded (expected behavior: when all the keys in a directory are whole numbers, then convert them into a list). Maybe it can be added as an optional parameter (e.g. --keep-lists)?.
Etcd only handles strings natively for a key, also it doesn't support lists per default this is simulated in this manner. I could add some logic that would assume that if there are only integer keys that it's a list.
It would also be possible to create an identifier like "list": "true" on import.
I'm using the import/export functions of etcdtool from different sources, therefore I need both jsons to be equal. I assume the import will convert lists the way it does, so I think the import doesn't need an identifier. Just by adding an option to reconstruct the lists (if there are only integer keys, as you said) in the exported json file would be enough.
I'll look into adding an option for this like "--num-infer-list".