Module: Consult::TemplateFunctions
- Included in:
- Template
- Defined in:
- lib/consult/template_functions.rb
Instance Method Summary collapse
-
#indent(string, level, separator = "\n") ⇒ Object
Indent a multi-line string by the provided amount.
- #key(key, options: nil, not_found: :reject, found: :return) ⇒ Object
-
#query(name_or_id, options: nil) ⇒ Object
Execute a prepared query.
-
#query_nodes(*args) ⇒ Object
Return just the nodes from a prepared query.
-
#secret(path) ⇒ Object
Vault.
- #secrets(path) ⇒ Object
-
#service(key, scope: :all, options: nil, meta: nil) ⇒ Object
Consul.
- #timestamp ⇒ Object
-
#with(whatever) {|whatever| ... } ⇒ Object
Utility.
Instance Method Details
#indent(string, level, separator = "\n") ⇒ Object
Indent a multi-line string by the provided amount.
51 52 53 54 55 |
# 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) ⇒ Object
33 34 35 |
# File 'lib/consult/template_functions.rb', line 33 def key(key, options: nil, not_found: :reject, found: :return) Diplomat::Kv.get(key, , not_found, found) end |
#query(name_or_id, options: nil) ⇒ Object
Execute a prepared query
24 25 26 |
# File 'lib/consult/template_functions.rb', line 24 def query(name_or_id, options: nil) Diplomat::Query.execute(name_or_id, ) end |
#query_nodes(*args) ⇒ Object
Return just the nodes from a prepared query
29 30 31 |
# File 'lib/consult/template_functions.rb', line 29 def query_nodes(*args) query(*args)&.Nodes&.map { |node| node['Node'] } end |
#secret(path) ⇒ Object
Vault
8 9 10 |
# File 'lib/consult/template_functions.rb', line 8 def secret(path) Vault.logical.read(path) end |
#secrets(path) ⇒ Object
12 13 14 |
# File 'lib/consult/template_functions.rb', line 12 def secrets(path) Vault.logical.list(path) end |
#service(key, scope: :all, options: nil, meta: nil) ⇒ Object
Consul
19 20 21 |
# File 'lib/consult/template_functions.rb', line 19 def service(key, scope: :all, options: nil, meta: nil) Diplomat::Service.get(key, scope, , ) end |
#timestamp ⇒ Object
46 47 48 |
# File 'lib/consult/template_functions.rb', line 46 def Time.now.utc end |
#with(whatever) {|whatever| ... } ⇒ Object
Utility
Provided as a bridge to consul-template/go conventions. Simply yields back whatever was provided.
42 43 44 |
# File 'lib/consult/template_functions.rb', line 42 def with(whatever) yield whatever end |