Ecwid / consul-api

Java client for Consul HTTP API
Apache License 2.0
416 stars 177 forks source link

acl token support in setKVValue #237

Open DanielYWoo opened 2 years ago

DanielYWoo commented 2 years ago

Currently the client can use an acl token, e.g.,

    @Override
    public Response<Boolean> setKVBinaryValue(String key, byte[] value, String token, PutParams putParams, QueryParams queryParams) {
        Request request = Request.Builder.newBuilder()
            .setEndpoint("/v1/kv/" + key)
            .setToken(token) <---- here is the acl token as X-Consul-Token header
            .addUrlParameter(queryParams)
            .addUrlParameter(putParams)
            .setBinaryContent(value)
            .build();

The token will be later used by Utils.createTokenMap() and attached to the request header as X-Consul-Token. Good.

But in the string value of the same method, why do we use the token as a request parameter? And the token will not be attached to the request header, instead, it's attached as a request parameter. What is it for?

    @Override
    public Response<Boolean> setKVValue(String key, String value, String token, PutParams putParams, QueryParams queryParams) {
        UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; <-- what is this?
        HttpResponse httpResponse = rawClient.makePutRequest("/v1/kv/" + key, value, putParams, tokenParam, queryParams);