Sha256: 6c53bcecefb0e50a31b4a407f9ed2e2571670300aa87d6057c20030c711c60cc

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

# the default vault based store
class Trocla::Stores::Vault < Trocla::Store
  attr_reader :vault, :mount
  def initialize(config,trocla)
    super(config,trocla)
    require 'vault'
    @mount = (config.delete(:mount) || 'kv')
    # load expire support by default
    @vault = Vault::Client.new(config)
  end

  def close
  end

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

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

  private
  def read(key)
    k = vault.kv(mount).read(key)
    k.nil? ? {} : k.data
  end

  def write(key, value)
    vault.kv(mount).write(key, value)
  end

  def set_plain(key,value,options)
    set_format(key,'plain',value,options)
  end

  def set_format(key,format,value,options)
    write(key, read(key).merge({format.to_sym => value}))
  end

  def delete_all(key)
    vault.kv(mount).delete(key)
  end

  def delete_format(key,format)
    old = read(key)
    write(key, old.reject { |k,v| k == format.to_sym })
    old[format.to_sym]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trocla-0.4.0 lib/trocla/stores/vault.rb