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
@@ -82,8 +82,9 @@ module Inspec::Resources
82
82
  end
83
83
 
84
84
  def iis_site
85
- return @cache if !@cache.nil?
86
- @cache = @site_provider.iis_site(@site_name) if !@site_provider.nil?
85
+ return @cache unless @cache.nil?
86
+
87
+ @cache = @site_provider.iis_site(@site_name) unless @site_provider.nil?
87
88
  end
88
89
  end
89
90
 
@@ -106,7 +107,7 @@ module Inspec::Resources
106
107
  end
107
108
 
108
109
  bindings_array = site["bindings"]["Collection"].map do |k|
109
- "#{k['protocol']} #{k['bindingInformation']}#{k['protocol'] == 'https' ? " sslFlags=#{k['sslFlags']}" : ''}"
110
+ "#{k["protocol"]} #{k["bindingInformation"]}#{k["protocol"] == "https" ? " sslFlags=#{k["sslFlags"]}" : ""}"
110
111
  end
111
112
 
112
113
  # map our values to a hash table
@@ -61,13 +61,13 @@ module Inspec::Resources
61
61
 
62
62
  def ipv4_addresses_netmask
63
63
  ipv4_cidrs.map { |i| i.split("/") }.map do |addr, netlen|
64
- binmask = "#{'1' * netlen.to_i}#{'0' * (32 - netlen.to_i)}".to_i(2)
64
+ binmask = "#{"1" * netlen.to_i}#{"0" * (32 - netlen.to_i)}".to_i(2)
65
65
  netmask = []
66
66
  (1..4).each do |_byte|
67
67
  netmask.unshift(binmask & 255)
68
68
  binmask = binmask >> 8
69
69
  end
70
- "#{addr}/#{netmask.join('.')}"
70
+ "#{addr}/#{netmask.join(".")}"
71
71
  end
72
72
  end
73
73
 
@@ -87,7 +87,8 @@ module Inspec::Resources
87
87
 
88
88
  def interface_info
89
89
  return @cache if defined?(@cache)
90
- @cache = @interface_provider.interface_info(@iface) if !@interface_provider.nil?
90
+
91
+ @cache = @interface_provider.interface_info(@iface) unless @interface_provider.nil?
91
92
  end
92
93
  end
93
94
 
@@ -142,6 +143,7 @@ module Inspec::Resources
142
143
  [4, 6].each do |v|
143
144
  cmd = inspec.command("/sbin/ip -br -#{v} address show dev #{iface}")
144
145
  next unless cmd.exit_status.to_i == 0
146
+
145
147
  family = v == 6 ? "inet6" : "inet"
146
148
 
147
149
  cmd.stdout.each_line do |line|
@@ -171,8 +173,8 @@ module Inspec::Resources
171
173
  end
172
174
 
173
175
  # ensure we have an array of groups
174
- net_adapter = [net_adapter] if !net_adapter.is_a?(Array)
175
- addresses = [addresses] if !addresses.is_a?(Array)
176
+ net_adapter = [net_adapter] unless net_adapter.is_a?(Array)
177
+ addresses = [addresses] unless addresses.is_a?(Array)
176
178
 
177
179
  # select the requested interface
178
180
  adapters = net_adapter.each_with_object([]) do |adapter, adapter_collection|
@@ -188,6 +190,7 @@ module Inspec::Resources
188
190
  end
189
191
 
190
192
  return nil if adapters.empty?
193
+
191
194
  warn "[Possible Error] detected multiple network interfaces with the name #{iface}" if adapters.size > 1
192
195
  adapters[0]
193
196
  end
@@ -196,8 +199,8 @@ module Inspec::Resources
196
199
 
197
200
  def addresses_for_proto(all_addresses, iface, proto)
198
201
  all_addresses.select { |i| i["InterfaceAlias"] == iface }
199
- .map { |i| "#{i["#{proto}Address"]}/#{i['PrefixLength']}" unless i["#{proto}Address"].nil? }
200
- .compact
202
+ .map { |i| "#{i["#{proto}Address"]}/#{i["PrefixLength"]}" unless i["#{proto}Address"].nil? }
203
+ .compact
201
204
  end
202
205
  end
203
206
  end
@@ -59,7 +59,7 @@ module Inspec::Resources
59
59
  end
60
60
 
61
61
  def to_s
62
- "#{resource_base_name} #{@resource_name_supplement || 'content'}"
62
+ "#{resource_base_name} #{@resource_name_supplement || "content"}"
63
63
  end
64
64
 
65
65
  private
@@ -36,7 +36,7 @@ module Inspec::Resources
36
36
  def initialize(modulename = nil)
37
37
  @module = modulename
38
38
  # this resource is only supported on Linux
39
- return skip_resource "The `kernel_parameter` resource is not supported on your OS." if !inspec.os.linux?
39
+ return skip_resource "The `kernel_parameter` resource is not supported on your OS." unless inspec.os.linux?
40
40
  end
41
41
 
42
42
  def loaded?
@@ -15,12 +15,13 @@ module Inspec::Resources
15
15
  @parameter = parameter
16
16
 
17
17
  # this resource is only supported on Linux
18
- return skip_resource "The `kernel_parameter` resource is not supported on your OS." if !inspec.os.linux?
18
+ return skip_resource "The `kernel_parameter` resource is not supported on your OS." unless inspec.os.linux?
19
19
  end
20
20
 
21
21
  def value
22
22
  cmd = inspec.command("/sbin/sysctl -q -n #{@parameter}")
23
23
  return nil if cmd.exit_status != 0
24
+
24
25
  # remove whitespace
25
26
  cmd = cmd.stdout.chomp.strip
26
27
  # convert to number if possible
@@ -31,26 +31,31 @@ module Inspec::Resources
31
31
 
32
32
  def public?
33
33
  return if @key.nil?
34
+
34
35
  @key.public?
35
36
  end
36
37
 
37
38
  def public_key
38
39
  return if @key.nil?
40
+
39
41
  @key.public_key.to_s
40
42
  end
41
43
 
42
44
  def private?
43
45
  return if @key.nil?
46
+
44
47
  @key.private?
45
48
  end
46
49
 
47
50
  def private_key
48
51
  return if @key.nil?
52
+
49
53
  @key.to_s
50
54
  end
51
55
 
52
56
  def key_length
53
57
  return if @key.nil?
58
+
54
59
  @key.public_key.n.num_bytes * 8
55
60
  end
56
61
 
@@ -21,6 +21,7 @@ module Inspec::Resources
21
21
  @path = path
22
22
  @mount_manager = mount_manager_for_os
23
23
  return skip_resource "The `mount` resource is not supported on your OS yet." if @mount_manager.nil?
24
+
24
25
  @file = inspec.backend.file(@path)
25
26
  end
26
27
 
@@ -31,11 +32,12 @@ module Inspec::Resources
31
32
  def count
32
33
  mounted = file.mounted
33
34
  return nil if mounted.nil? || mounted.stdout.nil?
35
+
34
36
  mounted.stdout.lines.count
35
37
  end
36
38
 
37
39
  def method_missing(name)
38
- return nil if !file.mounted?
40
+ return nil unless file.mounted?
39
41
 
40
42
  mounted = file.mounted
41
43
  return nil if mounted.nil? || mounted.stdout.nil?
@@ -17,11 +17,12 @@ module Inspec::Resources
17
17
  k = name.to_s
18
18
  res = @params[k]
19
19
  return true if res.nil? && @params.key?(k)
20
+
20
21
  @params[k]
21
22
  end
22
23
 
23
24
  def to_s
24
- "MySQL Config entry [#{@path.join(' ')}]"
25
+ "MySQL Config entry [#{@path.join(" ")}]"
25
26
  end
26
27
  end
27
28
 
@@ -112,6 +113,7 @@ module Inspec::Resources
112
113
 
113
114
  def abs_path(dir, f)
114
115
  return f if f.start_with? "/"
116
+
115
117
  File.join(dir, f)
116
118
  end
117
119
 
@@ -73,12 +73,14 @@ module Inspec::Resources
73
73
  def init_fallback
74
74
  # support debian mysql administration login
75
75
  return if inspec.platform.in_family?("windows")
76
+
76
77
  debian = inspec.command("test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf").stdout
77
78
  return if debian.empty?
78
79
 
79
80
  user = debian.match(/^\s*user\s*=\s*([^ ]*)\s*$/)
80
81
  pass = debian.match(/^\s*password\s*=\s*([^ ]*)\s*$/)
81
82
  return if user.nil? || pass.nil?
83
+
82
84
  @user = user[1]
83
85
  @pass = pass[1]
84
86
  end
@@ -28,6 +28,7 @@ module Inspec::Resources
28
28
  if cmd.exit_status != 0
29
29
  return skip_resource "Error using the command nginx -V"
30
30
  end
31
+
31
32
  @data = cmd.stdout
32
33
  @params = {}
33
34
  read_content
@@ -33,6 +33,7 @@ module Inspec::Resources
33
33
  @conf_path = conf_path || "/etc/nginx/nginx.conf"
34
34
  @contents = {}
35
35
  return skip_resource "The `nginx_conf` resource is currently not supported on Windows." if inspec.os.windows?
36
+
36
37
  read_content(@conf_path)
37
38
  end
38
39
 
@@ -57,11 +58,13 @@ module Inspec::Resources
57
58
 
58
59
  def read_content(path)
59
60
  return @contents[path] if @contents.key?(path)
61
+
60
62
  @contents[path] = read_file_content(path, allow_empty: true)
61
63
  end
62
64
 
63
65
  def parse_nginx(path)
64
66
  return nil if inspec.os.windows?
67
+
65
68
  content = read_content(path)
66
69
 
67
70
  # Don't attempt to parse file if it contains only comments or is empty
@@ -96,10 +99,10 @@ module Inspec::Resources
96
99
  # into the current data structure
97
100
  if data.key?("include")
98
101
  data.delete("include").flatten
99
- .map { |x| File.expand_path(x, rel_path) }
100
- .map { |x| find_files(x) }.flatten
101
- .map { |path| parse_nginx(path) }
102
- .each { |conf| merge_config!(data, conf) }
102
+ .map { |x| File.expand_path(x, rel_path) }
103
+ .map { |x| find_files(x) }.flatten
104
+ .map { |path| parse_nginx(path) }
105
+ .each { |conf| merge_config!(data, conf) }
103
106
  end
104
107
 
105
108
  # Walk through the remaining hash fields to find more references
@@ -114,6 +117,7 @@ module Inspec::Resources
114
117
  def merge_config!(data, conf)
115
118
  # Catch edge-cases
116
119
  return if data.nil? || conf.nil?
120
+
117
121
  # Step through all conf items and create combined return value
118
122
  data.merge!(conf) do |_, v1, v2|
119
123
  if v1.is_a?(Array) && v2.is_a?(Array)
@@ -160,7 +164,7 @@ module Inspec::Resources
160
164
 
161
165
  filter = FilterTable.create
162
166
  filter.register_column(:servers, field: "server")
163
- .install_filter_methods_on_resource(self, :server_table)
167
+ .install_filter_methods_on_resource(self, :server_table)
164
168
 
165
169
  def locations
166
170
  servers.map(&:locations).flatten
@@ -187,7 +191,7 @@ module Inspec::Resources
187
191
 
188
192
  filter = FilterTable.create
189
193
  filter.register_column(:locations, field: "location")
190
- .install_filter_methods_on_resource(self, :location_table)
194
+ .install_filter_methods_on_resource(self, :location_table)
191
195
 
192
196
  def to_s
193
197
  server = ""
@@ -26,6 +26,7 @@ module Inspec::Resources
26
26
  param = read_params[name.to_s]
27
27
  # extract first value if we have only one value in array
28
28
  return param[0] if param.is_a?(Array) && (param.length == 1)
29
+
29
30
  param
30
31
  end
31
32
 
@@ -23,7 +23,7 @@ module Inspec::Resources
23
23
  @package_name = package_name
24
24
 
25
25
  # verify that this resource is only supported on Windows
26
- return skip_resource "The `oneget` resource is not supported on your OS." if !inspec.os.windows?
26
+ return skip_resource "The `oneget` resource is not supported on your OS." unless inspec.os.windows?
27
27
  end
28
28
 
29
29
  def info
@@ -36,6 +36,7 @@ module Inspec::Resources
36
36
 
37
37
  # connection as sysdba stuff
38
38
  return skip_resource "Option 'as_os_user' not available in Windows" if inspec.os.windows? && opts[:as_os_user]
39
+
39
40
  @su_user = opts[:as_os_user]
40
41
  @db_role = opts[:as_db_role]
41
42
 
@@ -93,7 +94,7 @@ module Inspec::Resources
93
94
 
94
95
  def verify_query(query)
95
96
  # ensure we have a ; at the end
96
- query + ";" if !query.strip.end_with?(";")
97
+ query + ";" unless query.strip.end_with?(";")
97
98
  query
98
99
  end
99
100
 
@@ -121,7 +122,7 @@ module Inspec::Resources
121
122
  doc = REXML::Document.new result
122
123
  table = doc.elements["table"]
123
124
  hash = []
124
- if !table.nil?
125
+ unless table.nil?
125
126
  rows = table.elements.to_a
126
127
  headers = rows[0].elements.to_a("th").map { |entry| entry.text.strip }
127
128
  rows.delete_at(0)
@@ -134,6 +135,7 @@ module Inspec::Resources
134
135
  entries = row.elements.to_a("td")
135
136
  # ignore if we have empty entries, oracle is adding th rows in between
136
137
  return nil if entries.empty?
138
+
137
139
  headers.each_with_index do |header, index|
138
140
  # we need htmlentities since we do not have nokogiri
139
141
  coder = HTMLEntities.new
@@ -43,6 +43,7 @@ module Inspec::Resources
43
43
 
44
44
  def content
45
45
  return @content if defined?(@content)
46
+
46
47
  @content = value_for(@osenv, @target) unless @osenv.nil?
47
48
  end
48
49
 
@@ -65,11 +65,12 @@ module Inspec::Resources
65
65
 
66
66
  # returns the package description
67
67
  def info
68
- return @cache if !@cache.nil?
68
+ return @cache unless @cache.nil?
69
69
  # All `@pkgman.info` methods return `{}`. This matches that
70
70
  # behavior if `@pkgman` can't be determined, thus avoiding the
71
71
  # `undefined method 'info' for nil:NilClass` error
72
72
  return {} if @pkgman.nil?
73
+
73
74
  @pkgman.info(@package_name)
74
75
  end
75
76
 
@@ -88,6 +89,7 @@ module Inspec::Resources
88
89
  def evaluate_missing_requirements
89
90
  missing_requirements_string = @pkgman.missing_requirements.uniq.join(", ")
90
91
  return if missing_requirements_string.empty?
92
+
91
93
  raise Inspec::Exceptions::ResourceSkipped, "The following requirements are not met for this resource: #{missing_requirements_string}"
92
94
  end
93
95
  end
@@ -154,6 +156,7 @@ module Inspec::Resources
154
156
  # CentOS does not return an error code if the package is not installed,
155
157
  # therefore we need to check for emptyness
156
158
  return {} if cmd.exit_status.to_i != 0 || cmd.stdout.chomp.empty?
159
+
157
160
  params = SimpleConfig.new(
158
161
  cmd.stdout.chomp,
159
162
  assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
@@ -214,8 +217,8 @@ module Inspec::Resources
214
217
  }
215
218
  rescue JSON::ParserError => e
216
219
  raise Inspec::Exceptions::ResourceFailed,
217
- "Failed to parse JSON from `brew` command. " \
218
- "Error: #{e}"
220
+ "Failed to parse JSON from `brew` command. " \
221
+ "Error: #{e}"
219
222
  end
220
223
  end
221
224
 
@@ -244,6 +247,7 @@ module Inspec::Resources
244
247
  def info(package_name)
245
248
  cmd = inspec.command("swlist -l product | grep #{package_name}")
246
249
  return {} if cmd.exit_status.to_i != 0
250
+
247
251
  pkg = cmd.stdout.strip.split(" ")
248
252
  {
249
253
  name: pkg[0],
@@ -303,8 +307,8 @@ module Inspec::Resources
303
307
  package = JSON.parse(cmd.stdout)
304
308
  rescue JSON::ParserError => e
305
309
  raise Inspec::Exceptions::ResourceFailed,
306
- "Failed to parse JSON from PowerShell. " \
307
- "Error: #{e}"
310
+ "Failed to parse JSON from PowerShell. " \
311
+ "Error: #{e}"
308
312
  end
309
313
 
310
314
  # What if we match multiple packages? just pick the first one for now.
@@ -381,7 +385,7 @@ module Inspec::Resources
381
385
  name: params["Name"],
382
386
  installed: true,
383
387
  # 0.5.11-0.175.3.1.0.5.0
384
- version: "#{params['Version']}-#{params['Branch']}",
388
+ version: "#{params["Version"]}-#{params["Branch"]}",
385
389
  type: "pkg",
386
390
  }
387
391
  end
@@ -42,11 +42,11 @@ module Inspec::Resources
42
42
  end
43
43
 
44
44
  filter = FilterTable.create
45
- filter.register_column(:statuses, field: "status", style: :simple)
46
- .register_column(:names, field: "name")
47
- .register_column(:versions, field: "version")
48
- .register_column(:architectures, field: "architecture")
49
- .install_filter_methods_on_resource(self, :filtered_packages)
45
+ filter.register_column(:statuses, field: "status", style: :simple)
46
+ .register_column(:names, field: "name")
47
+ .register_column(:versions, field: "version")
48
+ .register_column(:architectures, field: "architecture")
49
+ .install_filter_methods_on_resource(self, :filtered_packages)
50
50
 
51
51
  private
52
52
 
@@ -82,6 +82,7 @@ module Inspec::Resources
82
82
  cmd = inspec.command(command)
83
83
  all = cmd.stdout.split("\n")
84
84
  return [] if all.nil?
85
+
85
86
  all.map do |m|
86
87
  a = m.split(/ {2,}/)
87
88
  a[0] = "installed" if a[0] =~ /^.i/
@@ -99,6 +100,7 @@ module Inspec::Resources
99
100
  cmd = inspec.command(command)
100
101
  all = cmd.stdout.split("\n")
101
102
  return [] if all.nil?
103
+
102
104
  all.map do |m|
103
105
  a = m.split(" ")
104
106
  a.unshift("installed")
@@ -49,13 +49,13 @@ module Inspec::Resources
49
49
  end
50
50
 
51
51
  filter = FilterTable.create
52
- filter.register_column(:users, field: "user")
53
- .register_column(:passwords, field: "password")
54
- .register_column(:uids, field: "uid")
55
- .register_column(:gids, field: "gid")
56
- .register_column(:descs, field: "desc")
57
- .register_column(:homes, field: "home")
58
- .register_column(:shells, field: "shell")
52
+ filter.register_column(:users, field: "user")
53
+ .register_column(:passwords, field: "password")
54
+ .register_column(:uids, field: "uid")
55
+ .register_column(:gids, field: "gid")
56
+ .register_column(:descs, field: "desc")
57
+ .register_column(:homes, field: "home")
58
+ .register_column(:shells, field: "shell")
59
59
 
60
60
  # rebuild the passwd line from raw content
61
61
  filter.register_custom_property(:content) do |t, _|