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
@@ -16,7 +16,8 @@ module Inspec::Resources
16
16
  EXAMPLE
17
17
 
18
18
  def initialize(zfs_dataset)
19
- return skip_resource "The `zfs_dataset` resource is not supported on your OS yet." if !inspec.os.bsd?
19
+ return skip_resource "The `zfs_dataset` resource is not supported on your OS yet." unless inspec.os.bsd?
20
+
20
21
  @zfs_dataset = zfs_dataset
21
22
 
22
23
  @params = gather
@@ -28,7 +29,8 @@ module Inspec::Resources
28
29
  end
29
30
 
30
31
  def mounted?
31
- return false if !exists?
32
+ return false unless exists?
33
+
32
34
  inspec.mount(@params["mountpoint"]).mounted?
33
35
  end
34
36
 
@@ -15,7 +15,8 @@ module Inspec::Resources
15
15
  EXAMPLE
16
16
 
17
17
  def initialize(zfs_pool)
18
- return skip_resource "The `zfs_pool` resource is not supported on your OS yet." if !inspec.os.bsd?
18
+ return skip_resource "The `zfs_pool` resource is not supported on your OS yet." unless inspec.os.bsd?
19
+
19
20
  @zfs_pool = zfs_pool
20
21
 
21
22
  @params = gather
@@ -49,6 +49,7 @@ module Inspec
49
49
 
50
50
  # evaluate the given definition
51
51
  return unless block_given?
52
+
52
53
  begin
53
54
  instance_eval(&block)
54
55
  rescue StandardError => e
@@ -91,6 +92,7 @@ module Inspec
91
92
 
92
93
  def desc(v = nil, data = nil)
93
94
  return @descriptions[:default] if v.nil?
95
+
94
96
  if data.nil?
95
97
  @descriptions[:default] = unindent(v)
96
98
  else
@@ -100,11 +102,13 @@ module Inspec
100
102
 
101
103
  def descriptions(description_hash = nil)
102
104
  return @descriptions if description_hash.nil?
105
+
103
106
  @descriptions.merge!(description_hash)
104
107
  end
105
108
 
106
109
  def ref(ref = nil, opts = {})
107
110
  return @refs if ref.nil? && opts.empty?
111
+
108
112
  if opts.empty? && ref.is_a?(Hash)
109
113
  opts = ref
110
114
  else
@@ -191,7 +195,7 @@ module Inspec
191
195
 
192
196
  def self.set_skip_rule(rule, value, message = nil)
193
197
  rule.instance_variable_set(:@__skip_rule,
194
- { result: value, message: message })
198
+ { result: value, message: message })
195
199
  end
196
200
 
197
201
  def self.merge_count(rule)
@@ -205,6 +209,7 @@ module Inspec
205
209
  def self.prepare_checks(rule)
206
210
  skip_check = skip_status(rule)
207
211
  return checks(rule) unless skip_check[:result].eql?(true)
212
+
208
213
  if skip_check[:message]
209
214
  msg = "Skipped control due to only_if condition: #{skip_check[:message]}"
210
215
  else
@@ -223,12 +228,14 @@ module Inspec
223
228
  # TODO: register an error, this case should not happen
224
229
  return
225
230
  end
231
+
226
232
  sp = rule_id(src)
227
233
  dp = rule_id(dst)
228
234
  if sp != dp
229
235
  # TODO: register an error, this case should not happen
230
236
  return
231
237
  end
238
+
232
239
  # merge all fields
233
240
  dst.impact(src.impact) unless src.impact.nil?
234
241
  dst.title(src.title) unless src.title.nil?
@@ -274,6 +281,7 @@ module Inspec
274
281
  #
275
282
  def with_dsl(block)
276
283
  return nil if block.nil?
284
+
277
285
  if self.class.resource_dsl
278
286
  dsl = self.class.resource_dsl
279
287
  proc do |*args|
@@ -299,6 +307,7 @@ module Inspec
299
307
  # @return [String] input with indentation removed; '' if input is nil
300
308
  def unindent(text)
301
309
  return "" if text.nil?
310
+
302
311
  len = text.split("\n").reject { |l| l.strip.empty? }.map { |x| x.index(/[^\s]/) }.compact.min
303
312
  text.gsub(/^[[:blank:]]{#{len}}/, "").strip
304
313
  end
@@ -306,6 +315,7 @@ module Inspec
306
315
  # get the source location of the block
307
316
  def __get_block_source_location(&block)
308
317
  return {} unless block_given?
318
+
309
319
  r, l = block.source_location
310
320
  { ref: r, line: l }
311
321
  rescue MethodSource::SourceNotFoundError
@@ -136,7 +136,7 @@ module Inspec
136
136
  end
137
137
 
138
138
  def write_lockfile(profile)
139
- return false if !profile.writable?
139
+ return false unless profile.writable?
140
140
 
141
141
  if profile.lockfile_exists?
142
142
  Inspec::Log.debug "Using existing lockfile #{profile.lockfile_path}"
@@ -182,16 +182,17 @@ module Inspec
182
182
  #
183
183
  def add_target(target, _opts = [])
184
184
  profile = Inspec::Profile.for_target(target,
185
- vendor_cache: @cache,
186
- backend: @backend,
187
- controls: @controls,
188
- runner_conf: @conf)
185
+ vendor_cache: @cache,
186
+ backend: @backend,
187
+ controls: @controls,
188
+ runner_conf: @conf)
189
189
  raise "Could not resolve #{target} to valid input." if profile.nil?
190
+
190
191
  @target_profiles << profile if supports_profile?(profile)
191
192
  end
192
193
 
193
194
  def supports_profile?(profile)
194
- if !profile.supports_runtime?
195
+ unless profile.supports_runtime?
195
196
  raise "This profile requires #{Inspec::Dist::PRODUCT_NAME} version "\
196
197
  "#{profile.metadata.inspec_requirement}. You are running "\
197
198
  "#{Inspec::Dist::PRODUCT_NAME} v#{Inspec::VERSION}.\n"
@@ -211,6 +212,7 @@ module Inspec
211
212
  new_tests = false
212
213
  ctx.rules.each do |rule_id, rule|
213
214
  next if block_given? && !(yield rule_id, rule)
215
+
214
216
  new_tests = true
215
217
  register_rule(rule)
216
218
  end
@@ -238,6 +240,7 @@ module Inspec
238
240
 
239
241
  def block_source_info(block)
240
242
  return {} if block.nil? || !block.respond_to?(:source_location)
243
+
241
244
  opts = {}
242
245
  file_path, line = block.source_location
243
246
  opts["file_path"] = file_path
@@ -31,10 +31,10 @@ module Inspec
31
31
  # @return [nil]
32
32
  def add_profile(profile)
33
33
  RSpec.configuration.formatters
34
- .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
35
- .each do |fmt|
36
- fmt.add_profile(profile)
37
- end
34
+ .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
35
+ .each do |fmt|
36
+ fmt.add_profile(profile)
37
+ end
38
38
  end
39
39
 
40
40
  # Configure the backend of the runner.
@@ -43,10 +43,10 @@ module Inspec
43
43
  # @return [nil]
44
44
  def backend=(backend)
45
45
  RSpec.configuration.formatters
46
- .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
47
- .each do |fmt|
48
- fmt.backend = backend
49
- end
46
+ .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
47
+ .each do |fmt|
48
+ fmt.backend = backend
49
+ end
50
50
  end
51
51
 
52
52
  # Add an example group to the list of registered tests.
@@ -81,6 +81,7 @@ module Inspec
81
81
  # @return [int] exit code
82
82
  def exit_code
83
83
  return @rspec_exit_code if @formatter.results.empty?
84
+
84
85
  stats = @formatter.results[:statistics][:controls]
85
86
  skipped = @formatter.results&.fetch(:profiles, nil)&.first&.fetch(:status, nil) == "skipped"
86
87
  if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped
@@ -111,6 +112,7 @@ module Inspec
111
112
  #
112
113
  def set_optional_formatters
113
114
  return if @conf["reporter"].nil?
115
+
114
116
  if @conf["reporter"].key?("json-rspec")
115
117
  # We cannot pass in a nil output path. Rspec only accepts a valid string or a IO object.
116
118
  if @conf["reporter"]["json-rspec"]&.[]("file").nil?
@@ -228,6 +228,7 @@ module Inspec
228
228
  else
229
229
  v = LIST[name]
230
230
  end
231
+
231
232
  JSON.dump(v)
232
233
  end
233
234
  end
@@ -7,6 +7,7 @@ module Inspec
7
7
  if version != 1
8
8
  raise "Only secrets version 1 is supported!"
9
9
  end
10
+
10
11
  Inspec::Plugins::Secret
11
12
  end
12
13
  end
@@ -10,6 +10,7 @@ module Secrets
10
10
  unless target.is_a?(String) && File.file?(target) && [".yml", ".yaml"].include?(File.extname(target).downcase)
11
11
  return nil
12
12
  end
13
+
13
14
  new(target)
14
15
  end
15
16
 
@@ -24,7 +24,7 @@ module Inspec
24
24
  # Delete any before_session, before_eval, and after_eval hooks so we can
25
25
  # replace them with our own. Pry 0.10 used to have a single method to clear
26
26
  # all hooks, but this was removed in Pry 0.11.
27
- [:before_session, :before_eval, :after_eval].each do |event|
27
+ %i{before_session before_eval after_eval}.each do |event|
28
28
  Pry.hooks.get_hooks(event).keys.map { |hook| Pry.hooks.delete_hook(event, hook) }
29
29
  end
30
30
 
@@ -54,13 +54,14 @@ module Inspec
54
54
  # test file, register all the rules it discovered.
55
55
  Pry.hooks.add_hook(:after_eval, "inspec_after_eval") do
56
56
  @runner.load
57
- @runner.run_tests if !@runner.all_rules.empty?
57
+ @runner.run_tests unless @runner.all_rules.empty?
58
58
  end
59
59
 
60
60
  # Don't print out control class inspection when the user uses DSL methods.
61
61
  # Instead produce a result of evaluating their control.
62
62
  Pry.config.print = proc do |_output_, value, pry|
63
- next if !@runner.all_rules.empty?
63
+ next unless @runner.all_rules.empty?
64
+
64
65
  pry.pager.open do |pager|
65
66
  pager.print pry.config.output_prefix
66
67
  Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
@@ -78,7 +79,7 @@ module Inspec
78
79
 
79
80
  def intro
80
81
  puts "Welcome to the interactive InSpec Shell"
81
- puts "To find out how to use it, type: #{mark 'help'}"
82
+ puts "To find out how to use it, type: #{mark "help"}"
82
83
  puts
83
84
  end
84
85
 
@@ -118,18 +119,18 @@ module Inspec
118
119
  print_matchers_help
119
120
  elsif !Inspec::Resource.registry[topic].nil? # TODO: fix unnecessary logic
120
121
  topic_info = Inspec::Resource.registry[topic]
121
- info = "#{mark 'Name:'} #{topic}\n\n"
122
+ info = "#{mark "Name:"} #{topic}\n\n"
122
123
  unless topic_info.desc.nil?
123
- info += "#{mark 'Description:'}\n\n"
124
+ info += "#{mark "Description:"}\n\n"
124
125
  info += "#{topic_info.desc}\n\n"
125
126
  end
126
127
 
127
128
  unless topic_info.example.nil?
128
- info += "#{mark 'Example:'}\n\n"
129
+ info += "#{mark "Example:"}\n\n"
129
130
  info += "#{topic_info.example}\n\n"
130
131
  end
131
132
 
132
- info += "#{mark 'Web Reference:'}\n\n"
133
+ info += "#{mark "Web Reference:"}\n\n"
133
134
  info += "https://www.inspec.io/docs/reference/resources/#{topic}\n\n"
134
135
  puts info
135
136
  else
@@ -147,15 +148,15 @@ module Inspec
147
148
  resources implement their own custom matchers, the following matchers are
148
149
  common amongst all resources:
149
150
 
150
- #{mark 'be'}
151
+ #{mark "be"}
151
152
 
152
- The #{mark 'be'} matcher can be used to compare numeric values.
153
+ The #{mark "be"} matcher can be used to compare numeric values.
153
154
 
154
155
  its('size') { should be >= 10 }
155
156
 
156
- #{mark 'cmp'}
157
+ #{mark "cmp"}
157
158
 
158
- The #{mark 'cmp'} matcher is like #{mark 'eq'} but less restrictive. It will try
159
+ The #{mark "cmp"} matcher is like #{mark "eq"} but less restrictive. It will try
159
160
  to fit the resource value to the expectation.
160
161
 
161
162
  "Protocol" likely returns a string, but cmp will ensure it's a number before
@@ -174,23 +175,23 @@ module Inspec
174
175
  its('log_format') { should cmp 'raw' }
175
176
  its('log_format') { should cmp 'RAW' }
176
177
 
177
- #{mark 'eq'}
178
+ #{mark "eq"}
178
179
 
179
- The #{mark 'eq'} matcher tests for exact equality of two values. Value type
180
+ The #{mark "eq"} matcher tests for exact equality of two values. Value type
180
181
  (string, number, etc.) is important and must be the same. For a less-restrictive
181
- comparison matcher, use the #{mark 'cmp'} matcher.
182
+ comparison matcher, use the #{mark "cmp"} matcher.
182
183
 
183
184
  its('RSAAuthentication') { should_not eq 'no' }
184
185
 
185
- #{mark 'include'}
186
+ #{mark "include"}
186
187
 
187
- The #{mark 'include'} matcher tests to see if a value is included in a list.
188
+ The #{mark "include"} matcher tests to see if a value is included in a list.
188
189
 
189
190
  its('users') { should include 'my_user' }
190
191
 
191
- #{mark 'match'}
192
+ #{mark "match"}
192
193
 
193
- The #{mark 'match'} matcher can be used to test a string for a match using a
194
+ The #{mark "match"} matcher can be used to test a string for a match using a
194
195
  regular expression.
195
196
 
196
197
  its('content') { should_not match /^MyKey:\\s+some value/ }
@@ -23,7 +23,7 @@ module Inspec
23
23
  end
24
24
 
25
25
  def shell
26
- @shell = detect if !detected?(@shell)
26
+ @shell = detect unless detected?(@shell)
27
27
  @shell
28
28
  end
29
29
 
@@ -6,6 +6,7 @@ module Inspec
6
6
  class SourceReaderRegistry < PluginRegistry
7
7
  def resolve(target)
8
8
  return nil if target.nil?
9
+
9
10
  super(target)
10
11
  end
11
12
  end
@@ -16,6 +17,7 @@ module Inspec
16
17
  if version != 1
17
18
  raise "Only source readers version 1 is supported!"
18
19
  end
20
+
19
21
  Inspec::Plugins::SourceReader
20
22
  end
21
23
  end
@@ -204,6 +204,7 @@ module Inspec
204
204
  unless interactive?
205
205
  raise Inspec::UserInteractionRequired, "Somthing is trying to ask the user a question, but interactivity is disabled."
206
206
  end
207
+
207
208
  require "tty-prompt"
208
209
 
209
210
  @prompt ||= TTY::Prompt.new
@@ -41,6 +41,7 @@ module Inspec
41
41
  unless File.exist?(default_path)
42
42
  raise Inspec::Deprecation::MalformedConfigError, "Missing deprecation config file: #{default_path}"
43
43
  end
44
+
44
45
  File.open(default_path)
45
46
  end
46
47
 
@@ -57,6 +58,7 @@ module Inspec
57
58
  unless @raw_data["groups"].is_a?(Hash)
58
59
  raise Inspec::Deprecation::InvalidConfigFileError, "Groups field must be a Hash"
59
60
  end
61
+
60
62
  @raw_data["groups"].each do |group_name, group_info|
61
63
  validate_group_entry(group_name, group_info)
62
64
  end
@@ -67,22 +69,23 @@ module Inspec
67
69
  raise Inspec::Deprecation::InvalidConfigFileError, "Missing file_version field"
68
70
  end
69
71
  unless @raw_data["file_version"] == "1.0.0"
70
- raise Inspec::Deprecation::InvalidConfigFileError, "Unrecognized file_version '#{@raw_data['file_version']}' - supported versions: 1.0.0"
72
+ raise Inspec::Deprecation::InvalidConfigFileError, "Unrecognized file_version '#{@raw_data["file_version"]}' - supported versions: 1.0.0"
71
73
  end
72
74
  end
73
75
 
74
76
  def validate_unknown_group_action
75
77
  seen_action = (@raw_data["unknown_group_action"] || @unknown_group_action).to_sym
76
78
  unless VALID_ACTIONS.include?(seen_action)
77
- raise Inspec::Deprecation::UnrecognizedActionError, "Unrecognized value '#{seen_action}' for field 'unknown_group_action' - supported actions: #{VALID_ACTIONS.map(&:to_s).join(', ')}"
79
+ raise Inspec::Deprecation::UnrecognizedActionError, "Unrecognized value '#{seen_action}' for field 'unknown_group_action' - supported actions: #{VALID_ACTIONS.map(&:to_s).join(", ")}"
78
80
  end
81
+
79
82
  @unknown_group_action = seen_action
80
83
  end
81
84
 
82
85
  def validate_group_entry(name, opts)
83
86
  opts.each do |seen_field, _value|
84
87
  unless VALID_GROUP_FIELDS.include?(seen_field)
85
- raise Inspec::Deprecation::InvalidConfigFileError, "Unrecognized field for group '#{name}' - saw '#{seen_field}', supported fields: #{VALID_GROUP_FIELDS.map(&:to_s).join(', ')}"
88
+ raise Inspec::Deprecation::InvalidConfigFileError, "Unrecognized field for group '#{name}' - saw '#{seen_field}', supported fields: #{VALID_GROUP_FIELDS.map(&:to_s).join(", ")}"
86
89
  end
87
90
  end
88
91
 
@@ -90,8 +93,9 @@ module Inspec
90
93
 
91
94
  opts["action"] = (opts["action"] || :warn).to_sym
92
95
  unless VALID_ACTIONS.include?(opts["action"])
93
- raise Inspec::Deprecation::UnrecognizedActionError, "Unrecognized action for group '#{name}' - saw '#{opts['action']}', supported actions: #{VALID_ACTIONS.map(&:to_s).join(', ')}"
96
+ raise Inspec::Deprecation::UnrecognizedActionError, "Unrecognized action for group '#{name}' - saw '#{opts["action"]}', supported actions: #{VALID_ACTIONS.map(&:to_s).join(", ")}"
94
97
  end
98
+
95
99
  entry.action = opts["action"]
96
100
 
97
101
  entry.suffix = opts["suffix"]
@@ -94,6 +94,7 @@ class ErlangBitstream
94
94
  def bit_size(size, type)
95
95
  raise "Cannot specify size and type at the same time." if !type.nil? && !size.nil?
96
96
  return (size || 8).to_i if type.nil?
97
+
97
98
  TYPES[type] || raise("Cannot handle binary-stream type #{type}")
98
99
  end
99
100
 
@@ -101,6 +102,7 @@ class ErlangBitstream
101
102
  if i[:integer].nil? && i[:string].nil?
102
103
  raise "No data provided, internal error for binary-stream processing!"
103
104
  end
105
+
104
106
  s = bit_size(i[:size], i[:type])
105
107
  unless i[:string].nil?
106
108
  str2int(i[:string].to_s, i[:type]).map { |e| add_bits(int2bits(e, 8)) }
@@ -6,7 +6,7 @@ module FileReader
6
6
  # pre-refactor (which used skip_resource). These should likely be changed to
7
7
  # ResourceFailed during a major version bump.
8
8
  file = inspec.file(path)
9
- if !file.file?
9
+ unless file.file?
10
10
  raise Inspec::Exceptions::ResourceSkipped, "Can't find file: #{path}"
11
11
  end
12
12