pusher / stronghold-ruby

Ruby client for stronghold.
MIT License
1 stars 1 forks source link

Add option to replace json, rather than merge it #8

Closed TomKemp closed 5 years ago

TomKemp commented 5 years ago

Stronghold doesn't have any documented APIs for deleting keys or paths. In stronghold-ui you can achieve the same effect by doing the following: to delete a key, you can remove the key from the JSON for that path and save. To remove a path entirely, you can delete all the keys (so that the JSON is {}) and saving will remove the path. This works because updates replace the entire JSON structure at a path.

However in the stronghold-cli, the --set-json option merges the new JSON object with the old JSON object. This means it isn't possible to delete keys or to delete whole paths.

This PR adds a --replace-json option, which replaces the JSON at a path rather than merging the keys. This makes it possible to delete a path by replacing the JSON with {}:

echo "{}" | stronghold-cli --path /test/path --replace-json

While this does also make it possible to also delete individual keys, it would require the user of this CLI to provide the full JSON with the individual keys removed. The CLI could make the process simpler by giving an option to delete individual keys and that could be future work.