Class: Vaulty::Catacomb
- Inherits:
-
Object
- Object
- Vaulty::Catacomb
- Defined in:
- lib/vaulty/catacomb.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.delete(path) ⇒ Boolean
Wrapper around Vault logical delete.
-
.list(path) ⇒ Array
Wrapper around Vault logical list.
-
.read(path) ⇒ Hash
Wrapper around Vault logical read, return always a hash.
-
.write(path, data) ⇒ Hash
Wrapper around Vault logical write.
Instance Method Summary collapse
-
#delete ⇒ True
Deletes a path (with all values) from Vault.
-
#initialize(path) ⇒ Catacomb
constructor
A new instance of Catacomb.
-
#key?(key) ⇒ Boolean
Checks if the key is found in the data.
-
#keys?(keys) ⇒ Boolean
Checks if any of the provided keys are found in the data.
-
#matching_keys(keys) ⇒ Array<String>
Returns matching keys.
-
#merge(data) ⇒ Object
Merges the data to Vault with an optional confirm/msg.
-
#read ⇒ Hash
Reads the data from Vault, always returns an Hash.
-
#reload ⇒ Hash
Clears the cached result from read and returns the result.
-
#write(data) ⇒ Object
Writes data to Vault with an optional confirm/msg.
Constructor Details
#initialize(path) ⇒ Catacomb
Returns a new instance of Catacomb.
5 6 7 |
# File 'lib/vaulty/catacomb.rb', line 5 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/vaulty/catacomb.rb', line 3 def path @path end |
Class Method Details
.delete(path) ⇒ Boolean
Wrapper around Vault logical delete
108 109 110 |
# File 'lib/vaulty/catacomb.rb', line 108 def delete(path) Vault.logical.delete(path) end |
.list(path) ⇒ Array
Wrapper around Vault logical list
98 99 100 101 102 |
# File 'lib/vaulty/catacomb.rb', line 98 def list(path) list = Vault.logical.list(path) cleaned_list = Array(list).map { |folder| folder.delete('/') } cleaned_list.reject(&:empty?).uniq end |
.read(path) ⇒ Hash
Wrapper around Vault logical read, return always a hash
79 80 81 82 |
# File 'lib/vaulty/catacomb.rb', line 79 def read(path) secret = Vault.logical.read(path) secret ? secret.data : {} end |
.write(path, data) ⇒ Hash
Wrapper around Vault logical write
89 90 91 92 |
# File 'lib/vaulty/catacomb.rb', line 89 def write(path, data) secret = Vault.logical.write(path, data) secret.is_a?(Vault::Secret) ? secret.data : {} end |
Instance Method Details
#delete ⇒ True
Deletes a path (with all values) from Vault
69 70 71 72 |
# File 'lib/vaulty/catacomb.rb', line 69 def delete self.class.delete(path) @read = nil end |
#key?(key) ⇒ Boolean
Checks if the key is found in the data
13 14 15 |
# File 'lib/vaulty/catacomb.rb', line 13 def key?(key) read.key?(key.to_sym) end |
#keys?(keys) ⇒ Boolean
Checks if any of the provided keys are found in the data
21 22 23 |
# File 'lib/vaulty/catacomb.rb', line 21 def keys?(keys) matching_keys(keys).any? end |
#matching_keys(keys) ⇒ Array<String>
Returns matching keys
29 30 31 |
# File 'lib/vaulty/catacomb.rb', line 29 def matching_keys(keys) Array(keys).select { |key| key?(key) } end |
#merge(data) ⇒ Object
Merges the data to Vault with an optional confirm/msg
44 45 46 47 |
# File 'lib/vaulty/catacomb.rb', line 44 def merge(data) current = read write(current.merge(data)) end |
#read ⇒ Hash
Reads the data from Vault, always returns an Hash
52 53 54 |
# File 'lib/vaulty/catacomb.rb', line 52 def read @read ||= self.class.read(path) end |
#reload ⇒ Hash
Clears the cached result from read and returns the result
59 60 61 62 |
# File 'lib/vaulty/catacomb.rb', line 59 def reload @read = nil read end |
#write(data) ⇒ Object
Writes data to Vault with an optional confirm/msg
36 37 38 39 |
# File 'lib/vaulty/catacomb.rb', line 36 def write(data) self.class.write(path, data) reload end |