Class: Cipherpipe::Vault::API

Inherits:
Vault::Request
  • Object
show all
Defined in:
lib/cipherpipe/vault/api.rb

Instance Method Summary collapse

Instance Method Details

#read(path, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/cipherpipe/vault/api.rb', line 2

def read(path, options = {})
  headers = extract_headers! options
  json    = client.get("/v1/secret/data/#{encode_path(path)}", {}, headers)

  ::Vault::Secret.decode json[:data]
rescue ::Vault::HTTPError => error
  return nil if error.code == 404
  raise error
end

#write(path, data = {}, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/cipherpipe/vault/api.rb', line 12

def write(path, data = {}, options = {})
  headers = extract_headers! options
  json    = Vault.logical.client.post(
    "/v1/secret/data/#{encode_path path}",
    JSON.fast_generate(:data => data),
    headers
  )

  json.nil? ? true : ::Vault::Secret.decode(json)
end