module Consult::TemplateFunctions

Public Instance Methods

indent(string, level, separator = "\n") click to toggle source

Indent a multi-line string by the provided amount.

# File lib/consult/template_functions.rb, line 51
def indent(string, level, separator = "\n")
  string.split(separator).map do |line|
    ' ' * level + line
  end.join(separator)
end
key(key, options: nil, not_found: :reject, found: :return) click to toggle source
# File lib/consult/template_functions.rb, line 33
def key(key, options: nil, not_found: :reject, found: :return)
  Diplomat::Kv.get(key, options, not_found, found)
end
query(name_or_id, options: nil) click to toggle source

Execute a prepared query

# File lib/consult/template_functions.rb, line 24
def query(name_or_id, options: nil)
  Diplomat::Query.execute(name_or_id, options)
end
query_nodes(*args) click to toggle source

Return just the nodes from a prepared query

# File lib/consult/template_functions.rb, line 29
def query_nodes(*args)
  query(*args)&.Nodes&.map { |node| node['Node'] }
end
secret(path) click to toggle source

Vault

# File lib/consult/template_functions.rb, line 8
def secret(path)
  Vault.logical.read(path)
end
secrets(path) click to toggle source
# File lib/consult/template_functions.rb, line 12
def secrets(path)
  Vault.logical.list(path)
end
service(key, scope: :all, options: nil, meta: nil) click to toggle source

Consul

# File lib/consult/template_functions.rb, line 19
def service(key, scope: :all, options: nil, meta: nil)
  Diplomat::Service.get(key, scope, options, meta)
end
timestamp() click to toggle source
# File lib/consult/template_functions.rb, line 46
def timestamp
  Time.now.utc
end
with(whatever) { |whatever| ... } click to toggle source

Utility

Provided as a bridge to consul-template/go conventions. Simply yields back whatever was provided.

# File lib/consult/template_functions.rb, line 42
def with(whatever)
  yield whatever
end