Module: Vaml

Defined in:
lib/vaml.rb,
lib/vaml/github.rb,
lib/vaml/railtie.rb,
lib/vaml/version.rb,
lib/vaml/vault_config.rb,
lib/vaml/configuration.rb,
lib/vaml/config_handler.rb

Defined Under Namespace

Modules: Github, VaultConfig Classes: ConfigHandler, Configuration, Railtie

Constant Summary collapse

VERSION =
"0.2.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



13
14
15
# File 'lib/vaml.rb', line 13

def configuration
  @configuration
end

Class Method Details

.add_policy(policy_name, policy_definition) ⇒ Object

policy = <<-EOH

  path "sys" {
    policy = "deny"
  }
EOH
Vault.sys.put_policy("dev", policy)


69
70
71
# File 'lib/vaml.rb', line 69

def add_policy(policy_name, policy_definition)
  Vault.sys.put_policy(policy_name, policy_definition)
end

.auth_with_github(token) ⇒ Object



59
60
61
# File 'lib/vaml.rb', line 59

def auth_with_github(token)
  Vaml::Github.auth(token)
end

.configure(options) {|configuration| ... } ⇒ Object

Parameters:

  • options (Hash)

    ‘0.0.0.0:8200’, token: ENV, organization: ”

Yields:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vaml.rb', line 16

def configure(options)
  options[:host] ||= 'http://127.0.0.1:8200'
  options[:token] ||= ENV['VAULT_TOKEN']
  options[:ssl_verify] ||= false

  self.configuration ||= Configuration.new(options)
  yield configuration if block_given?

  # Configures Vault itself.
  Vaml::VaultConfig.configure!
  self
end

.from_yaml(yml) ⇒ Object



37
38
39
40
41
42
# File 'lib/vaml.rb', line 37

def from_yaml(yml)
  handler = Vaml::ConfigHandler.new
  parser = Psych::Parser.new(handler)
  parser.parse(yml)
  handler.root.to_ruby.first
end

.list_policiesObject



73
74
75
76
77
# File 'lib/vaml.rb', line 73

def list_policies
  Vault.sys.policies.map do |name|
    Vault.sys.policy(name)
  end
end

.read(query) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/vaml.rb', line 44

def read(query)
  Vault.with_retries(Vault::HTTPConnectionError) do
    val = Vault.logical.read(query)
    raise "VamlError: No secret was stored for #{query}" unless val
    val
  end
end

.read_string(key) ⇒ Object



33
34
35
# File 'lib/vaml.rb', line 33

def read_string(key)
  read(key).data[:value]
end

.write(key, value) ⇒ Object



53
54
55
56
57
# File 'lib/vaml.rb', line 53

def write(key, value)
  Vault.with_retries(Vault::HTTPConnectionError) do
    Vault.logical.write(key, value)
  end
end

.write_string(key, value) ⇒ Object



29
30
31
# File 'lib/vaml.rb', line 29

def write_string(key, value)
  write(key, {value: value})
end