Class: Vault::Logical

Inherits:
Request show all
Defined in:
lib/vault/api/logical.rb

Instance Attribute Summary

Attributes inherited from Request

#client

Instance Method Summary collapse

Methods inherited from Request

#initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Vault::Request

Instance Method Details

#delete(path) ⇒ true

Delete the secret at the given path. If the secret does not exist, vault will still return true.

Examples:

Vault.logical.delete("secret/password") #=> true

Parameters:

  • path (String)

    the path to delete

Returns:

  • (true)


65
66
67
68
# File 'lib/vault/api/logical.rb', line 65

def delete(path)
  client.delete("/v1/#{path}")
  return true
end

#read(path) ⇒ Secret?

Read the secret at the given path. If the secret does not exist, nil will be returned.

Examples:

Vault.logical.read("secret/password") #=> #<Vault::Secret lease_id="">

Parameters:

  • path (String)

    the path to read

Returns:



26
27
28
29
30
31
32
# File 'lib/vault/api/logical.rb', line 26

def read(path)
  json = client.get("/v1/#{path}")
  return Secret.decode(json)
rescue HTTPError => e
  return nil if e.code == 404
  raise
end

#write(path, data = {}) ⇒ Secret

Write the secret at the given path with the given data. Note that the data must be a Hash!

Examples:

Vault.logical.write("secret/password", value: "secret") #=> #<Vault::Secret lease_id="">

Parameters:

  • path (String)

    the path to write

  • data (Hash) (defaults to: {})

    the data to write

Returns:



46
47
48
49
50
51
52
53
# File 'lib/vault/api/logical.rb', line 46

def write(path, data = {})
  json = client.put("/v1/#{path}", JSON.fast_generate(data))
  if json.nil?
    return true
  else
    return Secret.decode(json)
  end
end