Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/nomad/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def request(verb, path, data = {}, headers = {})
# Get a list of headers
headers = DEFAULT_HEADERS.merge(headers)

# Dynamically read Nomad ACL token
headers = headers.merge({"X-Nomad-Token" => nomad_token})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind guarding this so if nomad_token is nil the header is excluded.


# Add headers
headers.each do |key, value|
req.add_field(key, value)
Expand Down
1 change: 1 addition & 0 deletions lib/nomad/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Configurable
def self.keys
@keys ||= [
:address,
:nomad_token,
:hostname,
:open_timeout,
:proxy_address,
Expand Down
4 changes: 4 additions & 0 deletions lib/nomad/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def address
ENV["NOMAD_ADDR"] || NOMAD_ADDRESS
end

def nomad_token
ENV["NOMAD_TOKEN"]
end

# The SNI host to use when connecting to Nomad via TLS.
# @return [String, nil]
def hostname
Expand Down
2 changes: 1 addition & 1 deletion lib/nomad/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Response

# Parses the value as a string, converting "" to nil (go compat).
string_as_nil: ->(item) {
if item.nil? || item.strip.empty?
if item.nil? || item.to_s.strip.empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary?

nil
else
item
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ module Nomad
end
end

describe ".nomad_token" do
it "uses ENV['NOMAD_TOKEN'] if present" do
with_stubbed_env("NOMAD_TOKEN" => "test") do
expect(Defaults.nomad_token).to eq("test")
end
end
end


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

nit: extra newline

describe ".hostname" do
it "defaults to ENV['NOMAD_TLS_SERVER_NAME']" do
with_stubbed_env("NOMAD_TLS_SERVER_NAME" => "www.foo.com") do
Expand Down