chef-config 12.15.19 → 12.16.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0b3ecc643889dee8fa2bd0abcf48b2f52dd87d1
4
- data.tar.gz: a5ec443f588c7b4877187c76121c6c9adaa1bb0c
3
+ metadata.gz: 1634767453969e0627f8d7dfc6a07804a7062842
4
+ data.tar.gz: f51e8c8dcf909ae9f433973147d0fdf2e1c084f0
5
5
  SHA512:
6
- metadata.gz: 91772fe1f3dd86c7f7099d3ad8700e6dd20430d7519a98bef2352436177630f759f58e27bc76d7528eb5b954063c8ca61f434ab6ee87ee7358c83f638d75572a
7
- data.tar.gz: bf9cb541d01fac3fe7e8bd9170e6c915d9e1c70cfdbb35060ac33cbb4d25c8c3771039a844161ce6627675250ddb1bcd1c5e54e8e1329a0ee8eda089b2949ebb
6
+ metadata.gz: d7fd44e43699b42b8657afaefbb5672915213a811dd7c9ea811bf00796a17412acace7feaddb804e137a7478c343ceea9cb7aceda2597a6919ced00878c59d17
7
+ data.tar.gz: 09f7056b8ed2054346e5618306c9a2b14e755ba677e0c08279d7c635eb373fc1d8073cf33b0e0d4f3519f7fdb5d2ca07c4852998ef6f27b39bb85c0a3c96ab50
@@ -32,6 +32,7 @@ require "mixlib/shellout"
32
32
  require "uri"
33
33
  require "addressable/uri"
34
34
  require "openssl"
35
+ require "yaml"
35
36
 
36
37
  module ChefConfig
37
38
 
@@ -70,6 +71,25 @@ module ChefConfig
70
71
  event_handlers << logger
71
72
  end
72
73
 
74
+ def self.apply_extra_config_options(extra_config_options)
75
+ if extra_config_options
76
+ extra_parsed_options = extra_config_options.inject({}) do |memo, option|
77
+ # Sanity check value.
78
+ if option.empty? || !option.include?("=")
79
+ raise UnparsableConfigOption, "Unparsable config option #{option.inspect}"
80
+ end
81
+ # Split including whitespace if someone does truly odd like
82
+ # --config-option "foo = bar"
83
+ key, value = option.split(/\s*=\s*/, 2)
84
+ # Call to_sym because Chef::Config expects only symbol keys. Also
85
+ # runs a simple parse on the string for some common types.
86
+ memo[key.to_sym] = YAML.safe_load(value)
87
+ memo
88
+ end
89
+ merge!(extra_parsed_options)
90
+ end
91
+ end
92
+
73
93
  # Config file to load (client.rb, knife.rb, etc. defaults set differently in knife, chef-client, etc.)
74
94
  configurable(:config_file)
75
95
 
@@ -837,7 +857,13 @@ module ChefConfig
837
857
  # Full URL to the endpoint that will receive our data. If nil, the
838
858
  # data collector will not run.
839
859
  # Ex: http://my-data-collector.mycompany.com/ingest
840
- default :server_url, nil
860
+ default(:server_url) do
861
+ if config_parent.solo || config_parent.local_mode
862
+ nil
863
+ else
864
+ File.join(config_parent.chef_server_url, "/data-collector")
865
+ end
866
+ end
841
867
 
842
868
  # An optional pre-shared token to pass as an HTTP header (x-data-collector-token)
843
869
  # that can be used to determine whether or not the poster of this
@@ -966,7 +992,7 @@ module ChefConfig
966
992
  # If there is no 'locale -a' then we return 'en_US.UTF-8' since that is the most commonly
967
993
  # available English UTF-8 locale. However, all modern POSIXen should support 'locale -a'.
968
994
  def self.guess_internal_locale
969
- # https://github.com/opscode/chef/issues/2181
995
+ # https://github.com/chef/chef/issues/2181
970
996
  # Some systems have the `locale -a` command, but the result has
971
997
  # invalid characters for the default encoding.
972
998
  #
@@ -22,5 +22,6 @@ module ChefConfig
22
22
 
23
23
  class ConfigurationError < ArgumentError; end
24
24
  class InvalidPath < StandardError; end
25
+ class UnparsableConfigOption < StandardError; end
25
26
 
26
27
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  module ChefConfig
23
23
  CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "12.15.19"
24
+ VERSION = "12.16.42"
25
25
  end
26
26
 
27
27
  #
@@ -68,6 +68,91 @@ RSpec.describe ChefConfig::Config do
68
68
  end
69
69
  end
70
70
 
71
+ describe "parsing arbitrary config from the CLI" do
72
+
73
+ def apply_config
74
+ described_class.apply_extra_config_options(extra_config_options)
75
+ end
76
+
77
+ context "when no arbitrary config is given" do
78
+
79
+ let(:extra_config_options) { nil }
80
+
81
+ it "succeeds" do
82
+ expect { apply_config }.to_not raise_error
83
+ end
84
+
85
+ end
86
+
87
+ context "when given a simple string option" do
88
+
89
+ let(:extra_config_options) { [ "node_name=bobotclown" ] }
90
+
91
+ it "applies the string option" do
92
+ apply_config
93
+ expect(described_class[:node_name]).to eq("bobotclown")
94
+ end
95
+
96
+ end
97
+
98
+ context "when given a blank value" do
99
+
100
+ let(:extra_config_options) { [ "http_retries=" ] }
101
+
102
+ it "sets the value to nil" do
103
+ # ensure the value is actually changed in the test
104
+ described_class[:http_retries] = 55
105
+ apply_config
106
+ expect(described_class[:http_retries]).to eq(nil)
107
+ end
108
+ end
109
+
110
+ context "when given spaces between `key = value`" do
111
+
112
+ let(:extra_config_options) { [ "node_name = bobo" ] }
113
+
114
+ it "handles the extra spaces and applies the config option" do
115
+ apply_config
116
+ expect(described_class[:node_name]).to eq("bobo")
117
+ end
118
+
119
+ end
120
+
121
+ context "when given an integer value" do
122
+
123
+ let(:extra_config_options) { [ "http_retries=9000" ] }
124
+
125
+ it "converts to a numeric type and applies the config option" do
126
+ apply_config
127
+ expect(described_class[:http_retries]).to eq(9000)
128
+ end
129
+
130
+ end
131
+
132
+ context "when given a boolean" do
133
+
134
+ let(:extra_config_options) { [ "boolean_thing=true" ] }
135
+
136
+ it "converts to a boolean type and applies the config option" do
137
+ apply_config
138
+ expect(described_class[:boolean_thing]).to eq(true)
139
+ end
140
+
141
+ end
142
+
143
+ context "when given input that is not in key=value form" do
144
+
145
+ let(:extra_config_options) { [ "http_retries:9000" ] }
146
+
147
+ it "raises UnparsableConfigOption" do
148
+ message = 'Unparsable config option "http_retries:9000"'
149
+ expect { apply_config }.to raise_error(ChefConfig::UnparsableConfigOption, message)
150
+ end
151
+
152
+ end
153
+
154
+ end
155
+
71
156
  describe "when configuring formatters" do
72
157
  # if TTY and not(force-logger)
73
158
  # formatter = configured formatter or default formatter
@@ -1042,4 +1127,34 @@ RSpec.describe ChefConfig::Config do
1042
1127
 
1043
1128
  end
1044
1129
 
1130
+ describe "data collector URL" do
1131
+
1132
+ context "when using default settings" do
1133
+
1134
+ context "for Chef Client" do
1135
+
1136
+ it "configures the data collector URL as a relative path to the Chef Server URL" do
1137
+ ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg"
1138
+ expect(ChefConfig::Config[:data_collector][:server_url]).to eq("https://chef.example/organizations/myorg/data-collector")
1139
+ end
1140
+
1141
+ end
1142
+
1143
+ context "for Chef Solo" do
1144
+
1145
+ before do
1146
+ ChefConfig::Config[:solo] = true
1147
+ end
1148
+
1149
+ it "sets the data collector server URL to nil" do
1150
+ ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg"
1151
+ expect(ChefConfig::Config[:data_collector][:server_url]).to be_nil
1152
+ end
1153
+
1154
+ end
1155
+
1156
+ end
1157
+
1158
+ end
1159
+
1045
1160
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.15.19
4
+ version: 12.16.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-07 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project:
173
- rubygems_version: 2.6.7
173
+ rubygems_version: 2.6.8
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Chef's default configuration and config loading