chef 17.3.48-universal-mingw32 → 17.6.15-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/chef.gemspec +2 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +1 -2
  7. data/lib/chef/compliance/default_attributes.rb +5 -3
  8. data/lib/chef/compliance/input.rb +115 -0
  9. data/lib/chef/compliance/input_collection.rb +139 -0
  10. data/lib/chef/compliance/profile.rb +122 -0
  11. data/lib/chef/compliance/profile_collection.rb +109 -0
  12. data/lib/chef/compliance/reporter/automate.rb +1 -1
  13. data/lib/chef/compliance/runner.rb +62 -6
  14. data/lib/chef/compliance/waiver.rb +115 -0
  15. data/lib/chef/compliance/waiver_collection.rb +143 -0
  16. data/lib/chef/dsl/compliance.rb +38 -0
  17. data/lib/chef/dsl/reader_helpers.rb +51 -0
  18. data/lib/chef/dsl/recipe.rb +4 -2
  19. data/lib/chef/dsl/secret.rb +5 -7
  20. data/lib/chef/dsl/universal.rb +2 -0
  21. data/lib/chef/event_dispatch/base.rb +44 -2
  22. data/lib/chef/exceptions.rb +0 -2
  23. data/lib/chef/formatters/doc.rb +60 -13
  24. data/lib/chef/formatters/error_mapper.rb +2 -2
  25. data/lib/chef/formatters/minimal.rb +6 -5
  26. data/lib/chef/http/basic_client.rb +15 -7
  27. data/lib/chef/http.rb +12 -8
  28. data/lib/chef/provider/execute.rb +1 -1
  29. data/lib/chef/provider/file.rb +2 -0
  30. data/lib/chef/provider/group/dscl.rb +1 -1
  31. data/lib/chef/provider/launchd.rb +6 -6
  32. data/lib/chef/provider/link.rb +2 -2
  33. data/lib/chef/provider/registry_key.rb +3 -2
  34. data/lib/chef/provider/remote_file/http.rb +1 -1
  35. data/lib/chef/provider/subversion.rb +4 -4
  36. data/lib/chef/provider/support/yum_repo.erb +1 -1
  37. data/lib/chef/provider/systemd_unit.rb +17 -16
  38. data/lib/chef/provider/template.rb +1 -1
  39. data/lib/chef/provider/user/mac.rb +3 -3
  40. data/lib/chef/provider/yum_repository.rb +27 -43
  41. data/lib/chef/provider/zypper_repository.rb +3 -3
  42. data/lib/chef/provider.rb +26 -1
  43. data/lib/chef/provider_resolver.rb +8 -2
  44. data/lib/chef/resource/archive_file.rb +17 -14
  45. data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
  46. data/lib/chef/resource/chocolatey_config.rb +13 -13
  47. data/lib/chef/resource/execute.rb +2 -2
  48. data/lib/chef/resource/file/verification/json.rb +50 -0
  49. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  50. data/lib/chef/resource/homebrew_cask.rb +1 -1
  51. data/lib/chef/resource/inspec_input.rb +127 -0
  52. data/lib/chef/resource/inspec_waiver.rb +184 -0
  53. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  54. data/lib/chef/resource/launchd.rb +3 -3
  55. data/lib/chef/resource/mount.rb +1 -1
  56. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  57. data/lib/chef/resource/powershell_package_source.rb +234 -70
  58. data/lib/chef/resource/registry_key.rb +36 -48
  59. data/lib/chef/resource/remote_file.rb +99 -3
  60. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  61. data/lib/chef/resource/ruby_block.rb +100 -0
  62. data/lib/chef/resource/scm/subversion.rb +1 -1
  63. data/lib/chef/resource/sysctl.rb +2 -2
  64. data/lib/chef/resource/systemd_unit.rb +3 -3
  65. data/lib/chef/resource/timezone.rb +2 -2
  66. data/lib/chef/resource/user_ulimit.rb +1 -0
  67. data/lib/chef/resource/windows_printer.rb +1 -1
  68. data/lib/chef/resource/windows_uac.rb +3 -1
  69. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  70. data/lib/chef/resource/yum_package.rb +1 -5
  71. data/lib/chef/resource.rb +13 -17
  72. data/lib/chef/resource_inspector.rb +6 -2
  73. data/lib/chef/resources.rb +2 -0
  74. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  75. data/lib/chef/run_context.rb +31 -1
  76. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  77. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +17 -5
  78. data/lib/chef/secret_fetcher/azure_key_vault.rb +32 -10
  79. data/lib/chef/secret_fetcher/base.rb +6 -2
  80. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  81. data/lib/chef/secret_fetcher.rb +13 -6
  82. data/lib/chef/version.rb +1 -1
  83. data/lib/chef/win32/version.rb +2 -1
  84. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  85. data/spec/functional/resource/archive_file_spec.rb +87 -0
  86. data/spec/functional/resource/group_spec.rb +5 -1
  87. data/spec/functional/resource/link_spec.rb +8 -0
  88. data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
  89. data/spec/integration/compliance/compliance_spec.rb +61 -0
  90. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  91. data/spec/spec_helper.rb +3 -0
  92. data/spec/support/platform_helpers.rb +4 -0
  93. data/spec/support/ruby_installer.rb +51 -0
  94. data/spec/unit/compliance/input_spec.rb +104 -0
  95. data/spec/unit/compliance/profile_spec.rb +120 -0
  96. data/spec/unit/compliance/runner_spec.rb +46 -2
  97. data/spec/unit/compliance/waiver_spec.rb +104 -0
  98. data/spec/unit/dsl/secret_spec.rb +8 -2
  99. data/spec/unit/formatters/doc_spec.rb +1 -1
  100. data/spec/unit/http/basic_client_spec.rb +30 -0
  101. data/spec/unit/http_spec.rb +8 -2
  102. data/spec/unit/provider/link_spec.rb +13 -7
  103. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  104. data/spec/unit/provider/template_spec.rb +2 -2
  105. data/spec/unit/provider_spec.rb +23 -0
  106. data/spec/unit/resource/archive_file_spec.rb +414 -3
  107. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  108. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  109. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  110. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  111. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  112. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  113. data/spec/unit/resource/mount_spec.rb +10 -0
  114. data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
  115. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  116. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  117. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  118. data/spec/unit/resource_spec.rb +19 -8
  119. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  120. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  121. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +23 -16
  122. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  123. data/spec/unit/secret_fetcher_spec.rb +9 -9
  124. data/tasks/rspec.rb +2 -1
  125. metadata +61 -6
@@ -12,6 +12,8 @@ class Chef
12
12
 
13
13
  attr_accessor :run_id
14
14
  attr_reader :node
15
+ attr_reader :run_context
16
+
15
17
  def_delegators :node, :logger
16
18
 
17
19
  def enabled?
@@ -25,7 +27,9 @@ class Chef
25
27
  logger.debug("#{self.class}##{__method__}: audit cookbook? #{audit_cookbook_present}")
26
28
  logger.debug("#{self.class}##{__method__}: compliance phase attr? #{node["audit"]["compliance_phase"]}")
27
29
 
28
- if node["audit"]["compliance_phase"].nil?
30
+ if safe_profile_collection&.using_profiles?
31
+ true
32
+ elsif node["audit"]["compliance_phase"].nil?
29
33
  inspec_profiles.any? && !audit_cookbook_present
30
34
  else
31
35
  node["audit"]["compliance_phase"]
@@ -41,6 +45,14 @@ class Chef
41
45
  self.node = node
42
46
  end
43
47
 
48
+ # This hook gives us the run_context immediately after it is created so that we can wire up this object to it.
49
+ #
50
+ # (see EventDispatch::Base#)
51
+ #
52
+ def cookbook_compilation_start(run_context)
53
+ @run_context = run_context
54
+ end
55
+
44
56
  def run_started(run_status)
45
57
  self.run_id = run_status.run_id
46
58
  end
@@ -113,8 +125,25 @@ class Chef
113
125
  logger.info "Chef Infra Compliance Phase Complete"
114
126
  end
115
127
 
128
+ def inputs_from_attributes
129
+ if !node["audit"]["inputs"].empty?
130
+ node["audit"]["inputs"].to_h
131
+ else
132
+ node["audit"]["attributes"].to_h
133
+ end
134
+ end
135
+
136
+ def inputs_from_collection
137
+ safe_input_collection&.inspec_data || {}
138
+ end
139
+
140
+ def waivers_from_collection
141
+ safe_waiver_collection&.inspec_data || {}
142
+ end
143
+
116
144
  def inspec_opts
117
- inputs = node["audit"]["attributes"].to_h
145
+ inputs = inputs_from_attributes.merge(inputs_from_collection).merge(waivers_from_collection)
146
+
118
147
  if node["audit"]["chef_node_attribute_enabled"]
119
148
  inputs["chef_node"] = node.to_h
120
149
  inputs["chef_node"]["chef_environment"] = node.chef_environment
@@ -124,24 +153,34 @@ class Chef
124
153
  backend_cache: node["audit"]["inspec_backend_cache"],
125
154
  inputs: inputs,
126
155
  logger: logger,
156
+ # output: STDOUT,
127
157
  output: node["audit"]["quiet"] ? ::File::NULL : STDOUT,
128
158
  report: true,
129
159
  reporter: ["json-automate"],
160
+ # reporter: ["cli"],
130
161
  reporter_backtrace_inclusion: node["audit"]["result_include_backtrace"],
131
162
  reporter_message_truncation: node["audit"]["result_message_limit"],
132
- waiver_file: Array(node["audit"]["waiver_file"]),
163
+ waiver_file: waiver_files,
133
164
  }
134
165
  end
135
166
 
167
+ def waiver_files
168
+ Array(node["audit"]["waiver_file"])
169
+ end
170
+
136
171
  def inspec_profiles
137
172
  profiles = node["audit"]["profiles"]
138
173
  unless profiles.respond_to?(:map) && profiles.all? { |_, p| p.respond_to?(:transform_keys) && p.respond_to?(:update) }
139
174
  raise "CMPL010: #{Inspec::Dist::PRODUCT_NAME} profiles specified in an unrecognized format, expected a hash of hashes."
140
175
  end
141
176
 
142
- profiles.map do |name, profile|
177
+ from_attributes = profiles.map do |name, profile|
143
178
  profile.transform_keys(&:to_sym).update(name: name)
144
- end
179
+ end || []
180
+
181
+ from_cookbooks = safe_profile_collection&.inspec_data || []
182
+
183
+ from_attributes + from_cookbooks
145
184
  end
146
185
 
147
186
  def load_fetchers!
@@ -171,7 +210,7 @@ class Chef
171
210
  logger.info "Running profiles from: #{profiles.inspect}"
172
211
  runner.run
173
212
  runner.report.tap do |r|
174
- logger.debug "Compliance Report #{r}"
213
+ logger.debug "Compliance Phase report #{r}"
175
214
  end
176
215
  rescue Inspec::FetcherFailure => e
177
216
  failed_report("Cannot fetch all profiles: #{profiles}. Please make sure you're authenticated and the server is reachable. #{e.message}")
@@ -300,8 +339,25 @@ class Chef
300
339
  raise "CMPL002: Unrecognized Compliance Phase fetcher (node['audit']['fetcher'] = #{fetcher}). Supported fetchers are: #{SUPPORTED_FETCHERS.join(", ")}, or nil. For more information, see the documentation at https://docs.chef.io/chef_compliance_phase#fetch-profiles"
301
340
  end
302
341
  end
342
+
343
+ if !node["audit"]["attributes"].empty? && !node["audit"]["inputs"].empty?
344
+ raise "CMPL011: both node['audit']['inputs'] and node['audit']['attributes'] are set. The node['audit']['attributes'] setting is deprecated and should not be used."
345
+ end
346
+
303
347
  @validation_passed = true
304
348
  end
349
+
350
+ def safe_profile_collection
351
+ run_context&.profile_collection
352
+ end
353
+
354
+ def safe_waiver_collection
355
+ run_context&.waiver_collection
356
+ end
357
+
358
+ def safe_input_collection
359
+ run_context&.input_collection
360
+ end
305
361
  end
306
362
  end
307
363
  end
@@ -0,0 +1,115 @@
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 "yaml"
19
+
20
+ class Chef
21
+ module Compliance
22
+ #
23
+ # Chef object that represents a single waiver file in the compliance
24
+ # segment of a cookbook
25
+ #
26
+ class Waiver
27
+ # @return [Boolean] if the waiver has been enabled
28
+ attr_reader :enabled
29
+
30
+ # @return [String] The name of the cookbook that the waiver is in
31
+ attr_reader :cookbook_name
32
+
33
+ # @return [String] The full path on the host to the waiver yml file
34
+ attr_reader :path
35
+
36
+ # @return [String] the pathname in the cookbook
37
+ attr_reader :pathname
38
+
39
+ # @api private
40
+ attr_reader :data
41
+
42
+ # Event dispatcher for this run.
43
+ #
44
+ # @return [Chef::EventDispatch::Dispatcher]
45
+ #
46
+ attr_accessor :events
47
+
48
+ def initialize(events, data, path, cookbook_name)
49
+ @events = events
50
+ @data = data
51
+ @cookbook_name = cookbook_name
52
+ @path = path
53
+ @pathname = File.basename(path, File.extname(path)) unless path.nil?
54
+ disable!
55
+ end
56
+
57
+ # @return [Boolean] if the waiver has been enabled
58
+ #
59
+ def enabled?
60
+ !!@enabled
61
+ end
62
+
63
+ # Set the waiver to being enabled
64
+ #
65
+ def enable!
66
+ events.compliance_waiver_enabled(self)
67
+ @enabled = true
68
+ end
69
+
70
+ # Set the waiver as being disabled
71
+ #
72
+ def disable!
73
+ @enabled = false
74
+ end
75
+
76
+ # Render the waiver in a way that it can be consumed by inspec
77
+ #
78
+ def inspec_data
79
+ data
80
+ end
81
+
82
+ HIDDEN_IVARS = [ :@events ].freeze
83
+
84
+ # Omit the event object from error output
85
+ #
86
+ def inspect
87
+ ivar_string = (instance_variables.map(&:to_sym) - HIDDEN_IVARS).map do |ivar|
88
+ "#{ivar}=#{instance_variable_get(ivar).inspect}"
89
+ end.join(", ")
90
+ "#<#{self.class}:#{object_id} #{ivar_string}>"
91
+ end
92
+
93
+ # Helper to construct a waiver object from a hash. Since the path and
94
+ # cookbook_name are required this is probably not externally useful.
95
+ #
96
+ def self.from_hash(events, hash, path = nil, cookbook_name = nil)
97
+ new(events, hash, path, cookbook_name)
98
+ end
99
+
100
+ # Helper to construct a waiver object from a yaml string. Since the path
101
+ # and cookbook_name are required this is probably not externally useful.
102
+ #
103
+ def self.from_yaml(events, string, path = nil, cookbook_name = nil)
104
+ from_hash(events, YAML.load(string), path, cookbook_name)
105
+ end
106
+
107
+ # @param filename [String] full path to the yml file in the cookbook
108
+ # @param cookbook_name [String] cookbook that the waiver is in
109
+ #
110
+ def self.from_file(events, filename, cookbook_name = nil)
111
+ from_yaml(events, IO.read(filename), filename, cookbook_name)
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,143 @@
1
+ # Copyright:: Copyright (c) Chef Software Inc.
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "waiver"
18
+
19
+ class Chef
20
+ module Compliance
21
+ class WaiverCollection < Array
22
+
23
+ # Event dispatcher for this run.
24
+ #
25
+ # @return [Chef::EventDispatch::Dispatcher]
26
+ #
27
+ attr_reader :events
28
+
29
+ def initialize(events)
30
+ @events = events
31
+ end
32
+
33
+ # Add a waiver to the waiver collection. The cookbook_name needs to be determined by the
34
+ # caller and is used in the `include_waiver` API to match on. The path should be the complete
35
+ # path on the host of the yml file, including the filename.
36
+ #
37
+ # @param path [String]
38
+ # @param cookbook_name [String]
39
+ #
40
+ def from_file(filename, cookbook_name)
41
+ new_waiver = Waiver.from_file(events, filename, cookbook_name)
42
+ self << new_waiver
43
+ events.compliance_waiver_loaded(new_waiver)
44
+ end
45
+
46
+ # Add a waiver from a raw hash. This waiver will be enabled by default.
47
+ #
48
+ # @param path [String]
49
+ # @param cookbook_name [String]
50
+ #
51
+ def from_hash(hash)
52
+ new_waiver = Waiver.from_hash(events, hash)
53
+ new_waiver.enable!
54
+ self << new_waiver
55
+ end
56
+
57
+ # @return [Array<Waiver>] inspec waivers which are enabled in a form suitable to pass to inspec
58
+ #
59
+ def inspec_data
60
+ select(&:enabled?).each_with_object({}) { |waiver, hash| hash.merge(waiver.inspec_data) }
61
+ end
62
+
63
+ # DSL method to enable waiver files. This matches on the filename of the waiver file.
64
+ # If the specific waiver is omitted then it uses the default waiver. The string
65
+ # supports regular expression matching.
66
+ #
67
+ # @example Specific waiver file in a cookbook
68
+ #
69
+ # include_waiver "acme_cookbook::ssh-001"
70
+ #
71
+ # @example The compliance/waiver/default.rb waiver file in a cookbook
72
+ #
73
+ # include_waiver "acme_cookbook"
74
+ #
75
+ # @example Every waiver file in a cookbook
76
+ #
77
+ # include_waiver "acme_cookbook::.*"
78
+ #
79
+ # @example Matching waivers by regexp in a cookbook
80
+ #
81
+ # include_waiver "acme_cookbook::ssh.*"
82
+ #
83
+ # @example Matching waivers by regexp in any cookbook in the cookbook collection
84
+ #
85
+ # include_waiver ".*::ssh.*"
86
+ #
87
+ # @example Adding an arbitrary hash of data (not from any file in a cookbook)
88
+ #
89
+ # include_waiver({ "ssh-01" => {
90
+ # "expiration_date" => "2033-07-31",
91
+ # "run" => false,
92
+ # "justification" => "the reason it is waived",
93
+ # } })
94
+ #
95
+ def include_waiver(arg)
96
+ raise "include_waiver was given a nil value" if arg.nil?
97
+
98
+ # if we're given a hash argument just shove it in the collection
99
+ if arg.is_a?(Hash)
100
+ from_hash(arg)
101
+ return
102
+ end
103
+
104
+ matching_waivers!(arg).each(&:enable!)
105
+ end
106
+
107
+ def valid?(arg)
108
+ !matching_waivers(arg).empty?
109
+ end
110
+
111
+ HIDDEN_IVARS = [ :@events ].freeze
112
+
113
+ # Omit the event object from error output
114
+ #
115
+ def inspect
116
+ ivar_string = (instance_variables.map(&:to_sym) - HIDDEN_IVARS).map do |ivar|
117
+ "#{ivar}=#{instance_variable_get(ivar).inspect}"
118
+ end.join(", ")
119
+ "#<#{self.class}:#{object_id} #{ivar_string}>"
120
+ end
121
+
122
+ private
123
+
124
+ def matching_waivers(arg, should_raise: false)
125
+ (cookbook_name, waiver_name) = arg.split("::")
126
+
127
+ waiver_name = "default" if waiver_name.nil?
128
+
129
+ waivers = select { |waiver| /^#{cookbook_name}$/.match?(waiver.cookbook_name) && /^#{waiver_name}$/.match?(waiver.pathname) }
130
+
131
+ if waivers.empty? && should_raise
132
+ raise "No inspec waivers matching '#{waiver_name}' found in cookbooks matching '#{cookbook_name}'"
133
+ end
134
+
135
+ waivers
136
+ end
137
+
138
+ def matching_waivers!(arg)
139
+ matching_waivers(arg, should_raise: true)
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,38 @@
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
+ class Chef
19
+ module DSL
20
+ module Compliance
21
+
22
+ # @see Chef::Compliance::ProfileCollection#include_profile
23
+ def include_profile(*args)
24
+ run_context.profile_collection.include_profile(*args)
25
+ end
26
+
27
+ # @see Chef::Compliance::WaiverCollection#include_waiver
28
+ def include_waiver(*args)
29
+ run_context.waiver_collection.include_waiver(*args)
30
+ end
31
+
32
+ # @see Chef::Compliance::inputCollection#include_input
33
+ def include_input(*args)
34
+ run_context.input_collection.include_input(*args)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
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
+ autoload :TOML, "tomlrb"
18
+ require_relative "../json_compat"
19
+ autoload :YAML, "yaml"
20
+
21
+ class Chef
22
+ module DSL
23
+ module ReaderHelpers
24
+
25
+ def parse_file(filename)
26
+ case File.extname(filename)
27
+ when ".toml"
28
+ parse_toml(filename)
29
+ when ".yaml", ".yml"
30
+ parse_yaml(filename)
31
+ when ".json"
32
+ parse_json(filename)
33
+ end
34
+ end
35
+
36
+ def parse_json(filename)
37
+ JSONCompat.parse(IO.read(filename))
38
+ end
39
+
40
+ def parse_toml(filename)
41
+ Tomlrb.load_file(filename)
42
+ end
43
+
44
+ def parse_yaml(filename)
45
+ YAML.load(IO.read(filename))
46
+ end
47
+
48
+ extend self
49
+ end
50
+ end
51
+ end
@@ -18,12 +18,13 @@
18
18
  #
19
19
 
20
20
  require_relative "../exceptions"
21
- require_relative "resources"
21
+ require_relative "compliance"
22
+ require_relative "declare_resource"
22
23
  require_relative "definitions"
23
24
  require_relative "include_recipe"
24
25
  require_relative "reboot_pending"
26
+ require_relative "resources"
25
27
  require_relative "universal"
26
- require_relative "declare_resource"
27
28
  require_relative "../mixin/notifying_block"
28
29
  require_relative "../mixin/lazy_module_include"
29
30
 
@@ -42,6 +43,7 @@ class Chef
42
43
  # - it also pollutes the namespace of nearly every context, watch out.
43
44
  #
44
45
  module Recipe
46
+ include Chef::DSL::Compliance
45
47
  include Chef::DSL::Universal
46
48
  include Chef::DSL::DeclareResource
47
49
  include Chef::Mixin::NotifyingBlock
@@ -49,15 +49,13 @@ class Chef
49
49
  #
50
50
  # value = secret(name: "test1", service: :aws_secrets_manager, version: "v1", config: { region: "us-west-1" })
51
51
  # log "My secret is #{value}"
52
- def secret(name: nil, version: nil, service: nil, config: nil)
53
- Chef::Log.warn <<~EOM.gsub("\n", "")
54
- The secrets Chef Infra language helper is currently in beta.
55
- This helper will most likely change over time in potentially breaking ways.
56
- If you have feedback or you'd like to be part of the future design of this
57
- helper e-mail us at secrets_management_beta@progress.com"
52
+ def secret(name: nil, version: nil, service: nil, config: {})
53
+ Chef::Log.warn <<~EOM.gsub("\n", " ")
54
+ The secrets Chef Infra language helper is currently in beta. If you have feedback or you would
55
+ like to be part of the future design of this helper e-mail us at secrets_management_beta@progress.com"
58
56
  EOM
59
57
  sensitive(true) if is_a?(Chef::Resource)
60
- Chef::SecretFetcher.for_service(service, config).fetch(name, version)
58
+ Chef::SecretFetcher.for_service(service, config, run_context).fetch(name, version)
61
59
  end
62
60
  end
63
61
  end
@@ -23,6 +23,7 @@ require_relative "chef_vault"
23
23
  require_relative "registry_helper"
24
24
  require_relative "powershell"
25
25
  require_relative "secret"
26
+ require_relative "reader_helpers"
26
27
  require_relative "render_helpers"
27
28
  require_relative "toml"
28
29
  require_relative "../mixin/powershell_exec"
@@ -50,6 +51,7 @@ class Chef
50
51
  include Chef::DSL::ChefVault
51
52
  include Chef::DSL::RegistryHelper
52
53
  include Chef::DSL::Powershell
54
+ include Chef::DSL::ReaderHelpers
53
55
  include Chef::DSL::RenderHelpers
54
56
  include Chef::DSL::Secret
55
57
  include Chef::Mixin::PowershellExec
@@ -164,7 +164,7 @@ class Chef
164
164
  # Called when LWRPs are finished loading
165
165
  def lwrp_load_complete; end
166
166
 
167
- # Called when an ohai plugin file loading starts
167
+ # Called when ohai plugin file loading starts
168
168
  def ohai_plugin_load_start(file_count); end
169
169
 
170
170
  # Called when an ohai plugin file has been loaded
@@ -173,9 +173,51 @@ class Chef
173
173
  # Called when an ohai plugin file has an error on load.
174
174
  def ohai_plugin_file_load_failed(path, exception); end
175
175
 
176
- # Called when an ohai plugin file loading has finished
176
+ # Called when ohai plugin file loading has finished
177
177
  def ohai_plugin_load_complete; end
178
178
 
179
+ # Called when compliance file loading starts
180
+ def compliance_load_start; end
181
+
182
+ # Called when compliance file loading ends
183
+ def compliance_load_complete; end
184
+
185
+ # Called when compliance profile loading starts
186
+ def profiles_load_start; end
187
+
188
+ # Called when compliance profile loading end
189
+ def profiles_load_complete; end
190
+
191
+ # Called when compliance input loading starts
192
+ def inputs_load_start; end
193
+
194
+ # Called when compliance input loading end
195
+ def inputs_load_complete; end
196
+
197
+ # Called when compliance waiver loading starts
198
+ def waivers_load_start; end
199
+
200
+ # Called when compliance waiver loading end
201
+ def waivers_load_complete; end
202
+
203
+ # Called when a compliance profile is found in a cookbook by the cookbook_compiler
204
+ def compliance_profile_loaded(profile); end
205
+
206
+ # Called when a compliance waiver is found in a cookbook by the cookbook_compiler
207
+ def compliance_waiver_loaded(waiver); end
208
+
209
+ # Called when a compliance waiver is found in a cookbook by the cookbook_compiler
210
+ def compliance_input_loaded(input); end
211
+
212
+ # Called when a compliance profile is enabled (by include_profile)
213
+ def compliance_profile_enabled(profile); end
214
+
215
+ # Called when a compliance waiver is enabled (by include_waiver)
216
+ def compliance_waiver_enabled(waiver); end
217
+
218
+ # Called when a compliance input is enabled (by include_input)
219
+ def compliance_input_enabled(input); end
220
+
179
221
  # Called before attribute files are loaded
180
222
  def attribute_load_start(attribute_file_count); end
181
223
 
@@ -308,8 +308,6 @@ class Chef
308
308
  super("No secret service provided. Supported services are: :#{fetcher_service_names.join(" :")}")
309
309
  end
310
310
  end
311
-
312
- class MissingVaultName < RuntimeError; end
313
311
  end
314
312
 
315
313
  # Exception class for collecting multiple failures. Used when running