rickfast / consul-client

Java Client for Consul HTTP API
Other
570 stars 241 forks source link

Fails to retrieve keyValue in folder by key #443

Open dschulten opened 3 years ago

dschulten commented 3 years ago

Consul allows to organize keyValues in folders, which then become part of the URL path.

In the example kv url below, resources/ is a kv folder and my.key is an actual keyValue pair.

http://consul.example.com/v1/kv/resources/my.key

Unfortunately KeyValueClient.getValue() urlencodes a key with folder prefix such as resources/my.key and requests

/v1/kv/resources%2fmy.key

which fails with 404.

The same problem occurs with KeyValueClient.getValues() for a path of folders, as in getValues("resources/subfolder").

dschulten commented 3 years ago

The reason that the keys are encoded are the @Path annotations on the methods in KeyValueClient.Api. Their encoded property is false, which causes RequestFactory to create a ParameterHandler.Path that encodes the entire key. Probably the Api Methods need a variant with a {path} and a {key} argument where the path is encoded, but not the key - the question is if that could work alongside the existing Api.