forked from Ecwid/consul-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ecwid#186 token as request param is deprecated
Consul now warns aggressively when token is provided as a request param and the X-Consul-Token is required. Also as already mentioned in Ecwid#186 token request param will be removed in Consul v1.17. By reading the code and related PRs I've seen that in the so called "new http architecture" this is addressed although not all clients fully utilize the new Request class. This PR uses the Request class for both Catalog and KV clients. Should address both Ecwid#186 and Ecwid#237.
- Loading branch information
1 parent
232550b
commit 65cb928
Showing
6 changed files
with
79 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package com.ecwid.consul.v1.kv; | ||
|
||
import java.util.List; | ||
|
||
import com.ecwid.consul.ConsulException; | ||
import com.ecwid.consul.SingleUrlParameters; | ||
import com.ecwid.consul.UrlParameters; | ||
|
@@ -14,6 +12,8 @@ | |
import com.ecwid.consul.v1.kv.model.PutParams; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Vasily Vasilkov ([email protected]) | ||
*/ | ||
|
@@ -66,8 +66,12 @@ public Response<GetValue> getKVValue(String key, QueryParams queryParams) { | |
|
||
@Override | ||
public Response<GetValue> getKVValue(String key, String token, QueryParams queryParams) { | ||
UrlParameters tokenParams = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/kv/" + key, tokenParams, queryParams); | ||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + key) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
HttpResponse httpResponse = rawClient.makeGetRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
List<GetValue> value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken<List<GetValue>>() { | ||
|
@@ -104,8 +108,13 @@ public Response<GetBinaryValue> getKVBinaryValue(String key, QueryParams queryPa | |
|
||
@Override | ||
public Response<GetBinaryValue> getKVBinaryValue(String key, String token, QueryParams queryParams) { | ||
UrlParameters tokenParams = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/kv/" + key, tokenParams, queryParams); | ||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + key) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
|
||
HttpResponse httpResponse = rawClient.makeGetRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
List<GetBinaryValue> value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken<List<GetBinaryValue>>() { | ||
|
@@ -143,8 +152,15 @@ public Response<List<GetValue>> getKVValues(String keyPrefix, QueryParams queryP | |
@Override | ||
public Response<List<GetValue>> getKVValues(String keyPrefix, String token, QueryParams queryParams) { | ||
UrlParameters recurseParam = new SingleUrlParameters("recurse"); | ||
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, recurseParam, tokenParam, queryParams); | ||
|
||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + keyPrefix) | ||
.addUrlParameter(recurseParam) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
|
||
HttpResponse httpResponse = rawClient.makeGetRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
List<GetValue> value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken<List<GetValue>>() { | ||
|
@@ -175,8 +191,15 @@ public Response<List<GetBinaryValue>> getKVBinaryValues(String keyPrefix, QueryP | |
@Override | ||
public Response<List<GetBinaryValue>> getKVBinaryValues(String keyPrefix, String token, QueryParams queryParams) { | ||
UrlParameters recurseParam = new SingleUrlParameters("recurse"); | ||
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, recurseParam, tokenParam, queryParams); | ||
|
||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + keyPrefix) | ||
.addUrlParameter(recurseParam) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
|
||
HttpResponse httpResponse = rawClient.makeGetRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
List<GetBinaryValue> value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken<List<GetBinaryValue>>() { | ||
|
@@ -208,8 +231,16 @@ public Response<List<String>> getKVKeysOnly(String keyPrefix, QueryParams queryP | |
public Response<List<String>> getKVKeysOnly(String keyPrefix, String separator, String token, QueryParams queryParams) { | ||
UrlParameters keysParam = new SingleUrlParameters("keys"); | ||
UrlParameters separatorParam = separator != null ? new SingleUrlParameters("separator", separator) : null; | ||
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, keysParam, separatorParam, tokenParam, queryParams); | ||
|
||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + keyPrefix) | ||
.addUrlParameter(keysParam) | ||
.addUrlParameter(separatorParam) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
|
||
HttpResponse httpResponse = rawClient.makeGetRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
List<String> value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken<List<String>>() { | ||
|
@@ -250,7 +281,16 @@ public Response<Boolean> setKVValue(String key, String value, PutParams putParam | |
@Override | ||
public Response<Boolean> setKVValue(String key, String value, String token, PutParams putParams, QueryParams queryParams) { | ||
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; | ||
HttpResponse httpResponse = rawClient.makePutRequest("/v1/kv/" + key, value, putParams, tokenParam, queryParams); | ||
|
||
Request request = Request.Builder.newBuilder() | ||
.setEndpoint("/v1/kv/" + key) | ||
.setContent(value) | ||
.addUrlParameter(putParams) | ||
.addUrlParameter(queryParams) | ||
.setToken(token) | ||
.build(); | ||
|
||
HttpResponse httpResponse = rawClient.makePutRequest(request); | ||
|
||
if (httpResponse.getStatusCode() == 200) { | ||
boolean result = GsonFactory.getGson().fromJson(httpResponse.getContent(), boolean.class); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters