chef-config 12.5.1 → 12.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/chef-config.gemspec +32 -0
- data/lib/chef-config/config.rb +75 -2
- data/lib/chef-config/version.rb +1 -1
- data/spec/unit/config_spec.rb +129 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657659650232e1f20d20c8cceda2319dbbee9275
|
4
|
+
data.tar.gz: 5f0cae5b96b02972dad1c301fd519d74f0ad65dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe4c7d72f78259fffa316f4702f76a6fe3e7bf56c4e144f987eab0006b791f379514e4d53ec3ad90024cc8545722be3e04cc221dbd21d4d930e958f5c8d7ef4
|
7
|
+
data.tar.gz: b5c0b623957b8b30a3e75631fb7f96d9780cda43cbef580467cbad299714633a97d50649dba996e13117115cd09b870a926d49ec894bc4ae1809362a5bedcd1d
|
data/chef-config.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef-config/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chef-config"
|
8
|
+
spec.version = ChefConfig::VERSION
|
9
|
+
spec.authors = ["Adam Jacob"]
|
10
|
+
spec.email = ["adam@chef.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Chef's default configuration and config loading}
|
13
|
+
spec.homepage = "https://github.com/chef/chef"
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "mixlib-shellout", "~> 2.0"
|
19
|
+
spec.add_dependency "mixlib-config", "~> 2.0"
|
20
|
+
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
|
23
|
+
%w(rspec-core rspec-expectations rspec-mocks).each do |rspec|
|
24
|
+
spec.add_development_dependency(rspec, "~> 3.2")
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = %w(Rakefile LICENSE README.md) + Dir.glob("*.gemspec") +
|
28
|
+
Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
|
29
|
+
|
30
|
+
spec.bindir = "bin"
|
31
|
+
spec.executables = []
|
32
|
+
end
|
data/lib/chef-config/config.rb
CHANGED
@@ -26,6 +26,7 @@ require 'chef-config/logger'
|
|
26
26
|
require 'chef-config/windows'
|
27
27
|
require 'chef-config/path_helper'
|
28
28
|
require 'mixlib/shellout'
|
29
|
+
require 'uri'
|
29
30
|
|
30
31
|
module ChefConfig
|
31
32
|
|
@@ -76,12 +77,21 @@ module ChefConfig
|
|
76
77
|
|
77
78
|
default :formatters, []
|
78
79
|
|
80
|
+
def self.is_valid_url? uri
|
81
|
+
url = uri.to_s.strip
|
82
|
+
/^http:\/\// =~ url || /^https:\/\// =~ url || /^chefzero:/ =~ url
|
83
|
+
end
|
79
84
|
# Override the config dispatch to set the value of multiple server options simultaneously
|
80
85
|
#
|
81
86
|
# === Parameters
|
82
87
|
# url<String>:: String to be set for all of the chef-server-api URL's
|
83
88
|
#
|
84
|
-
configurable(:chef_server_url).writes_value
|
89
|
+
configurable(:chef_server_url).writes_value do |uri|
|
90
|
+
unless is_valid_url? uri
|
91
|
+
raise ConfigurationError, "#{uri} is an invalid chef_server_url."
|
92
|
+
end
|
93
|
+
uri.to_s.strip
|
94
|
+
end
|
85
95
|
|
86
96
|
# When you are using ActiveSupport, they monkey-patch 'daemonize' into Kernel.
|
87
97
|
# So while this is basically identical to what method_missing would do, we pull
|
@@ -271,6 +281,9 @@ module ChefConfig
|
|
271
281
|
# Using `force_logger` causes chef to default to logger output when STDOUT is a tty
|
272
282
|
default :force_logger, false
|
273
283
|
|
284
|
+
# Using 'stream_execute_output' will have Chef always stream the execute output
|
285
|
+
default :stream_execute_output, false
|
286
|
+
|
274
287
|
default :http_retry_count, 5
|
275
288
|
default :http_retry_delay, 5
|
276
289
|
default :interval, nil
|
@@ -300,7 +313,7 @@ module ChefConfig
|
|
300
313
|
default :host, 'localhost'
|
301
314
|
default :port, 8889.upto(9999) # Will try ports from 8889-9999 until one works
|
302
315
|
end
|
303
|
-
default :chef_server_url,
|
316
|
+
default :chef_server_url, "https://localhost:443"
|
304
317
|
|
305
318
|
default(:chef_server_root) do
|
306
319
|
# if the chef_server_url is a path to an organization, aka
|
@@ -698,6 +711,66 @@ module ChefConfig
|
|
698
711
|
config_context :chefdk do
|
699
712
|
end
|
700
713
|
|
714
|
+
configurable(:http_proxy)
|
715
|
+
configurable(:http_proxy_user)
|
716
|
+
configurable(:http_proxy_pass)
|
717
|
+
configurable(:https_proxy)
|
718
|
+
configurable(:https_proxy_user)
|
719
|
+
configurable(:https_proxy_pass)
|
720
|
+
configurable(:ftp_proxy)
|
721
|
+
configurable(:ftp_proxy_user)
|
722
|
+
configurable(:ftp_proxy_pass)
|
723
|
+
configurable(:no_proxy)
|
724
|
+
|
725
|
+
# Public method that users should call to export proxies to the appropriate
|
726
|
+
# environment variables. This method should be called after the config file is
|
727
|
+
# parsed and loaded.
|
728
|
+
# TODO add some post-file-parsing logic that automatically calls this so
|
729
|
+
# users don't have to
|
730
|
+
def self.export_proxies
|
731
|
+
export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if http_proxy
|
732
|
+
export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if https_proxy
|
733
|
+
export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if ftp_proxy
|
734
|
+
export_no_proxy(no_proxy) if no_proxy
|
735
|
+
end
|
736
|
+
|
737
|
+
# Builds a proxy uri and exports it to the appropriate environment variables. Examples:
|
738
|
+
# http://username:password@hostname:port
|
739
|
+
# https://username@hostname:port
|
740
|
+
# ftp://hostname:port
|
741
|
+
# when
|
742
|
+
# scheme = "http", "https", or "ftp"
|
743
|
+
# hostport = hostname:port or scheme://hostname:port
|
744
|
+
# user = username
|
745
|
+
# pass = password
|
746
|
+
# @api private
|
747
|
+
def self.export_proxy(scheme, path, user, pass)
|
748
|
+
path = "#{scheme}://#{path}" unless path.include?('://')
|
749
|
+
# URI.split returns the following parts:
|
750
|
+
# [scheme, userinfo, host, port, registry, path, opaque, query, fragment]
|
751
|
+
parts = URI.split(URI.encode(path))
|
752
|
+
# URI::Generic.build requires an integer for the port, but URI::split gives
|
753
|
+
# returns a string for the port.
|
754
|
+
parts[3] = parts[3].to_i if parts[3]
|
755
|
+
if user && !user.empty?
|
756
|
+
userinfo = URI.encode(URI.encode(user), '@:')
|
757
|
+
if pass
|
758
|
+
userinfo << ":#{URI.encode(URI.encode(pass), '@:')}"
|
759
|
+
end
|
760
|
+
parts[1] = userinfo
|
761
|
+
end
|
762
|
+
|
763
|
+
path = URI::Generic.build(parts).to_s
|
764
|
+
ENV["#{scheme}_proxy".downcase] = path unless ENV["#{scheme}_proxy".downcase]
|
765
|
+
ENV["#{scheme}_proxy".upcase] = path unless ENV["#{scheme}_proxy".upcase]
|
766
|
+
end
|
767
|
+
|
768
|
+
# @api private
|
769
|
+
def self.export_no_proxy(value)
|
770
|
+
ENV['no_proxy'] = value unless ENV['no_proxy']
|
771
|
+
ENV['NO_PROXY'] = value unless ENV['NO_PROXY']
|
772
|
+
end
|
773
|
+
|
701
774
|
# Chef requires an English-language UTF-8 locale to function properly. We attempt
|
702
775
|
# to use the 'locale -a' command and search through a list of preferences until we
|
703
776
|
# find one that we can use. On Ubuntu systems we should find 'C.UTF-8' and be
|
data/lib/chef-config/version.rb
CHANGED
data/spec/unit/config_spec.rb
CHANGED
@@ -60,6 +60,12 @@ RSpec.describe ChefConfig::Config do
|
|
60
60
|
expect(ChefConfig::Config.chef_server_url).to eq("https://junglist.gen.nz")
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
context "when the url is invalid" do
|
65
|
+
it "raises an exception" do
|
66
|
+
expect { ChefConfig::Config.chef_server_url = "127.0.0.1" }.to raise_error(ChefConfig::ConfigurationError)
|
67
|
+
end
|
68
|
+
end
|
63
69
|
end
|
64
70
|
|
65
71
|
describe "when configuring formatters" do
|
@@ -264,6 +270,10 @@ RSpec.describe ChefConfig::Config do
|
|
264
270
|
end
|
265
271
|
end
|
266
272
|
|
273
|
+
it "ChefConfig::Config[:stream_execute_output] defaults to false" do
|
274
|
+
expect(ChefConfig::Config[:stream_execute_output]).to eq(false)
|
275
|
+
end
|
276
|
+
|
267
277
|
it "ChefConfig::Config[:file_backup_path] defaults to /var/chef/backup" do
|
268
278
|
allow(ChefConfig::Config).to receive(:cache_path).and_return(primary_cache_path)
|
269
279
|
backup_path = is_windows ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
|
@@ -561,6 +571,125 @@ RSpec.describe ChefConfig::Config do
|
|
561
571
|
end
|
562
572
|
end
|
563
573
|
|
574
|
+
describe "export_proxies" do
|
575
|
+
let(:http_proxy) { "http://localhost:7979" }
|
576
|
+
let(:https_proxy) { "https://localhost:7979" }
|
577
|
+
let(:ftp_proxy) { "ftp://localhost:7979" }
|
578
|
+
let(:proxy_user) { "http_user" }
|
579
|
+
let(:proxy_pass) { "http_pass" }
|
580
|
+
|
581
|
+
context "when http_proxy, proxy_pass and proxy_user are set" do
|
582
|
+
before do
|
583
|
+
ChefConfig::Config.http_proxy = http_proxy
|
584
|
+
ChefConfig::Config.http_proxy_user = proxy_user
|
585
|
+
ChefConfig::Config.http_proxy_pass = proxy_pass
|
586
|
+
end
|
587
|
+
it "exports ENV['http_proxy']" do
|
588
|
+
expect(ENV).to receive(:[]=).with('http_proxy', "http://http_user:http_pass@localhost:7979")
|
589
|
+
expect(ENV).to receive(:[]=).with('HTTP_PROXY', "http://http_user:http_pass@localhost:7979")
|
590
|
+
ChefConfig::Config.export_proxies
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
context "when https_proxy, proxy_pass and proxy_user are set" do
|
595
|
+
before do
|
596
|
+
ChefConfig::Config.https_proxy = https_proxy
|
597
|
+
ChefConfig::Config.https_proxy_user = proxy_user
|
598
|
+
ChefConfig::Config.https_proxy_pass = proxy_pass
|
599
|
+
end
|
600
|
+
it "exports ENV['https_proxy']" do
|
601
|
+
expect(ENV).to receive(:[]=).with('https_proxy', "https://http_user:http_pass@localhost:7979")
|
602
|
+
expect(ENV).to receive(:[]=).with('HTTPS_PROXY', "https://http_user:http_pass@localhost:7979")
|
603
|
+
ChefConfig::Config.export_proxies
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
context "when ftp_proxy, proxy_pass and proxy_user are set" do
|
608
|
+
before do
|
609
|
+
ChefConfig::Config.ftp_proxy = ftp_proxy
|
610
|
+
ChefConfig::Config.ftp_proxy_user = proxy_user
|
611
|
+
ChefConfig::Config.ftp_proxy_pass = proxy_pass
|
612
|
+
end
|
613
|
+
it "exports ENV['ftp_proxy']" do
|
614
|
+
expect(ENV).to receive(:[]=).with('ftp_proxy', "ftp://http_user:http_pass@localhost:7979")
|
615
|
+
expect(ENV).to receive(:[]=).with('FTP_PROXY', "ftp://http_user:http_pass@localhost:7979")
|
616
|
+
ChefConfig::Config.export_proxies
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
shared_examples "no user pass" do
|
621
|
+
it "does not populate the user or password" do
|
622
|
+
expect(ENV).to receive(:[]=).with('http_proxy', "http://localhost:7979")
|
623
|
+
expect(ENV).to receive(:[]=).with('HTTP_PROXY', "http://localhost:7979")
|
624
|
+
ChefConfig::Config.export_proxies
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
context "when proxy_pass and proxy_user are passed as empty strings" do
|
629
|
+
before do
|
630
|
+
ChefConfig::Config.http_proxy = http_proxy
|
631
|
+
ChefConfig::Config.http_proxy_user = ""
|
632
|
+
ChefConfig::Config.http_proxy_pass = proxy_pass
|
633
|
+
end
|
634
|
+
include_examples "no user pass"
|
635
|
+
end
|
636
|
+
|
637
|
+
context "when proxy_pass and proxy_user are not provided" do
|
638
|
+
before do
|
639
|
+
ChefConfig::Config.http_proxy = http_proxy
|
640
|
+
end
|
641
|
+
include_examples "no user pass"
|
642
|
+
end
|
643
|
+
|
644
|
+
context "when the proxy is provided without a scheme" do
|
645
|
+
before do
|
646
|
+
ChefConfig::Config.http_proxy = "localhost:1111"
|
647
|
+
end
|
648
|
+
it "automatically adds the scheme to the proxy url" do
|
649
|
+
expect(ENV).to receive(:[]=).with('http_proxy', "http://localhost:1111")
|
650
|
+
expect(ENV).to receive(:[]=).with('HTTP_PROXY', "http://localhost:1111")
|
651
|
+
ChefConfig::Config.export_proxies
|
652
|
+
end
|
653
|
+
end
|
654
|
+
|
655
|
+
shared_examples "no export" do
|
656
|
+
it "does not export any proxy settings" do
|
657
|
+
ChefConfig::Config.export_proxies
|
658
|
+
expect(ENV['http_proxy']).to eq(nil)
|
659
|
+
expect(ENV['https_proxy']).to eq(nil)
|
660
|
+
expect(ENV['ftp_proxy']).to eq(nil)
|
661
|
+
expect(ENV['no_proxy']).to eq(nil)
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
context "when nothing is set" do
|
666
|
+
include_examples "no export"
|
667
|
+
end
|
668
|
+
|
669
|
+
context "when all the users and passwords are set but no proxies are set" do
|
670
|
+
before do
|
671
|
+
ChefConfig::Config.http_proxy_user = proxy_user
|
672
|
+
ChefConfig::Config.http_proxy_pass = proxy_pass
|
673
|
+
ChefConfig::Config.https_proxy_user = proxy_user
|
674
|
+
ChefConfig::Config.https_proxy_pass = proxy_pass
|
675
|
+
ChefConfig::Config.ftp_proxy_user = proxy_user
|
676
|
+
ChefConfig::Config.ftp_proxy_pass = proxy_pass
|
677
|
+
end
|
678
|
+
include_examples "no export"
|
679
|
+
end
|
680
|
+
|
681
|
+
context "no_proxy is set" do
|
682
|
+
before do
|
683
|
+
ChefConfig::Config.no_proxy = "localhost"
|
684
|
+
end
|
685
|
+
it "exports ENV['no_proxy']" do
|
686
|
+
expect(ENV).to receive(:[]=).with('no_proxy', "localhost")
|
687
|
+
expect(ENV).to receive(:[]=).with('NO_PROXY', "localhost")
|
688
|
+
ChefConfig::Config.export_proxies
|
689
|
+
end
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
564
693
|
describe "allowing chefdk configuration outside of chefdk" do
|
565
694
|
|
566
695
|
it "allows arbitrary settings in the chefdk config context" do
|
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.
|
4
|
+
version: 12.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- LICENSE
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
107
|
+
- chef-config.gemspec
|
107
108
|
- lib/chef-config.rb
|
108
109
|
- lib/chef-config/config.rb
|
109
110
|
- lib/chef-config/exceptions.rb
|