Skip to content

Commit

Permalink
Merge pull request #19 from veracross/token-header
Browse files Browse the repository at this point in the history
Set consul token in X-Consul-Token header
  • Loading branch information
sixfeetover authored Oct 24, 2018
2 parents 9354c09 + 39f9219 commit d1b4155
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/consult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def configure_consul
# Additionally: prefer env vars over explicit config
configured_address = @config[:consul].delete(:address)
@config[:consul][:url] = ENV['CONSUL_HTTP_ADDR'] || configured_address || @config[:consul][:url]
@config[:consul][:acl_token] = consul_token
# If a consul token exists, treat it as special
# See https://github.com/WeAreFarmGeek/diplomat/pull/160
(@config[:consul][:options] ||= {}).merge!(headers: {'X-Consul-Token' => consul_token}) if consul_token.present?

Diplomat.configure do |c|
@config[:consul].each do |opt, val|
Expand Down Expand Up @@ -82,7 +84,7 @@ def render!
def consul_token
ENV['CONSUL_HTTP_TOKEN'] ||
@config[:consul].delete(:token) ||
@config[:consul][:acl_token] ||
@config[:consul].delete(:acl_token) ||
(CONSUL_DISK_TOKEN.exist? ? CONSUL_DISK_TOKEN.read.chomp : nil)
end
end
Expand Down

0 comments on commit d1b4155

Please sign in to comment.