Class: Trocla::Stores::Vault

Inherits:
Trocla::Store show all
Defined in:
lib/trocla/stores/vault.rb

Overview

the default vault based store

Instance Attribute Summary collapse

Attributes inherited from Trocla::Store

#store_config, #trocla

Instance Method Summary collapse

Methods inherited from Trocla::Store

#delete, #set

Constructor Details

#initialize(config, trocla) ⇒ Vault

Returns a new instance of Vault.



5
6
7
8
9
10
11
12
# File 'lib/trocla/stores/vault.rb', line 5

def initialize(config, trocla)
  super(config, trocla)
  require 'vault'
  @mount = (config.delete(:mount) || 'kv')
  @destroy = (config.delete(:destroy) || false)
  # load expire support by default
  @vault = Vault::Client.new(config)
end

Instance Attribute Details

#destroyObject (readonly)

Returns the value of attribute destroy.



3
4
5
# File 'lib/trocla/stores/vault.rb', line 3

def destroy
  @destroy
end

#mountObject (readonly)

Returns the value of attribute mount.



3
4
5
# File 'lib/trocla/stores/vault.rb', line 3

def mount
  @mount
end

#vaultObject (readonly)

Returns the value of attribute vault.



3
4
5
# File 'lib/trocla/stores/vault.rb', line 3

def vault
  @vault
end

Instance Method Details

#closeObject



14
# File 'lib/trocla/stores/vault.rb', line 14

def close; end

#formats(key) ⇒ Object



20
21
22
# File 'lib/trocla/stores/vault.rb', line 20

def formats(key)
  read(key).keys
end

#get(key, format) ⇒ Object



16
17
18
# File 'lib/trocla/stores/vault.rb', line 16

def get(key, format)
  read(key)[format.to_sym]
end

#search(key) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/trocla/stores/vault.rb', line 24

def search(key)
  arr = key.split('/')
  regexp = Regexp.new(arr.pop(1)[0].to_s)
  path = arr.join('/')
  list = vault.kv(mount).list(path)
  list.map! do |l|
    if regexp.match(l)
      path.empty? ? l : [path, l].join('/')
    end
  end
  list.compact
end