Skip to content

Commit

Permalink
Always properly take into account the agent when specified in endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pierresouchay committed Mar 27, 2020
1 parent 23f3925 commit 57aa5ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## (UNRELEASED)

## 1.26.1 (March 27, 2020)

BUGFIX:

* Using `agent: http://vault_or_consul_agent:port>` was not properly taken into account in some endpoints

## 1.26.0 (March 5, 2020)

NEW FEATURES:
Expand Down
26 changes: 13 additions & 13 deletions lib/consul/async/consul_template.rb
Expand Up @@ -53,7 +53,7 @@ def datacenters(dc: nil, agent: nil)
query_params = {}
query_params[:dc] = dc if dc
@endp_manager.create_if_missing(path, query_params, agent: agent) do
ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]', agent: agent))
ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]', agent))
end
end

Expand All @@ -63,7 +63,7 @@ def nodes(dc: nil, agent: nil)
query_params = {}
query_params[:dc] = dc if dc
@endp_manager.create_if_missing(path, query_params, agent: agent) do
ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]', agent: agent))
ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]', agent))
end
end

Expand Down Expand Up @@ -136,7 +136,7 @@ def service(name, dc: nil, passing: false, tag: nil, agent: nil)
query_params[:dc] = dc if dc
query_params[:passing] = passing if passing
query_params[:tag] = tag if tag
create_if_missing(path, query_params, agent: agent) { ConsulTemplateService.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateService.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]', agent)) }
end

# https://www.consul.io/api/health.html#list-checks-for-service
Expand All @@ -147,7 +147,7 @@ def checks_for_service(name, dc: nil, passing: false, agent: nil)
query_params = {}
query_params[:dc] = dc if dc
query_params[:passing] = passing if passing
create_if_missing(path, query_params, agent: agent) { ConsulTemplateChecks.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateChecks.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]', agent)) }
end

# https://www.consul.io/api/health.html#list-checks-for-node
Expand All @@ -158,39 +158,39 @@ def checks_for_node(name, dc: nil, passing: false, agent: nil)
query_params = {}
query_params[:dc] = dc if dc
query_params[:passing] = passing if passing
create_if_missing(path, query_params, agent: agent) { ConsulTemplateChecks.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateChecks.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]', agent)) }
end

# https://www.consul.io/api/catalog.html#list-nodes
def nodes(dc: nil, agent: nil)
path = '/v1/catalog/nodes'
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, '[]')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateNodes.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]', agent)) }
end

# 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, '{}')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateNodes.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'
query_params = {}
default_value = '{"Config":{}, "Coord":{}, "Member":{}, "Meta":{}, "Stats":{}}'
create_if_missing(path, query_params, agent: agent) { ConsulAgentSelf.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value)) }
create_if_missing(path, query_params, agent: agent) { ConsulAgentSelf.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value, agent)) }
end

# https://www.consul.io/api/agent.html#view-metrics
def agent_metrics(agent: nil)
path = '/v1/agent/metrics'
query_params = {}
default_value = '{"Gauges":[], "Points":[], "Member":{}, "Counters":[], "Samples":{}}'
create_if_missing(path, query_params, agent: agent) { ConsulAgentMetrics.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value)) }
create_if_missing(path, query_params, agent: agent) { ConsulAgentMetrics.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value, agent)) }
end

# https://www.consul.io/api/agent.html#list-members
Expand All @@ -199,7 +199,7 @@ def agent_members(wan: false, agent: nil)
query_params = {}
query_params['wan'] = true if wan
default_value = '[]'
create_if_missing(path, query_params, agent: agent) { ConsulTemplateMembers.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value)) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateMembers.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value, agent)) }
end

# Return a param of template
Expand All @@ -222,14 +222,14 @@ def services(dc: nil, tag: nil, agent: nil)
query_params[:dc] = dc if dc
# Tag filtering is performed on client side
query_params[:tag] = tag if tag
create_if_missing(path, query_params, agent: agent) { ConsulTemplateServices.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateServices.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', agent)) }
end

# https://www.consul.io/api/catalog.html#list-datacenters
def datacenters(agent: nil)
path = '/v1/catalog/datacenters'
query_params = {}
create_if_missing(path, query_params, agent: agent) { ConsulTemplateDatacenters.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]')) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateDatacenters.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '[]', agent)) }
end

# https://www.consul.io/api/kv.html#read-key
Expand All @@ -240,7 +240,7 @@ def kv(name = nil, dc: nil, keys: nil, recurse: false, agent: nil)
query_params[:recurse] = recurse if recurse
query_params[:keys] = keys if keys
default_value = '[]'
create_if_missing(path, query_params, agent: agent) { ConsulTemplateKV.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value), name) }
create_if_missing(path, query_params, agent: agent) { ConsulTemplateKV.new(ConsulEndpoint.new(consul_conf, path, true, query_params, default_value, agent), name) }
end

def secrets(path = '', agent: nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/consul/async/version.rb
@@ -1,5 +1,5 @@
module Consul
module Async
VERSION = '1.26.0'.freeze
VERSION = '1.26.1'.freeze
end
end

0 comments on commit 57aa5ba

Please sign in to comment.