chef-config 17.10.0 → 17.10.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
1
- #
2
- # Copyright:: Copyright (c) Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require_relative "windows"
19
- require_relative "logger"
20
-
21
- module ChefConfig
22
-
23
- class ConfigurationError < ArgumentError; end
24
- class InvalidPath < StandardError; end
25
- class UnparsableConfigOption < StandardError; end
26
-
27
- end
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "windows"
19
+ require_relative "logger"
20
+
21
+ module ChefConfig
22
+
23
+ class ConfigurationError < ArgumentError; end
24
+ class InvalidPath < StandardError; end
25
+ class UnparsableConfigOption < StandardError; end
26
+
27
+ end
@@ -1,53 +1,53 @@
1
- #
2
- # Author:: Matt Wrock (<matt@mattwrock.com>)
3
- # Copyright:: Copyright (c) Chef Software Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "chef-utils" unless defined?(ChefUtils::CANARY)
20
-
21
- module ChefConfig
22
-
23
- def self.fips?
24
- if ChefUtils.windows?
25
- begin
26
- require "win32/registry" unless defined?(Win32::Registry)
27
- rescue LoadError
28
- return false
29
- end
30
-
31
- # from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
32
- reg_type =
33
- case ::RbConfig::CONFIG["target_cpu"]
34
- when "i386"
35
- Win32::Registry::KEY_READ | 0x100
36
- when "x86_64"
37
- Win32::Registry::KEY_READ | 0x200
38
- else
39
- Win32::Registry::KEY_READ
40
- end
41
- begin
42
- Win32::Registry::HKEY_LOCAL_MACHINE.open("System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy", reg_type) do |policy|
43
- policy["Enabled"] != 0
44
- end
45
- rescue Win32::Registry::Error
46
- false
47
- end
48
- else
49
- fips_path = "/proc/sys/crypto/fips_enabled"
50
- File.exist?(fips_path) && File.read(fips_path).chomp != "0"
51
- end
52
- end
53
- end
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef-utils" unless defined?(ChefUtils::CANARY)
20
+
21
+ module ChefConfig
22
+
23
+ def self.fips?
24
+ if ChefUtils.windows?
25
+ begin
26
+ require "win32/registry" unless defined?(Win32::Registry)
27
+ rescue LoadError
28
+ return false
29
+ end
30
+
31
+ # from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
32
+ reg_type =
33
+ case ::RbConfig::CONFIG["target_cpu"]
34
+ when "i386"
35
+ Win32::Registry::KEY_READ | 0x100
36
+ when "x86_64"
37
+ Win32::Registry::KEY_READ | 0x200
38
+ else
39
+ Win32::Registry::KEY_READ
40
+ end
41
+ begin
42
+ Win32::Registry::HKEY_LOCAL_MACHINE.open("System\\CurrentControlSet\\Control\\Lsa\\FIPSAlgorithmPolicy", reg_type) do |policy|
43
+ policy["Enabled"] != 0
44
+ end
45
+ rescue Win32::Registry::Error
46
+ false
47
+ end
48
+ else
49
+ fips_path = "/proc/sys/crypto/fips_enabled"
50
+ File.exist?(fips_path) && File.read(fips_path).chomp != "0"
51
+ end
52
+ end
53
+ end
@@ -1,53 +1,53 @@
1
- #
2
- # Copyright:: Copyright (c) Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- module ChefConfig
19
-
20
- # Implements enough of Logger's API that we can use it in place of a real
21
- # logger for `ChefConfig.logger`
22
- class NullLogger
23
-
24
- def <<(_msg); end
25
-
26
- def add(_severity, _message = nil, _progname = nil); end
27
-
28
- def trace(_progname = nil, &block); end
29
-
30
- def debug(_progname = nil, &block); end
31
-
32
- def info(_progname = nil, &block); end
33
-
34
- def warn(_progname = nil, &block); end
35
-
36
- def deprecation(_progname = nil, &block); end
37
-
38
- def error(_progname = nil, &block); end
39
-
40
- def fatal(_progname = nil, &block); end
41
-
42
- end
43
-
44
- @logger = NullLogger.new
45
-
46
- def self.logger=(new_logger)
47
- @logger = new_logger
48
- end
49
-
50
- def self.logger
51
- @logger
52
- end
53
- end
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module ChefConfig
19
+
20
+ # Implements enough of Logger's API that we can use it in place of a real
21
+ # logger for `ChefConfig.logger`
22
+ class NullLogger
23
+
24
+ def <<(_msg); end
25
+
26
+ def add(_severity, _message = nil, _progname = nil); end
27
+
28
+ def trace(_progname = nil, &block); end
29
+
30
+ def debug(_progname = nil, &block); end
31
+
32
+ def info(_progname = nil, &block); end
33
+
34
+ def warn(_progname = nil, &block); end
35
+
36
+ def deprecation(_progname = nil, &block); end
37
+
38
+ def error(_progname = nil, &block); end
39
+
40
+ def fatal(_progname = nil, &block); end
41
+
42
+ end
43
+
44
+ @logger = NullLogger.new
45
+
46
+ def self.logger=(new_logger)
47
+ @logger = new_logger
48
+ end
49
+
50
+ def self.logger
51
+ @logger
52
+ end
53
+ end
@@ -1,102 +1,102 @@
1
- #
2
- # Copyright:: Copyright (c) Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- autoload :Tomlrb, "tomlrb"
19
- require_relative "../path_helper"
20
- require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
-
22
- module ChefConfig
23
- module Mixin
24
- # Helper methods for working with credentials files.
25
- #
26
- # @since 13.7
27
- # @api internal
28
- module Credentials
29
- # Compute the active credentials profile name.
30
- #
31
- # The lookup order is argument (from --profile), environment variable
32
- # ($CHEF_PROFILE), context file (~/.chef/context), and then "default" as
33
- # a fallback.
34
- #
35
- # @since 14.4
36
- # @param profile [String, nil] Optional override for the active profile,
37
- # normally set via a command-line option.
38
- # @return [String]
39
- def credentials_profile(profile = nil)
40
- context_file = PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "context").freeze
41
- if !profile.nil?
42
- profile
43
- elsif ENV.include?("CHEF_PROFILE")
44
- ENV["CHEF_PROFILE"]
45
- elsif File.file?(context_file)
46
- File.read(context_file).strip
47
- else
48
- "default"
49
- end
50
- end
51
-
52
- # Compute the path to the credentials file.
53
- #
54
- # @since 14.4
55
- # @return [String]
56
- def credentials_file_path
57
- PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "credentials").freeze
58
- end
59
-
60
- # Load and parse the credentials file.
61
- #
62
- # Returns `nil` if the credentials file is unavailable.
63
- #
64
- # @since 14.4
65
- # @return [String, nil]
66
- def parse_credentials_file
67
- credentials_file = credentials_file_path
68
- return nil unless File.file?(credentials_file)
69
-
70
- begin
71
- Tomlrb.load_file(credentials_file)
72
- rescue => e
73
- # TOML's error messages are mostly rubbish, so we'll just give a generic one
74
- message = "Unable to parse Credentials file: #{credentials_file}\n"
75
- message << e.message
76
- raise ChefConfig::ConfigurationError, message
77
- end
78
- end
79
-
80
- # Load and process the active credentials.
81
- #
82
- # @see WorkstationConfigLoader#apply_credentials
83
- # @param profile [String, nil] Optional override for the active profile,
84
- # normally set via a command-line option.
85
- # @return [void]
86
- def load_credentials(profile = nil)
87
- profile = credentials_profile(profile)
88
- cred_config = parse_credentials_file
89
- return if cred_config.nil? # No credentials, nothing to do here.
90
-
91
- if cred_config[profile].nil?
92
- # Unknown profile name. For "default" just silently ignore, otherwise
93
- # raise an error.
94
- return if profile == "default"
95
-
96
- raise ChefConfig::ConfigurationError, "Profile #{profile} doesn't exist. Please add it to #{credentials_file_path}."
97
- end
98
- apply_credentials(cred_config[profile], profile)
99
- end
100
- end
101
- end
102
- end
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ autoload :Tomlrb, "tomlrb"
19
+ require_relative "../path_helper"
20
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
+
22
+ module ChefConfig
23
+ module Mixin
24
+ # Helper methods for working with credentials files.
25
+ #
26
+ # @since 13.7
27
+ # @api internal
28
+ module Credentials
29
+ # Compute the active credentials profile name.
30
+ #
31
+ # The lookup order is argument (from --profile), environment variable
32
+ # ($CHEF_PROFILE), context file (~/.chef/context), and then "default" as
33
+ # a fallback.
34
+ #
35
+ # @since 14.4
36
+ # @param profile [String, nil] Optional override for the active profile,
37
+ # normally set via a command-line option.
38
+ # @return [String]
39
+ def credentials_profile(profile = nil)
40
+ context_file = PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "context").freeze
41
+ if !profile.nil?
42
+ profile
43
+ elsif ENV.include?("CHEF_PROFILE")
44
+ ENV["CHEF_PROFILE"]
45
+ elsif File.file?(context_file)
46
+ File.read(context_file).strip
47
+ else
48
+ "default"
49
+ end
50
+ end
51
+
52
+ # Compute the path to the credentials file.
53
+ #
54
+ # @since 14.4
55
+ # @return [String]
56
+ def credentials_file_path
57
+ PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "credentials").freeze
58
+ end
59
+
60
+ # Load and parse the credentials file.
61
+ #
62
+ # Returns `nil` if the credentials file is unavailable.
63
+ #
64
+ # @since 14.4
65
+ # @return [String, nil]
66
+ def parse_credentials_file
67
+ credentials_file = credentials_file_path
68
+ return nil unless File.file?(credentials_file)
69
+
70
+ begin
71
+ Tomlrb.load_file(credentials_file)
72
+ rescue => e
73
+ # TOML's error messages are mostly rubbish, so we'll just give a generic one
74
+ message = "Unable to parse Credentials file: #{credentials_file}\n"
75
+ message << e.message
76
+ raise ChefConfig::ConfigurationError, message
77
+ end
78
+ end
79
+
80
+ # Load and process the active credentials.
81
+ #
82
+ # @see WorkstationConfigLoader#apply_credentials
83
+ # @param profile [String, nil] Optional override for the active profile,
84
+ # normally set via a command-line option.
85
+ # @return [void]
86
+ def load_credentials(profile = nil)
87
+ profile = credentials_profile(profile)
88
+ cred_config = parse_credentials_file
89
+ return if cred_config.nil? # No credentials, nothing to do here.
90
+
91
+ if cred_config[profile].nil?
92
+ # Unknown profile name. For "default" just silently ignore, otherwise
93
+ # raise an error.
94
+ return if profile == "default"
95
+
96
+ raise ChefConfig::ConfigurationError, "Profile #{profile} doesn't exist. Please add it to #{credentials_file_path}."
97
+ end
98
+ apply_credentials(cred_config[profile], profile)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,44 +1,44 @@
1
- #
2
- # Copyright:: Copyright (c) Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require_relative "../path_helper"
18
-
19
- module ChefConfig
20
- module Mixin
21
- module DotD
22
- # Find available configuration files in a `.d/` style include directory.
23
- # Make sure we exclude anything that's not a file so we avoid directories ending in .rb (just in case)
24
- #
25
- # @api internal
26
- # @param path [String] Base .d/ path to load from.
27
- # @return [Array<String>]
28
- def find_dot_d(path)
29
- Dir["#{PathHelper.escape_glob_dir(path)}/*.rb"].select { |entry| File.file?(entry) }.sort
30
- end
31
-
32
- # Load configuration from a `.d/` style include directory.
33
- #
34
- # @api internal
35
- # @param path [String] Base .d/ path to load from.
36
- # @return [void]
37
- def load_dot_d(path)
38
- find_dot_d(path).each do |conf|
39
- apply_config(IO.read(conf), conf)
40
- end
41
- end
42
- end
43
- end
44
- end
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative "../path_helper"
18
+
19
+ module ChefConfig
20
+ module Mixin
21
+ module DotD
22
+ # Find available configuration files in a `.d/` style include directory.
23
+ # Make sure we exclude anything that's not a file so we avoid directories ending in .rb (just in case)
24
+ #
25
+ # @api internal
26
+ # @param path [String] Base .d/ path to load from.
27
+ # @return [Array<String>]
28
+ def find_dot_d(path)
29
+ Dir["#{PathHelper.escape_glob_dir(path)}/*.rb"].select { |entry| File.file?(entry) }.sort
30
+ end
31
+
32
+ # Load configuration from a `.d/` style include directory.
33
+ #
34
+ # @api internal
35
+ # @param path [String] Base .d/ path to load from.
36
+ # @return [void]
37
+ def load_dot_d(path)
38
+ find_dot_d(path).each do |conf|
39
+ apply_config(IO.read(conf), conf)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,49 +1,49 @@
1
- #
2
- # Copyright:: Copyright (c) Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require "fuzzyurl"
18
-
19
- module ChefConfig
20
- module Mixin
21
- module FuzzyHostnameMatcher
22
-
23
- #
24
- # Check to see if a hostname matches a match string. Used to see if hosts fall under our no_proxy config
25
- #
26
- # @param [String] hostname the hostname to check
27
- # @param [String] matches the pattern to match
28
- #
29
- # @return [Boolean]
30
- #
31
- def fuzzy_hostname_match_any?(hostname, matches)
32
- if hostname && matches
33
- return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
34
- fuzzy_hostname_match?(hostname, m)
35
- end
36
- end
37
-
38
- false
39
- end
40
-
41
- def fuzzy_hostname_match?(hostname, match)
42
- # Do greedy matching by adding wildcard if it is not specified
43
- match = "*" + match unless match.start_with?("*")
44
- Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
45
- end
46
-
47
- end
48
- end
49
- end
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "fuzzyurl"
18
+
19
+ module ChefConfig
20
+ module Mixin
21
+ module FuzzyHostnameMatcher
22
+
23
+ #
24
+ # Check to see if a hostname matches a match string. Used to see if hosts fall under our no_proxy config
25
+ #
26
+ # @param [String] hostname the hostname to check
27
+ # @param [String] matches the pattern to match
28
+ #
29
+ # @return [Boolean]
30
+ #
31
+ def fuzzy_hostname_match_any?(hostname, matches)
32
+ if hostname && matches
33
+ return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
34
+ fuzzy_hostname_match?(hostname, m)
35
+ end
36
+ end
37
+
38
+ false
39
+ end
40
+
41
+ def fuzzy_hostname_match?(hostname, match)
42
+ # Do greedy matching by adding wildcard if it is not specified
43
+ match = "*" + match unless match.start_with?("*")
44
+ Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
45
+ end
46
+
47
+ end
48
+ end
49
+ end