pierresouchay / consul-rust

Rust client libray for Consul HTTP API
Apache License 2.0
93 stars 48 forks source link

KV Value can be `null` #24

Open fussybeaver opened 5 years ago

fussybeaver commented 5 years ago

I believe I'm using the consul:1.4.4 docker image, and listing a path returns a null value. This is the response when I use curl:

curl -i http://localhost:8500/v1/kv/redacted/config/?recurse=true
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Index: 1282900
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Fri, 23 Aug 2019 15:15:53 GMT
Content-Length: 254

[{"LockIndex":0,"Key":"redacted/config/","Flags":0,"Value":null,"CreateIndex":1282566,"ModifyIndex":1282566},{"LockIndex":0,"Key":"redacted/config/BUFFER_LENGTH","Flags":0,"Value":"Ng==","CreateIndex":1282900,"ModifyIndex":1282900}]

This causes the consul-rust library to fail on JSON deserialization.

pierresouchay commented 4 years ago

Here are the few different kind of responses for this endpoint.

Assuming the commands have been issues before:

# Put null value
consul kv put test/other/path/value2
# Put non-null value
consul kv put test/other/path/value2 some-value

Listing keys

List keys on non-existing path

HTTP: 404 return: nil

curl -i localhost:8500/v1/kv/non-existing-prefix?keys
HTTP/1.1 404 Not Found
Vary: Accept-Encoding
X-Consul-Index: 21
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:45:37 GMT
Content-Length: 0

Listing keys on existing path

HTTP: 200 return Array[String]

curl -i localhost:8500/v1/kv/test?keys
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Index: 21
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:44:10 GMT
Content-Length: 52

[
    "test/other/path/value2",
    "test/value1"
]

Getting values (simple)

Getting non-existing value

HTTP 404 return nil

 curl -i localhost:8500/v1/kv/non-existing-prefix
HTTP/1.1 404 Not Found
Vary: Accept-Encoding
X-Consul-Index: 21
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:46:26 GMT
Content-Length: 0

Getting value

HTTP 200 return Array[KeyObject] BEWARE: KeyObject.Value might be null

curl -i localhost:8500/v1/kv/test/value1
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Index: 11
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:47:33 GMT
Content-Length: 166

[
    {
        "LockIndex": 0,
        "Key": "test/value1",
        "Flags": 0,
        "Value": null,
        "CreateIndex": 11,
        "ModifyIndex": 11
    }
]

Get Value (Simple) Non existing key

HTTP: 404

curl -i localhost:8500/v1/kv/non-existing-prefix
HTTP/1.1 404 Not Found
Vary: Accept-Encoding
X-Consul-Index: 21
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:41:51 GMT
Content-Length: 0

Getting multiple values

Same output as simple, but multiple values might bee returned:

 curl -i localhost:8500/v1/kv/test?recurse
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Index: 21
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Mon, 16 Mar 2020 18:49:44 GMT
Content-Length: 354

[
    {
        "LockIndex": 0,
        "Key": "test/other/path/value2",
        "Flags": 0,
        "Value": "c29tZS12YWx1ZQ==",
        "CreateIndex": 16,
        "ModifyIndex": 21
    },
    {
        "LockIndex": 0,
        "Key": "test/value1",
        "Flags": 0,
        "Value": null,
        "CreateIndex": 11,
        "ModifyIndex": 11
    }
]

Global Summary

KeyObject := {
        LockIndex uint64
    Key       string
    Flags     uint64
    Value     Option<[]byte> (serialized as base64, can be null)
    CreateIndex: uint64
        ModifyIndex: uint64
}
Operation HTTP Code type returned X-Consul-Index
path, existing 200 Array[KeyObject] Last-Modified index of path
path, not found 404 Array[KeyObject] Last index of change in KV
?keys, existing prefix 200 Array[String] Last Index of change in prefix
?keys, not found 404 nil, no Content Last index of change in KV
?recurse, existing prefix 200 Array[String] Last Index of change in prefix
?recurse, not found 200 nil, no Content Last Index of change in prefix