hashicorp / vault-ruby

The official Ruby client for HashiCorp's Vault
Mozilla Public License 2.0
340 stars 136 forks source link

Vault.logical.read throws NoMethodError when Vault responds with HTTP 204 (No Content) #241

Open wfhartford opened 4 years ago

wfhartford commented 4 years ago

When the Vault.logical.read function is called and Vault responds with a HTTP 204 No Content response, a NoMethodError is thrown by the vault client:

/usr/local/bundle/gems/vault-0.14.0/lib/vault/response.rb:49:in `initialize': undefined method `each' for nil:NilClass (NoMethodError)
    from /usr/local/bundle/gems/vault-0.14.0/lib/vault/response.rb:38:in `new'
    from /usr/local/bundle/gems/vault-0.14.0/lib/vault/response.rb:38:in `decode'
    from /usr/local/bundle/gems/vault-0.14.0/lib/vault/api/logical.rb:48:in `read'

In my case, I was requesting the /pki/ca where pki is the path of a newly mounted PKI secret engine whose signing certificate has not been created.

The Logical.read function calls client.get which returns nil when the server responds with 204. This nil value gets passed to Secret.decode from which the NoMethodError is thrown.

wfhartford commented 4 years ago

The work around I've used is to call client.get directly and check for nil.