WeAreFarmGeek / diplomat

A HTTP Ruby API for Consul
BSD 3-Clause "New" or "Revised" License
370 stars 116 forks source link

Kv.get /w recurse: true is not consistent #162

Closed scottybrisbane closed 5 years ago

scottybrisbane commented 6 years ago

This is essentially just a re-do of #119, since the solution (#120) was reverted by fd3f2a5e142858e5bb86ac1514e726618db3ad07. I would still very much like to see this get resolved as I am having to use a fork in the meantime. From the original issue:

Kv.get with recurse: true is not consistent if there is only single key were returned.

I am expecting array of key/values, but if there is only single key it would return just its value.

Diplomat::Kv.put('hello/world', 'test')

Diplomat::Kv.get('hello', recurse: true)
# current:
# => 'test'
# expected
# => [{ key: 'hello/world', value: 'test'}]

Current workaround is specifying decode_values: true:

Diplomat::Kv.get('hello', recurse: true, decode_values: true)
# => {[ 'Key' => 'hello/world', 'Value' => 'test', ... }]

But there is no way to make convert_to_hash to work with single key atm.

pierresouchay commented 6 years ago

This does indeed break some usages, what do you think about a new endpoint without this issue?

I would rather add: get_all() and get_keys()

get_all() would recurse, while get_keys() would use the array semantics of retrieving only values.

@scottybrisbane what do you think?

scottybrisbane commented 6 years ago

This seems like a reasonable solution