lib/consul/async/consul_template.rb in consul-templaterb-1.32.1 vs lib/consul/async/consul_template.rb in consul-templaterb-1.33.0
- old
+ new
@@ -29,11 +29,11 @@
@endp_manager = endpoints_manager
end
def as_json(url, default_value, refresh_delay_secs: 10, **opts)
conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs, **opts)
- endpoint_id = url + opts.to_json
+ endpoint_id = url + opts.hash.to_s
@endp_manager.create_if_missing(url, {}, endpoint_id: endpoint_id) do
if default_value.is_a?(Array)
ConsulTemplateJSONArray.new(JSONEndpoint.new(conf, url, default_value))
else
ConsulTemplateJSONObject.new(JSONEndpoint.new(conf, url, default_value))
@@ -185,11 +185,11 @@
# https://www.consul.io/api/catalog.html#list-services-for-node
def node(name_or_id, dc: nil, agent: nil)
path = "/v1/catalog/node/#{name_or_id}"
query_params = {}
query_params[:dc] = dc if dc
- create_if_missing(path, query_params, agent: agent) { ConsulTemplateNodes.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', agent)) }
+ create_if_missing(path, query_params, agent: agent) { ConsulTemplateNode.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', agent)) }
end
# https://www.consul.io/api/agent.html#read-configuration
def agent_self(agent: nil)
path = '/v1/agent/self'
@@ -623,9 +623,39 @@
# List of checks for agent
class ConsulTemplateChecks < ConsulTemplateAbstractArray
def initialize(consul_endpoint)
super(consul_endpoint)
+ end
+ end
+
+ # Get information about a single node
+ class ConsulTemplateNode < ConsulTemplateAbstractMap
+ def initialize(consul_endpoint)
+ super(consul_endpoint)
+ end
+
+ def exists?
+ !result_delegate.nil?
+ end
+
+ def safe_get
+ if exists?
+ result_delegate
+ else
+ {
+ 'Node': {},
+ 'Services': {}
+ }
+ end
+ end
+
+ def node
+ safe_get['Node'] || {}
+ end
+
+ def services
+ safe_get['Services'] || {}
end
end
# List of nodes of the whole cluster
class ConsulTemplateNodes < ConsulTemplateAbstractArray