inspec 4.7.3 → 4.7.18

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.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/inspec.gemspec +1 -1
  3. data/lib/bundles/inspec-supermarket/api.rb +2 -1
  4. data/lib/bundles/inspec-supermarket/cli.rb +6 -6
  5. data/lib/bundles/inspec-supermarket/target.rb +1 -0
  6. data/lib/fetchers/git.rb +3 -1
  7. data/lib/fetchers/mock.rb +1 -0
  8. data/lib/fetchers/url.rb +6 -3
  9. data/lib/inspec/backend.rb +1 -0
  10. data/lib/inspec/base_cli.rb +4 -1
  11. data/lib/inspec/cli.rb +5 -4
  12. data/lib/inspec/config.rb +9 -1
  13. data/lib/inspec/control_eval_context.rb +1 -0
  14. data/lib/inspec/dependencies/cache.rb +1 -0
  15. data/lib/inspec/dependencies/dependency_set.rb +2 -0
  16. data/lib/inspec/dependencies/lockfile.rb +1 -0
  17. data/lib/inspec/dependencies/requirement.rb +8 -7
  18. data/lib/inspec/dependencies/resolver.rb +3 -3
  19. data/lib/inspec/describe.rb +1 -0
  20. data/lib/inspec/dsl.rb +1 -1
  21. data/lib/inspec/dsl_shared.rb +1 -1
  22. data/lib/inspec/env_printer.rb +4 -4
  23. data/lib/inspec/fetcher.rb +4 -2
  24. data/lib/inspec/file_provider.rb +18 -8
  25. data/lib/inspec/formatters/base.rb +5 -0
  26. data/lib/inspec/impact.rb +2 -0
  27. data/lib/inspec/input_registry.rb +14 -13
  28. data/lib/inspec/metadata.rb +6 -2
  29. data/lib/inspec/method_source.rb +1 -1
  30. data/lib/inspec/objects/control.rb +4 -1
  31. data/lib/inspec/objects/describe.rb +3 -1
  32. data/lib/inspec/objects/input.rb +6 -5
  33. data/lib/inspec/objects/list.rb +2 -0
  34. data/lib/inspec/objects/test.rb +3 -2
  35. data/lib/inspec/plugin/v1/plugin_types/resource.rb +7 -0
  36. data/lib/inspec/plugin/v1/plugins.rb +4 -3
  37. data/lib/inspec/plugin/v1/registry.rb +3 -2
  38. data/lib/inspec/plugin/v2.rb +1 -0
  39. data/lib/inspec/plugin/v2/activator.rb +2 -0
  40. data/lib/inspec/plugin/v2/config_file.rb +4 -1
  41. data/lib/inspec/plugin/v2/filter.rb +1 -0
  42. data/lib/inspec/plugin/v2/installer.rb +9 -7
  43. data/lib/inspec/plugin/v2/loader.rb +2 -0
  44. data/lib/inspec/plugin/v2/plugin_base.rb +1 -0
  45. data/lib/inspec/plugin/v2/plugin_types/cli.rb +2 -2
  46. data/lib/inspec/plugin/v2/registry.rb +3 -1
  47. data/lib/inspec/profile.rb +13 -6
  48. data/lib/inspec/profile_context.rb +4 -2
  49. data/lib/inspec/reporters/cli.rb +14 -10
  50. data/lib/inspec/reporters/json.rb +1 -0
  51. data/lib/inspec/reporters/json_automate.rb +3 -0
  52. data/lib/inspec/reporters/json_min.rb +2 -0
  53. data/lib/inspec/resource.rb +2 -0
  54. data/lib/inspec/resources/aide_conf.rb +4 -3
  55. data/lib/inspec/resources/apache_conf.rb +1 -1
  56. data/lib/inspec/resources/apt.rb +2 -0
  57. data/lib/inspec/resources/auditd.rb +19 -18
  58. data/lib/inspec/resources/bridge.rb +5 -2
  59. data/lib/inspec/resources/chocolatey_package.rb +2 -0
  60. data/lib/inspec/resources/command.rb +1 -1
  61. data/lib/inspec/resources/crontab.rb +9 -8
  62. data/lib/inspec/resources/csv.rb +1 -1
  63. data/lib/inspec/resources/dh_params.rb +6 -0
  64. data/lib/inspec/resources/docker.rb +37 -34
  65. data/lib/inspec/resources/docker_container.rb +1 -0
  66. data/lib/inspec/resources/docker_image.rb +1 -0
  67. data/lib/inspec/resources/docker_plugin.rb +1 -0
  68. data/lib/inspec/resources/docker_service.rb +1 -0
  69. data/lib/inspec/resources/elasticsearch.rb +24 -24
  70. data/lib/inspec/resources/etc_fstab.rb +8 -7
  71. data/lib/inspec/resources/etc_group.rb +4 -0
  72. data/lib/inspec/resources/etc_hosts.rb +4 -4
  73. data/lib/inspec/resources/etc_hosts_allow_deny.rb +5 -3
  74. data/lib/inspec/resources/file.rb +4 -1
  75. data/lib/inspec/resources/filesystem.rb +5 -3
  76. data/lib/inspec/resources/firewalld.rb +7 -4
  77. data/lib/inspec/resources/groups.rb +6 -4
  78. data/lib/inspec/resources/grub_conf.rb +3 -0
  79. data/lib/inspec/resources/host.rb +5 -3
  80. data/lib/inspec/resources/http.rb +6 -4
  81. data/lib/inspec/resources/iis_app.rb +1 -0
  82. data/lib/inspec/resources/iis_app_pool.rb +1 -1
  83. data/lib/inspec/resources/iis_site.rb +4 -3
  84. data/lib/inspec/resources/interface.rb +10 -7
  85. data/lib/inspec/resources/json.rb +1 -1
  86. data/lib/inspec/resources/kernel_module.rb +1 -1
  87. data/lib/inspec/resources/kernel_parameter.rb +2 -1
  88. data/lib/inspec/resources/key_rsa.rb +5 -0
  89. data/lib/inspec/resources/mount.rb +3 -1
  90. data/lib/inspec/resources/mysql_conf.rb +3 -1
  91. data/lib/inspec/resources/mysql_session.rb +2 -0
  92. data/lib/inspec/resources/nginx.rb +1 -0
  93. data/lib/inspec/resources/nginx_conf.rb +10 -6
  94. data/lib/inspec/resources/ntp_conf.rb +1 -0
  95. data/lib/inspec/resources/oneget.rb +1 -1
  96. data/lib/inspec/resources/oracledb_session.rb +4 -2
  97. data/lib/inspec/resources/os_env.rb +1 -0
  98. data/lib/inspec/resources/package.rb +10 -6
  99. data/lib/inspec/resources/packages.rb +7 -5
  100. data/lib/inspec/resources/passwd.rb +7 -7
  101. data/lib/inspec/resources/pip.rb +2 -0
  102. data/lib/inspec/resources/port.rb +22 -8
  103. data/lib/inspec/resources/postgres.rb +2 -1
  104. data/lib/inspec/resources/postgres_conf.rb +2 -0
  105. data/lib/inspec/resources/postgres_hba_conf.rb +6 -6
  106. data/lib/inspec/resources/postgres_ident_conf.rb +3 -3
  107. data/lib/inspec/resources/processes.rb +16 -15
  108. data/lib/inspec/resources/rabbitmq_config.rb +2 -0
  109. data/lib/inspec/resources/registry_key.rb +8 -3
  110. data/lib/inspec/resources/security_identifier.rb +3 -1
  111. data/lib/inspec/resources/security_policy.rb +2 -1
  112. data/lib/inspec/resources/service.rb +13 -1
  113. data/lib/inspec/resources/shadow.rb +1 -0
  114. data/lib/inspec/resources/ssh_config.rb +2 -0
  115. data/lib/inspec/resources/ssl.rb +12 -11
  116. data/lib/inspec/resources/users.rb +29 -19
  117. data/lib/inspec/resources/virtualization.rb +10 -0
  118. data/lib/inspec/resources/windows_feature.rb +1 -1
  119. data/lib/inspec/resources/windows_hotfix.rb +2 -0
  120. data/lib/inspec/resources/windows_task.rb +4 -0
  121. data/lib/inspec/resources/wmi.rb +2 -1
  122. data/lib/inspec/resources/x509_certificate.rb +8 -0
  123. data/lib/inspec/resources/xinetd_conf.rb +10 -9
  124. data/lib/inspec/resources/yum.rb +15 -11
  125. data/lib/inspec/resources/zfs_dataset.rb +4 -2
  126. data/lib/inspec/resources/zfs_pool.rb +2 -1
  127. data/lib/inspec/rule.rb +11 -1
  128. data/lib/inspec/runner.rb +9 -6
  129. data/lib/inspec/runner_rspec.rb +10 -8
  130. data/lib/inspec/schema.rb +1 -0
  131. data/lib/inspec/secrets.rb +1 -0
  132. data/lib/inspec/secrets/yaml.rb +1 -0
  133. data/lib/inspec/shell.rb +20 -19
  134. data/lib/inspec/shell_detector.rb +1 -1
  135. data/lib/inspec/source_reader.rb +2 -0
  136. data/lib/inspec/ui.rb +1 -0
  137. data/lib/inspec/utils/deprecation/config_file.rb +8 -4
  138. data/lib/inspec/utils/erlang_parser.rb +2 -0
  139. data/lib/inspec/utils/file_reader.rb +1 -1
  140. data/lib/inspec/utils/filter.rb +16 -3
  141. data/lib/inspec/utils/find_files.rb +2 -2
  142. data/lib/inspec/utils/object_traversal.rb +1 -0
  143. data/lib/inspec/utils/parser.rb +2 -0
  144. data/lib/inspec/utils/simpleconfig.rb +4 -1
  145. data/lib/inspec/utils/telemetry/global_methods.rb +1 -0
  146. data/lib/inspec/version.rb +1 -1
  147. data/lib/matchers/matchers.rb +4 -1
  148. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +12 -11
  149. data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +3 -3
  150. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +15 -11
  151. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +4 -2
  152. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +13 -12
  153. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +3 -0
  154. data/lib/plugins/inspec-compliance/test/unit/api_test.rb +28 -28
  155. data/lib/plugins/inspec-compliance/test/unit/target_test.rb +1 -1
  156. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +1 -1
  157. data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +7 -6
  158. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +2 -2
  159. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +1 -0
  160. data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +12 -10
  161. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +6 -5
  162. data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +1 -0
  163. data/lib/plugins/shared/core_plugin_test_helper.rb +1 -0
  164. data/lib/resource_support/aws/aws_resource_mixin.rb +3 -2
  165. data/lib/resources/aws/aws_billing_report.rb +1 -1
  166. data/lib/resources/aws/aws_billing_reports.rb +8 -7
  167. data/lib/resources/aws/aws_cloudtrail_trail.rb +1 -1
  168. data/lib/resources/aws/aws_cloudtrail_trails.rb +1 -0
  169. data/lib/resources/aws/aws_cloudwatch_alarm.rb +4 -3
  170. data/lib/resources/aws/aws_cloudwatch_log_metric_filter.rb +2 -1
  171. data/lib/resources/aws/aws_config_delivery_channel.rb +1 -1
  172. data/lib/resources/aws/aws_config_recorder.rb +2 -0
  173. data/lib/resources/aws/aws_ebs_volume.rb +1 -0
  174. data/lib/resources/aws/aws_ebs_volumes.rb +2 -0
  175. data/lib/resources/aws/aws_ec2_instance.rb +2 -0
  176. data/lib/resources/aws/aws_ec2_instances.rb +2 -0
  177. data/lib/resources/aws/aws_ecs_cluster.rb +2 -2
  178. data/lib/resources/aws/aws_eks_cluster.rb +3 -3
  179. data/lib/resources/aws/aws_elb.rb +2 -2
  180. data/lib/resources/aws/aws_elbs.rb +14 -12
  181. data/lib/resources/aws/aws_flow_log.rb +2 -2
  182. data/lib/resources/aws/aws_iam_access_key.rb +3 -1
  183. data/lib/resources/aws/aws_iam_access_keys.rb +18 -16
  184. data/lib/resources/aws/aws_iam_groups.rb +1 -0
  185. data/lib/resources/aws/aws_iam_password_policy.rb +9 -7
  186. data/lib/resources/aws/aws_iam_policies.rb +2 -1
  187. data/lib/resources/aws/aws_iam_policy.rb +10 -1
  188. data/lib/resources/aws/aws_iam_role.rb +1 -0
  189. data/lib/resources/aws/aws_iam_user.rb +5 -2
  190. data/lib/resources/aws/aws_iam_users.rb +12 -11
  191. data/lib/resources/aws/aws_kms_key.rb +2 -2
  192. data/lib/resources/aws/aws_kms_keys.rb +3 -1
  193. data/lib/resources/aws/aws_route_table.rb +2 -2
  194. data/lib/resources/aws/aws_route_tables.rb +2 -1
  195. data/lib/resources/aws/aws_s3_bucket.rb +5 -3
  196. data/lib/resources/aws/aws_s3_bucket_object.rb +3 -1
  197. data/lib/resources/aws/aws_s3_buckets.rb +1 -0
  198. data/lib/resources/aws/aws_security_group.rb +20 -9
  199. data/lib/resources/aws/aws_security_groups.rb +1 -0
  200. data/lib/resources/aws/aws_sns_subscription.rb +1 -1
  201. data/lib/resources/aws/aws_sns_topics.rb +2 -0
  202. data/lib/resources/aws/aws_subnet.rb +2 -2
  203. data/lib/resources/aws/aws_subnets.rb +4 -3
  204. data/lib/resources/aws/aws_vpc.rb +1 -1
  205. data/lib/resources/aws/aws_vpcs.rb +3 -2
  206. data/lib/resources/azure/azure_generic_resource.rb +4 -4
  207. data/lib/resources/azure/azure_resource_group.rb +1 -0
  208. data/lib/resources/azure/azure_virtual_machine_data_disk.rb +13 -12
  209. data/lib/source_readers/flat.rb +1 -0
  210. data/lib/source_readers/inspec.rb +1 -0
  211. metadata +2 -2
@@ -11,12 +11,13 @@ module Inspec
11
11
  end
12
12
  end
13
13
 
14
- NON_FETCHER_KEYS = [:name, :version_constraint, :cwd, :backend, :cache, :sha256].freeze
14
+ NON_FETCHER_KEYS = %i{name version_constraint cwd backend cache sha256}.freeze
15
15
  def fetcher_specified?(target)
16
16
  # Only set a default for Hash-based (i.e. from
17
17
  # inspec.yml/inspec.lock) targets
18
18
 
19
- return true if !target.respond_to?(:keys)
19
+ return true unless target.respond_to?(:keys)
20
+
20
21
  !(target.keys - NON_FETCHER_KEYS).empty?
21
22
  end
22
23
 
@@ -31,6 +32,7 @@ module Inspec
31
32
  if version != 1
32
33
  raise "Only fetcher version 1 is supported!"
33
34
  end
35
+
34
36
  Inspec::Plugins::Fetcher
35
37
  end
36
38
  end
@@ -21,8 +21,7 @@ module Inspec
21
21
  end
22
22
  end
23
23
 
24
- def initialize(_path)
25
- end
24
+ def initialize(_path); end
26
25
 
27
26
  # List all files that are offered.
28
27
  #
@@ -80,12 +79,14 @@ module Inspec
80
79
  def read(file)
81
80
  return nil unless files.include?(file)
82
81
  return nil unless File.file?(file)
82
+
83
83
  File.read(file)
84
84
  end
85
85
 
86
86
  def binread(file)
87
87
  return nil unless files.include?(file)
88
88
  return nil unless File.file?(file)
89
+
89
90
  File.binread(file)
90
91
  end
91
92
  end
@@ -133,10 +134,12 @@ module Inspec
133
134
 
134
135
  def read_from_zip(file)
135
136
  return nil unless @files.include?(file)
137
+
136
138
  res = nil
137
139
  walk_zip(@path) do |io|
138
140
  while (entry = io.get_next_entry)
139
141
  next unless file == entry.name
142
+
140
143
  res = io.read
141
144
  break
142
145
  end
@@ -172,6 +175,7 @@ module Inspec
172
175
  walk_tar(@path) do |files|
173
176
  files.each do |file|
174
177
  next unless @files.include?(file.full_name)
178
+
175
179
  final_path = File.join(destination_path, file.full_name)
176
180
 
177
181
  # This removes the top level directory (and any other files) to ensure
@@ -199,11 +203,13 @@ module Inspec
199
203
 
200
204
  def read_from_tar(file)
201
205
  return nil unless @files.include?(file)
206
+
202
207
  res = nil
203
208
  # NB `TarReader` includes `Enumerable` beginning with Ruby 2.x
204
209
  walk_tar(@path) do |tar|
205
210
  tar.each do |entry|
206
211
  next unless entry.file? && [file, "./#{file}"].include?(entry.full_name)
212
+
207
213
  res = entry.read
208
214
  break
209
215
  end
@@ -235,16 +241,17 @@ module Inspec
235
241
  # PAX-formatted tar files. Do not do any translation of the path if the
236
242
  # path is an absolute path.
237
243
  @files = parent.files
238
- .find_all { |x| x.start_with?(prefix) && x != prefix }
239
- .map { |x| x[prefix.length..-1] }
240
- .map do |x|
241
- path = Pathname.new(x)
242
- path.absolute? ? path.to_s : path.relative_path_from(Pathname.new(".")).to_s
243
- end
244
+ .find_all { |x| x.start_with?(prefix) && x != prefix }
245
+ .map { |x| x[prefix.length..-1] }
246
+ .map do |x|
247
+ path = Pathname.new(x)
248
+ path.absolute? ? path.to_s : path.relative_path_from(Pathname.new(".")).to_s
249
+ end
244
250
  end
245
251
 
246
252
  def abs_path(file)
247
253
  return nil if file.nil?
254
+
248
255
  prefix + file
249
256
  end
250
257
 
@@ -278,12 +285,14 @@ module Inspec
278
285
 
279
286
  def get_folder_prefix(fs)
280
287
  return get_files_prefix(fs) if fs.length == 1
288
+
281
289
  first, *rest = fs
282
290
  pre = prefix_candidate_for(first)
283
291
 
284
292
  if rest.all? { |i| i.start_with? pre }
285
293
  return get_folder_prefix(rest)
286
294
  end
295
+
287
296
  get_files_prefix(fs)
288
297
  end
289
298
 
@@ -303,6 +312,7 @@ module Inspec
303
312
 
304
313
  new_pre = get_prefix(rest)
305
314
  return new_pre if pre.start_with? new_pre
315
+
306
316
  # edge case: completely different prefixes; retry prefix detection
307
317
  a = File.dirname(pre + "a")
308
318
  b = File.dirname(new_pre + "b")
@@ -49,6 +49,7 @@ module Inspec::Formatters
49
49
  end
50
50
 
51
51
  next if e.is_a? RSpec::Expectations::ExpectationNotMetError
52
+
52
53
  hash[:exception] = e.class.name
53
54
  hash[:backtrace] = e.backtrace
54
55
  end
@@ -101,6 +102,7 @@ module Inspec::Formatters
101
102
 
102
103
  all_unique_controls.each do |control|
103
104
  next unless control[:results]
105
+
104
106
  if control[:results].any? { |r| r[:status] == "failed" }
105
107
  failed += 1
106
108
  elsif control[:results].any? { |r| r[:status] == "skipped" }
@@ -185,6 +187,7 @@ module Inspec::Formatters
185
187
  # the proper report.
186
188
  def platform(field)
187
189
  return nil if @backend.nil?
190
+
188
191
  begin
189
192
  @backend.platform[field]
190
193
  rescue Train::Error => e
@@ -195,6 +198,7 @@ module Inspec::Formatters
195
198
 
196
199
  def backend_target
197
200
  return nil if @backend.nil?
201
+
198
202
  connection = @backend.backend
199
203
  connection.respond_to?(:uri) ? connection.uri : nil
200
204
  end
@@ -218,6 +222,7 @@ module Inspec::Formatters
218
222
  def example2control(example)
219
223
  profile = profile_from_example(example)
220
224
  return nil unless profile&.[](:controls)
225
+
221
226
  profile[:controls].find { |x| x[:id] == example[:id] }
222
227
  end
223
228
 
@@ -12,6 +12,7 @@ module Inspec::Impact
12
12
  # return if its a number
13
13
  return value if is_number?(value)
14
14
  raise Inspec::ImpactError, "'#{value}' is not a valid impact name. Valid impact names: none, low, medium, high, critical." unless IMPACT_SCORES.key?(value.downcase)
15
+
15
16
  IMPACT_SCORES[value]
16
17
  end
17
18
 
@@ -25,6 +26,7 @@ module Inspec::Impact
25
26
  def self.string_from_impact(value)
26
27
  value = value.to_f
27
28
  raise Inspec::ImpactError, "'#{value}' is not a valid impact score. Valid impact scores: [0.0 - 1.0]." if value < 0 || value > 1
29
+
28
30
  IMPACT_SCORES.reverse_each do |name, impact|
29
31
  return name if value >= impact
30
32
  end
@@ -169,11 +169,12 @@ module Inspec
169
169
  data = Inspec::SecretsBackend.resolve(path)
170
170
  if data.nil?
171
171
  raise Inspec::Exceptions::SecretsBackendNotFound,
172
- "Cannot find parser for inputs file '#{path}'. " \
173
- "Check to make sure file has the appropriate extension."
172
+ "Cannot find parser for inputs file '#{path}'. " \
173
+ "Check to make sure file has the appropriate extension."
174
174
  end
175
175
 
176
176
  next if data.inputs.nil?
177
+
177
178
  data.inputs.each do |input_name, input_value|
178
179
  evt = Inspec::Input::Event.new(
179
180
  value: input_value,
@@ -190,14 +191,14 @@ module Inspec
190
191
  def validate_inputs_file_readability!(path)
191
192
  unless File.exist?(path)
192
193
  raise Inspec::Exceptions::InputsFileDoesNotExist,
193
- "Cannot find input file '#{path}'. " \
194
- "Check to make sure file exists."
194
+ "Cannot find input file '#{path}'. " \
195
+ "Check to make sure file exists."
195
196
  end
196
197
 
197
198
  unless File.readable?(path)
198
199
  raise Inspec::Exceptions::InputsFileNotReadable,
199
- "Cannot read input file '#{path}'. " \
200
- "Check to make sure file is readable."
200
+ "Cannot read input file '#{path}'. " \
201
+ "Check to make sure file is readable."
201
202
  end
202
203
 
203
204
  true
@@ -260,13 +261,13 @@ module Inspec
260
261
 
261
262
  # These class methods are convenience methods so you don't always
262
263
  # have to call #instance when calling the registry
263
- [
264
- :find_or_register_input,
265
- :register_profile_alias,
266
- :list_inputs_for_profile,
267
- :list_potential_input_names_for_profile,
268
- :bind_profile_inputs,
269
- ].each do |meth|
264
+ %i{
265
+ find_or_register_input
266
+ register_profile_alias
267
+ list_inputs_for_profile
268
+ list_potential_input_names_for_profile
269
+ bind_profile_inputs
270
+ }.each do |meth|
270
271
  define_singleton_method(meth) do |*args|
271
272
  instance.send(meth, *args)
272
273
  end
@@ -74,6 +74,7 @@ module Inspec
74
74
 
75
75
  %w{name version}.each do |field|
76
76
  next unless params[field.to_sym].nil?
77
+
77
78
  errors.push("Missing profile #{field} in #{ref}")
78
79
  end
79
80
 
@@ -89,6 +90,7 @@ module Inspec
89
90
 
90
91
  %w{title summary maintainer copyright license}.each do |field|
91
92
  next unless params[field.to_sym].nil?
93
+
92
94
  warnings.push("Missing profile #{field} in #{ref}")
93
95
  end
94
96
 
@@ -151,8 +153,8 @@ module Inspec
151
153
  when nil then nil
152
154
  else
153
155
  Inspec.deprecate(:supports_syntax,
154
- "Do not use deprecated `supports: #{x}` syntax. Instead use:\n"\
155
- "supports:\n - os-family: #{x}\n\n")
156
+ "Do not use deprecated `supports: #{x}` syntax. Instead use:\n"\
157
+ "supports:\n - os-family: #{x}\n\n")
156
158
  { :'os-family' => x } # rubocop:disable Style/HashSyntax
157
159
  end
158
160
  end
@@ -182,12 +184,14 @@ module Inspec
182
184
  # Crudely slug the target to not contain slashes, to avoid breaking
183
185
  # unit tests that look for warning sequences
184
186
  return if original_target.to_s.empty?
187
+
185
188
  metadata.params[:title] = "tests from #{original_target}"
186
189
  metadata.params[:name] = metadata.params[:title].gsub(%r{[\/\\]}, ".")
187
190
  end
188
191
 
189
192
  def self.finalize(metadata, profile_id, options, logger = nil)
190
193
  return nil if metadata.nil?
194
+
191
195
  param = metadata.params || {}
192
196
  options ||= {}
193
197
  param["version"] = param["version"].to_s unless param["version"].nil?
@@ -14,7 +14,7 @@ module Inspec
14
14
  ::MethodSource.expression_at(src.lines, location[:line]).force_encoding("utf-8")
15
15
  rescue SyntaxError => e
16
16
  raise ::MethodSource::SourceNotFoundError,
17
- "Could not parse source at #{location[:ref]}:#{location[:line]}: #{e.message}"
17
+ "Could not parse source at #{location[:ref]}:#{location[:line]}: #{e.message}"
18
18
  end
19
19
  end
20
20
  end
@@ -33,6 +33,7 @@ module Inspec
33
33
  descriptions.each do |label, text|
34
34
  if label == :default
35
35
  next if text.nil? || (text == "") # don't render empty/nil desc
36
+
36
37
  res.push " desc #{prettyprint_text(text, 2)}"
37
38
  else
38
39
  res.push " desc #{label.to_s.inspect}, #{prettyprint_text(text, 2)}"
@@ -52,6 +53,7 @@ module Inspec
52
53
  def print_ref(x)
53
54
  return x.inspect if x.is_a?(String)
54
55
  raise "Cannot process the ref: #{x}" unless x.is_a?(Hash)
56
+
55
57
  "(" + x.inspect + ")"
56
58
  end
57
59
 
@@ -62,7 +64,8 @@ module Inspec
62
64
  # @return [String] pretty-printed textblock
63
65
  def prettyprint_text(s, depth)
64
66
  txt = s.to_s.inspect.gsub('\n', "\n")
65
- return txt if !txt.include?("\n")
67
+ return txt unless txt.include?("\n")
68
+
66
69
  middle = indent(txt[1..-2], depth + 2)
67
70
  txt[0] + "\n" + middle + "\n" + " " * depth + txt[-1]
68
71
  end
@@ -62,7 +62,8 @@ module Inspec
62
62
  end
63
63
 
64
64
  def to_ruby
65
- return rb_skip if !skip.nil?
65
+ return rb_skip unless skip.nil?
66
+
66
67
  rb_describe
67
68
  end
68
69
 
@@ -72,6 +73,7 @@ module Inspec
72
73
 
73
74
  def resource
74
75
  return nil if qualifier.empty? || qualifier[0].empty? || qualifier[0][0].empty?
76
+
75
77
  qualifier[0][0]
76
78
  end
77
79
 
@@ -309,9 +309,10 @@ module Inspec
309
309
 
310
310
  def to_hash
311
311
  as_hash = { name: name, options: {} }
312
- [:description, :title, :identifier, :type, :required, :value].each do |field|
312
+ %i{description title identifier type required value}.each do |field|
313
313
  val = send(field)
314
314
  next if val.nil?
315
+
315
316
  as_hash[:options][field] = val
316
317
  end
317
318
  as_hash
@@ -372,11 +373,11 @@ module Inspec
372
373
 
373
374
  invalid_type = false
374
375
  if type_req == "Regexp"
375
- invalid_type = true if !valid_regexp?(proposed_value)
376
+ invalid_type = true unless valid_regexp?(proposed_value)
376
377
  elsif type_req == "Numeric"
377
- invalid_type = true if !valid_numeric?(proposed_value)
378
+ invalid_type = true unless valid_numeric?(proposed_value)
378
379
  elsif type_req == "Boolean"
379
- invalid_type = true if ![true, false].include?(proposed_value)
380
+ invalid_type = true unless [true, false].include?(proposed_value)
380
381
  elsif proposed_value.is_a?(Module.const_get(type_req)) == false
381
382
  # TODO: why is this case here?
382
383
  invalid_type = true
@@ -400,7 +401,7 @@ module Inspec
400
401
  "Regex" => "Regexp",
401
402
  }
402
403
  type_req = abbreviations[type_req] if abbreviations.key?(type_req)
403
- if !VALID_TYPES.include?(type_req)
404
+ unless VALID_TYPES.include?(type_req)
404
405
  error = Inspec::Input::TypeError.new
405
406
  error.input_type = type_req
406
407
  raise error, "Type '#{error.input_type}' is not a valid input type."
@@ -2,10 +2,12 @@ module Inspec
2
2
  class List < Value
3
3
  def map
4
4
  raise "Inspec::List.map needs to be called with a block" unless block_given?
5
+
5
6
  t = List.new
6
7
  t.qualifier = [["x"]]
7
8
  yield(t)
8
9
  return if t.qualifier == [["x"]]
10
+
9
11
  @qualifier.push(["map", "{ |x| #{t.to_ruby} }"])
10
12
  self
11
13
  end
@@ -14,7 +14,8 @@ module Inspec
14
14
  end
15
15
 
16
16
  def to_ruby
17
- return rb_skip if !skip.nil?
17
+ return rb_skip unless skip.nil?
18
+
18
19
  rb_describe
19
20
  end
20
21
 
@@ -74,7 +75,7 @@ module Inspec
74
75
  " " + expectation.inspect
75
76
  end
76
77
  format("%s%sdescribe %s do\n %s { should%s %s%s }\nend",
77
- only_if_clause, vars, res, itsy, naughty, matcher, xpect)
78
+ only_if_clause, vars, res, itsy, naughty, matcher, xpect)
78
79
  end
79
80
 
80
81
  def rb_skip
@@ -17,23 +17,27 @@ module Inspec
17
17
  module ResourceDSL
18
18
  def name(name = nil)
19
19
  return if name.nil?
20
+
20
21
  @name = name
21
22
  __register(name, self)
22
23
  end
23
24
 
24
25
  def desc(description = nil)
25
26
  return if description.nil?
27
+
26
28
  __resource_registry[@name].desc(description)
27
29
  end
28
30
 
29
31
  def supports(criteria = nil)
30
32
  return if criteria.nil?
33
+
31
34
  Inspec::Resource.supports[@name] ||= []
32
35
  Inspec::Resource.supports[@name].push(criteria)
33
36
  end
34
37
 
35
38
  def example(example = nil)
36
39
  return if example.nil?
40
+
37
41
  __resource_registry[@name].example(example)
38
42
  end
39
43
 
@@ -100,17 +104,20 @@ module Inspec
100
104
  # The new platform resources have methods generated on the fly
101
105
  # for inspec check to work we need to skip these train errors
102
106
  raise unless test_backend && e.receiver.class == Train::Transports::Mock::Connection
107
+
103
108
  skip_resource(e.message)
104
109
  end
105
110
  end
106
111
 
107
112
  def self.desc(description = nil)
108
113
  return @description if description.nil?
114
+
109
115
  @description = description
110
116
  end
111
117
 
112
118
  def self.example(example = nil)
113
119
  return @example if example.nil?
120
+
114
121
  @example = example
115
122
  end
116
123