summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2019-04-25 16:35:10 -0400
committerBryan McLellan <btm@loftninjas.org>2019-05-06 12:56:55 -0400
commit2a8872337373c4a75486044de348ef810d028e95 (patch)
tree41ef995c3cc8a94fb5f96d7ff99410774f4c7a8f
parentd1bb2f1cba61cd1c5a796fe17e7083831213e92b (diff)
downloadchef-2a8872337373c4a75486044de348ef810d028e95.tar.gz
Feedback from Ryan Davis
Signed-off-by: Bryan McLellan <btm@loftninjas.org>
-rw-r--r--lib/chef/client.rb8
-rw-r--r--lib/chef/train_transport.rb25
-rw-r--r--spec/unit/train_transport_spec.rb4
3 files changed, 11 insertions, 26 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 7b0303a9e3..a11662b7d8 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -55,7 +55,6 @@ require "chef/mixin/deprecation"
require "ohai"
require "rbconfig"
require "chef/dist"
-require "ostruct"
require "forwardable"
class Chef
@@ -157,11 +156,8 @@ class Chef
@json_attribs = json_attribs || {}
@logger = args.delete(:logger) || Chef::Log.with_child
- @ohai = if Chef::Config.target_mode?
- OpenStruct.new(data: Mash.new)
- else
- Ohai::System.new(logger: logger)
- end
+ @ohai = Ohai::System.new(logger: logger)
+
event_handlers = configure_formatters + configure_event_loggers
event_handlers += Array(Chef::Config[:event_handlers])
diff --git a/lib/chef/train_transport.rb b/lib/chef/train_transport.rb
index 420851d3a5..9db5f8fbf3 100644
--- a/lib/chef/train_transport.rb
+++ b/lib/chef/train_transport.rb
@@ -35,7 +35,7 @@ class Chef
# host names must be specified in credentials file as ['foo.example.org'] with quotes
if !credentials.nil? && !credentials[profile].nil?
- Mash.from_hash(credentials[profile]).symbolize_keys
+ credentials[profile].map { |k, v| [k.to_sym, v] }.to_h # return symbolized keys to match Train.options()
else
nil
end
@@ -50,25 +50,14 @@ class Chef
# This will be a common mistake so we should catch it
#
def self.contains_split_fqdn?(hash, fqdn)
- n = 0
- matches = 0
- fqdn_split = fqdn.split(".")
-
- # if the top level of the hash matches the first part of the fqdn, continue
- if hash.key?(fqdn_split[n])
- matches += 1
- until n == fqdn_split.length - 1
- # if we still have fqdn elements but ran out of depth, return false
- return false if !hash[fqdn_split[n]].is_a?(Hash)
- if hash[fqdn_split[n]].key?(fqdn_split[n + 1])
- matches += 1
- return true if matches == fqdn_split.length
- end
- hash = hash[fqdn_split[n]]
- n += 1
+ fqdn.split(".").reduce(hash) do |h, k|
+ v = h[k]
+ if Hash === v
+ v
+ else
+ break false
end
end
- false
end
# ChefConfig::Mixin::Credentials.credentials_file_path is designed around knife,
diff --git a/spec/unit/train_transport_spec.rb b/spec/unit/train_transport_spec.rb
index f24c0aaf0e..b56c7e1104 100644
--- a/spec/unit/train_transport_spec.rb
+++ b/spec/unit/train_transport_spec.rb
@@ -21,7 +21,7 @@ require "spec_helper"
describe Chef::TrainTransport do
describe "load_credentials" do
let(:transport) { Chef::TrainTransport.new }
- let(:good_credentials) { Mash.from_hash({ "switch.cisco.com": { user: "cisco", password: "cisco", enable_password: "secret" } }) }
+ let(:good_credentials) { { "switch.cisco.com" => { "user" => "cisco", "password" => "cisco", "enable_password" => "secret" } } }
before do
allow(Chef::TrainTransport).to receive(:parse_credentials_file).and_return(good_credentials)
@@ -40,7 +40,7 @@ describe Chef::TrainTransport do
# [foo.example.org] => {"foo"=>{"example"=>{"org"=>{}}}}
# ['foo.example.org'] => {"foo.example.org"=>{}}
it "warns if the host has been split by toml" do
- allow(Chef::TrainTransport).to receive(:parse_credentials_file).and_return(Mash.from_hash( { "foo" => { "example" => { "org" => {} } } }))
+ allow(Chef::TrainTransport).to receive(:parse_credentials_file).and_return({ "foo" => { "example" => { "org" => {} } } })
expect(Chef::Log).to receive(:warn).with(/as a Hash/)
expect(Chef::Log).to receive(:warn).with(/Hostnames must be surrounded by single quotes/)
expect(Chef::TrainTransport.load_credentials("foo.example.org")).to be_nil