inspec-core 4.37.20 → 4.37.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e824612959dfc0663c92583fa5a542300d6953bcd32b28cfabf48b0709b9bf6
4
- data.tar.gz: 79edead9df8512f94c9472bead2afd509b080f30e68630c912208734dc0b7bf1
3
+ metadata.gz: c9e4ef72fd93cf8c9de6cf6a6b14473388a1df8edee971d3e9db0dc89e31a756
4
+ data.tar.gz: 79ab3e58e1f574f6bd34aff949a965ed7c01744745cb09eba4768a420f9fe60b
5
5
  SHA512:
6
- metadata.gz: fba880eaf388b7ebb28a731ddaaab23a6c0b4f8a75ee70315c75f68d05445cc32c7c09109e5f9a696d8257111d5cf520409bf2d18079255fc7cce9376a3e87e3
7
- data.tar.gz: e5bf78b8ee6a067ca8762326093f92c26f97b1c102b0198ec3a494a520bb0a6fc137ff2d6f992e36e3ff690389c2082b3f92484a79266e91e7359a25d8719df7
6
+ metadata.gz: c1254e07b8263b7f97c53a3a3768db4fd50692d49defe607e2f7ceb42fce86c6a53909472e0b28fe7cbb58cfcdb6255dd549adaca18836ba2475f8644dab4153
7
+ data.tar.gz: 8b45db91165ebd6a9af3102a4a4f60e9cf1fd404f5cc28452cc4df92e1554cce42a009e40b6a11de1d13569bada66a270d344076965138d32e52aea045a8ca52
@@ -120,6 +120,11 @@
120
120
  "object_classes": {
121
121
  "action": "warn",
122
122
  "suffix": "These classes will be removed in InSpec 5.0."
123
+ },
124
+ "cli_option_hook":{
125
+ "action": "warn",
126
+ "prefix": "The --hook option is being replaced by the --activator option.",
127
+ "suffix": "This options will be removed in InSpec 4.0."
123
128
  }
124
129
  }
125
130
  }
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.37.20".freeze
2
+ VERSION = "4.37.23".freeze
3
3
  end
@@ -24,16 +24,8 @@ module InspecPlugins
24
24
  # the username of the account is used that is logged in
25
25
  def self.profiles(config, profile_filter = nil) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
26
26
  owner = config["owner"] || config["user"]
27
-
28
- # Chef Compliance
29
- if is_compliance_server?(config)
30
- url = "#{config["server"]}/user/compliance"
31
- # Chef Automate2
32
- elsif is_automate2_server?(config)
27
+ if is_automate2_server?(config)
33
28
  url = "#{config["server"]}/compliance/profiles/search"
34
- # Chef Automate
35
- elsif is_automate_server?(config)
36
- url = "#{config["server"]}/profiles/#{owner}"
37
29
  else
38
30
  raise ServerConfigurationMissing
39
31
  end
@@ -45,12 +37,9 @@ module InspecPlugins
45
37
  id, ver = nil
46
38
  end
47
39
 
48
- if is_automate2_server?(config)
49
- body = { owner: owner, name: id }.to_json
50
- response = InspecPlugins::Compliance::HTTP.post_with_headers(url, headers, body, config["insecure"])
51
- else
52
- response = InspecPlugins::Compliance::HTTP.get(url, headers, config["insecure"])
53
- end
40
+ body = { owner: owner, name: id }.to_json
41
+ response = InspecPlugins::Compliance::HTTP.post_with_headers(url, headers, body, config["insecure"])
42
+
54
43
  data = response.body
55
44
  response_code = response.code
56
45
  case response_code
@@ -58,25 +47,12 @@ module InspecPlugins
58
47
  msg = "success"
59
48
  profiles = JSON.parse(data)
60
49
  # iterate over profiles
61
- if is_compliance_server?(config)
62
- mapped_profiles = []
63
- profiles.values.each do |org|
64
- mapped_profiles += org.values
65
- end
66
- # Chef Automate pre 0.8.0
67
- elsif is_automate_server_pre_080?(config)
68
- mapped_profiles = profiles.values.flatten
69
- elsif is_automate2_server?(config)
70
- mapped_profiles = []
71
- profiles["profiles"].each do |p|
72
- mapped_profiles << p
73
- end
74
- else
75
- mapped_profiles = profiles.map do |e|
76
- e["owner_id"] = owner
77
- e
78
- end
50
+
51
+ mapped_profiles = []
52
+ profiles["profiles"].each do |p|
53
+ mapped_profiles << p
79
54
  end
55
+
80
56
  # filter by name and version if they were specified in profile_filter
81
57
  mapped_profiles.select! do |p|
82
58
  (!ver || p["version"] == ver) && (!id || p["name"] == id)
@@ -120,26 +96,9 @@ module InspecPlugins
120
96
  end
121
97
 
122
98
  def self.upload(config, owner, profile_name, archive_path)
123
- # Chef Compliance
124
- if is_compliance_server?(config)
125
- url = "#{config["server"]}/owners/#{owner}/compliance/#{profile_name}/tar"
126
- # Chef Automate pre 0.8.0
127
- elsif is_automate_server_pre_080?(config)
128
- url = "#{config["server"]}/#{owner}"
129
- elsif is_automate2_server?(config)
130
- url = "#{config["server"]}/compliance/profiles?owner=#{owner}"
131
- # Chef Automate
132
- else
133
- url = "#{config["server"]}/profiles/#{owner}"
134
- end
135
-
99
+ url = "#{config["server"]}/compliance/profiles?owner=#{owner}"
136
100
  headers = get_headers(config)
137
- if is_automate2_server?(config)
138
- res = InspecPlugins::Compliance::HTTP.post_multipart_file(url, headers, archive_path, config["insecure"])
139
- else
140
- res = InspecPlugins::Compliance::HTTP.post_file(url, headers, archive_path, config["insecure"])
141
- end
142
-
101
+ res = InspecPlugins::Compliance::HTTP.post_multipart_file(url, headers, archive_path, config["insecure"])
143
102
  [res.is_a?(Net::HTTPSuccess), res.body]
144
103
  end
145
104
 
@@ -210,16 +169,12 @@ module InspecPlugins
210
169
 
211
170
  def self.get_headers(config)
212
171
  token = get_token(config)
213
- if is_automate_server?(config) || is_automate2_server?(config)
214
- headers = { "chef-delivery-enterprise" => config["automate"]["ent"] }
215
- if config["automate"]["token_type"] == "dctoken"
216
- headers["x-data-collector-token"] = token
217
- else
218
- headers["chef-delivery-user"] = config["user"]
219
- headers["chef-delivery-token"] = token
220
- end
172
+ headers = { "chef-delivery-enterprise" => config["automate"]["ent"] }
173
+ if config["automate"]["token_type"] == "dctoken"
174
+ headers["x-data-collector-token"] = token
221
175
  else
222
- headers = { "Authorization" => "Bearer #{token}" }
176
+ headers["chef-delivery-user"] = config["user"]
177
+ headers["chef-delivery-token"] = token
223
178
  end
224
179
  headers
225
180
  end
@@ -232,16 +187,7 @@ module InspecPlugins
232
187
  end
233
188
 
234
189
  def self.target_url(config, profile)
235
- owner, id, ver = profile_split(profile)
236
-
237
- return "#{config["server"]}/compliance/profiles/tar" if is_automate2_server?(config)
238
- return "#{config["server"]}/owners/#{owner}/compliance/#{id}/tar" unless is_automate_server?(config)
239
-
240
- if ver.nil?
241
- "#{config["server"]}/profiles/#{owner}/#{id}/tar"
242
- else
243
- "#{config["server"]}/profiles/#{owner}/#{id}/version/#{ver}/tar"
244
- end
190
+ "#{config["server"]}/compliance/profiles/tar"
245
191
  end
246
192
 
247
193
  def self.profile_split(profile)
@@ -260,33 +206,6 @@ module InspecPlugins
260
206
  uri.to_s.sub(%r{^compliance:\/\/}, "")
261
207
  end
262
208
 
263
- def self.is_compliance_server?(config)
264
- config["server_type"] == "compliance"
265
- end
266
-
267
- def self.is_automate_server_pre_080?(config)
268
- # Automate versions before 0.8.x do not have a valid version in the config
269
- return false unless config["server_type"] == "automate"
270
-
271
- server_version_from_config(config).nil?
272
- end
273
-
274
- def self.is_automate_server_080_and_later?(config)
275
- # Automate versions 0.8.x and later will have a "version" key in the config
276
- # that is properly parsed out via server_version_from_config below
277
- return false unless config["server_type"] == "automate"
278
-
279
- !server_version_from_config(config).nil?
280
- end
281
-
282
- def self.is_automate2_server?(config)
283
- config["server_type"] == "automate2"
284
- end
285
-
286
- def self.is_automate_server?(config)
287
- config["server_type"] == "automate"
288
- end
289
-
290
209
  def self.server_version_from_config(config)
291
210
  # Automate versions 0.8.x and later will have a "version" key in the config
292
211
  # that looks like: "version":{"api":"compliance","version":"0.8.24"}
@@ -296,87 +215,8 @@ module InspecPlugins
296
215
  config["version"]["version"]
297
216
  end
298
217
 
299
- def self.determine_server_type(url, insecure)
300
- if target_is_automate2_server?(url, insecure)
301
- :automate2
302
- elsif target_is_automate_server?(url, insecure)
303
- :automate
304
- elsif target_is_compliance_server?(url, insecure)
305
- :compliance
306
- else
307
- Inspec::Log.debug("Could not determine server type using known endpoints")
308
- nil
309
- end
310
- end
311
-
312
- def self.target_is_automate2_server?(url, insecure)
313
- automate_endpoint = "/dex/auth"
314
- response = InspecPlugins::Compliance::HTTP.get(url + automate_endpoint, nil, insecure)
315
- if response.code == "400"
316
- Inspec::Log.debug(
317
- "Received 400 from #{url}#{automate_endpoint} - " \
318
- "assuming target is a #{AUTOMATE_PRODUCT_NAME}2 instance"
319
- )
320
- true
321
- else
322
- Inspec::Log.debug(
323
- "Received #{response.code} from #{url}#{automate_endpoint} - " \
324
- "assuming target is not an #{AUTOMATE_PRODUCT_NAME}2 instance"
325
- )
326
- false
327
- end
328
- end
329
-
330
- def self.target_is_automate_server?(url, insecure)
331
- automate_endpoint = "/compliance/version"
332
- response = InspecPlugins::Compliance::HTTP.get(url + automate_endpoint, nil, insecure)
333
- case response.code
334
- when "401"
335
- Inspec::Log.debug(
336
- "Received 401 from #{url}#{automate_endpoint} - " \
337
- "assuming target is a #{AUTOMATE_PRODUCT_NAME} instance"
338
- )
339
- true
340
- when "200"
341
- # Chef Automate currently returns 401 for `/compliance/version` but some
342
- # versions of OpsWorks Chef Automate return 200 and a Chef Manage page
343
- # when unauthenticated requests are received.
344
- if response.body.include?("Are You Looking For the #{SERVER_PRODUCT_NAME}?")
345
- Inspec::Log.debug(
346
- "Received 200 from #{url}#{automate_endpoint} - " \
347
- "assuming target is an #{AUTOMATE_PRODUCT_NAME} instance"
348
- )
349
- true
350
- else
351
- Inspec::Log.debug(
352
- "Received 200 from #{url}#{automate_endpoint} " \
353
- "but did not receive the Chef Manage page - " \
354
- "assuming target is not a #{AUTOMATE_PRODUCT_NAME} instance"
355
- )
356
- false
357
- end
358
- else
359
- Inspec::Log.debug(
360
- "Received unexpected status code #{response.code} " \
361
- "from #{url}#{automate_endpoint} - " \
362
- "assuming target is not a #{AUTOMATE_PRODUCT_NAME} instance"
363
- )
364
- false
365
- end
366
- end
367
-
368
- def self.target_is_compliance_server?(url, insecure)
369
- # All versions of Chef Compliance return 200 for `/api/version`
370
- compliance_endpoint = "/api/version"
371
-
372
- response = InspecPlugins::Compliance::HTTP.get(url + compliance_endpoint, nil, insecure)
373
- return false unless response.code == "200"
374
-
375
- Inspec::Log.debug(
376
- "Received 200 from #{url}#{compliance_endpoint} - " \
377
- "assuming target is a #{AUTOMATE_PRODUCT_NAME} server"
378
- )
379
- true
218
+ def self.is_automate2_server?(config)
219
+ config["server_type"] == "automate2"
380
220
  end
381
221
  end
382
222
  end
@@ -11,20 +11,10 @@ module InspecPlugins
11
11
  def login(options)
12
12
  raise ArgumentError, "Please specify a server using `#{EXEC_NAME} automate login https://SERVER` or `#{EXEC_NAME} compliance login https://SERVER`" unless options["server"]
13
13
 
14
+ options["server_type"] = "automate2"
14
15
  options["server"] = URI("https://#{options["server"]}").to_s if URI(options["server"]).scheme.nil?
15
16
 
16
- options["server_type"] = InspecPlugins::Compliance::API.determine_server_type(options["server"], options["insecure"])
17
-
18
- case options["server_type"]
19
- when :automate2
20
- Login::Automate2Server.login(options)
21
- when :automate
22
- Login::AutomateServer.login(options)
23
- when :compliance
24
- Login::ComplianceServer.login(options)
25
- else
26
- raise CannotDetermineServerType, "Unable to determine if #{options["server"]} is a #{AUTOMATE_PRODUCT_NAME} or #{COMPLIANCE_PRODUCT_NAME} server"
27
- end
17
+ Login::Automate2Server.login(options)
28
18
  end
29
19
 
30
20
  module Automate2Server
@@ -48,7 +38,7 @@ module InspecPlugins
48
38
  config["user"] = options["user"]
49
39
  config["owner"] = options["user"]
50
40
  config["insecure"] = options["insecure"] || false
51
- config["server_type"] = options["server_type"].to_s
41
+ config["server_type"] = options["server_type"]
52
42
  config["token"] = token
53
43
  config["version"] = "0"
54
44
 
@@ -69,133 +59,6 @@ module InspecPlugins
69
59
  end
70
60
  end
71
61
 
72
- module AutomateServer
73
- def self.login(options)
74
- verify_thor_options(options)
75
-
76
- options["url"] = options["server"] + "/compliance"
77
- token = options["dctoken"] || options["token"]
78
- success, msg = API::Login.authenticate_login(options)
79
- success ? store_access_token(options, token) : msg
80
- end
81
-
82
- def self.store_access_token(options, token)
83
- token_type = if options["token"]
84
- "usertoken"
85
- else
86
- "dctoken"
87
- end
88
-
89
- config = InspecPlugins::Compliance::Configuration.new
90
-
91
- config.clean
92
-
93
- config["automate"] = {}
94
- config["automate"]["ent"] = options["ent"]
95
- config["automate"]["token_type"] = token_type
96
- config["server"] = options["url"]
97
- config["user"] = options["user"]
98
- config["insecure"] = options["insecure"] || false
99
- config["server_type"] = options["server_type"].to_s
100
- config["token"] = token
101
- config["version"] = InspecPlugins::Compliance::API.version(config)
102
-
103
- config.store
104
- API::Login.configuration_stored_message(config)
105
- end
106
-
107
- # Automate login requires `--ent`, `--user`, and either `--token` or `--dctoken`
108
- def self.verify_thor_options(o)
109
- error_msg = []
110
-
111
- error_msg.push("Please specify a user using `--user='USER'`") if o["user"].nil?
112
- error_msg.push("Please specify an enterprise using `--ent='automate'`") if o["ent"].nil?
113
-
114
- if o["token"].nil? && o["dctoken"].nil?
115
- error_msg.push("Please specify a token using `--token='AUTOMATE_TOKEN'` or `--dctoken='DATA_COLLECTOR_TOKEN'`")
116
- end
117
-
118
- raise ArgumentError, error_msg.join("\n") unless error_msg.empty?
119
- end
120
- end
121
-
122
- module ComplianceServer
123
- include Inspec::Dist
124
-
125
- def self.login(options)
126
- compliance_verify_thor_options(options)
127
-
128
- options["url"] = options["server"] + "/api"
129
-
130
- if options["user"] && options["token"]
131
- success, msg = API::Login.authenticate_login(options)
132
- success ? compliance_store_access_token(options, options["token"]) : msg
133
- elsif options["user"] && options["password"]
134
- compliance_login_user_pass(options)
135
- elsif options["refresh_token"]
136
- compliance_login_refresh_token(options)
137
- end
138
- end
139
-
140
- def self.compliance_login_user_pass(options)
141
- success, msg, token = InspecPlugins::Compliance::API.get_token_via_password(
142
- options["url"],
143
- options["user"],
144
- options["password"],
145
- options["insecure"]
146
- )
147
-
148
- raise msg unless success
149
-
150
- compliance_store_access_token(options, token)
151
- end
152
-
153
- def self.compliance_login_refresh_token(options)
154
- success, msg, token = InspecPlugins::Compliance::API.get_token_via_refresh_token(
155
- options["url"],
156
- options["refresh_token"],
157
- options["insecure"]
158
- )
159
-
160
- raise msg unless success
161
-
162
- compliance_store_access_token(options, token)
163
- end
164
-
165
- def self.compliance_store_access_token(options, token)
166
- config = InspecPlugins::Compliance::Configuration.new
167
- config.clean
168
-
169
- config["user"] = options["user"] if options["user"]
170
- config["server"] = options["url"]
171
- config["insecure"] = options["insecure"] || false
172
- config["server_type"] = options["server_type"].to_s
173
- config["token"] = token
174
- config["version"] = InspecPlugins::Compliance::API.version(config)
175
-
176
- config.store
177
- API::Login.configuration_stored_message(config)
178
- end
179
-
180
- # Compliance login requires `--user` or `--refresh_token`
181
- # If `--user` then either `--password`, `--token`, or `--refresh-token`, is required
182
- def self.compliance_verify_thor_options(o)
183
- error_msg = []
184
-
185
- error_msg.push("Please specify a server using `#{EXEC_NAME} automate login https://SERVER` or `#{EXEC_NAME} compliance login https://SERVER`") if o["server"].nil?
186
-
187
- if o["user"].nil? && o["refresh_token"].nil?
188
- error_msg.push("Please specify a `--user='USER'` or a `--refresh-token='TOKEN'`")
189
- end
190
-
191
- if o["user"] && o["password"].nil? && o["token"].nil? && o["refresh_token"].nil?
192
- error_msg.push("Please specify either a `--password`, `--token`, or `--refresh-token`")
193
- end
194
-
195
- raise ArgumentError, error_msg.join("\n") unless error_msg.empty?
196
- end
197
- end
198
-
199
62
  def self.authenticate_login(options)
200
63
  InspecPlugins::Compliance::API.authenticate_login_using_version_api(
201
64
  options["url"],
@@ -32,16 +32,8 @@ module InspecPlugins
32
32
 
33
33
  def self.check_compliance_token(uri, config)
34
34
  if config["token"].nil? && config["refresh_token"].nil?
35
- if config["server_type"] == "automate"
36
- server = "automate"
37
- msg = "#{EXEC_NAME} [automate|compliance] login https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --token USERTOKEN"
38
- elsif config["server_type"] == "automate2"
39
- server = "automate2"
40
- msg = "#{EXEC_NAME} [automate|compliance] login https://your_automate2_server --user USER --token APITOKEN"
41
- else
42
- server = "compliance"
43
- msg = "#{EXEC_NAME} [automate|compliance] login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' "
44
- end
35
+ server = "automate2"
36
+ msg = "#{EXEC_NAME} [automate|compliance] login https://your_automate2_server --user USER --token APITOKEN"
45
37
  raise Inspec::FetcherFailure, <<~EOF
46
38
 
47
39
  Cannot fetch #{uri} because your #{server} token has not been
@@ -119,19 +111,9 @@ module InspecPlugins
119
111
 
120
112
  # determine the owner_id and the profile name from the url
121
113
  def compliance_profile_name
122
- m = if InspecPlugins::Compliance::API.is_automate_server_pre_080?(@config)
123
- %r{^#{@config['server']}/(?<owner>[^/]+)/(?<id>[^/]+)/tar$}
124
- elsif InspecPlugins::Compliance::API.is_automate_server_080_and_later?(@config)
125
- %r{^#{@config['server']}/profiles/(?<owner>[^/]+)/(?<id>[^/]+)/tar$}
126
- else
127
- %r{^#{@config['server']}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}
128
- end.match(@target)
129
-
130
- if InspecPlugins::Compliance::API.is_automate2_server?(@config)
131
- m = {}
132
- m[:owner] = @config["profile"][0]
133
- m[:id] = @config["profile"][1]
134
- end
114
+ m = {}
115
+ m[:owner] = @config["profile"][0]
116
+ m[:id] = @config["profile"][1]
135
117
 
136
118
  if m.nil?
137
119
  raise "Unable to determine compliance profile name. This can be caused by " \
@@ -17,7 +17,8 @@ module InspecPlugins
17
17
  option :description, type: :string, default: "", desc: "Multi-line description of the plugin"
18
18
  option :summary, type: :string, default: "A plugin with a default summary", desc: "One-line summary of your plugin"
19
19
  option :license_name, type: :string, default: "Apache-2.0", desc: "The name of a license"
20
- option :hook, type: :array, default: ["cli_command:my_command"], desc: "A list of plugin hooks, in the form type1:name1, type2:name2, etc"
20
+ option :activator, type: :array, default: ["cli_command:my_command"], desc: "A list of plugin activators, in the form type1:name1, type2:name2, etc"
21
+ option :hook, type: :array, desc: "Legacy name for --activator - Deprecated."
21
22
  # These vars have calculated defaults
22
23
  option :homepage, type: :string, default: nil, desc: "A URL for your project, often a GitHub link"
23
24
  option :module_name, type: :string, default: nil, desc: "Module Name for your plugin package. Will change plugin name to CamelCase by default."
@@ -29,6 +30,12 @@ module InspecPlugins
29
30
  plugin_type = determine_plugin_type(plugin_name)
30
31
  snake_case = plugin_name.tr("-", "_")
31
32
 
33
+ # Handle deprecation of option --hook
34
+ unless options[:hook].nil?
35
+ Inspec.deprecate "cli_option_hook"
36
+ options[:activator] = options.delete(:hook)
37
+ end
38
+
32
39
  template_vars = {
33
40
  name: plugin_name,
34
41
  plugin_name: plugin_name,
@@ -41,7 +48,7 @@ module InspecPlugins
41
48
  templates_path: TEMPLATES_PATH,
42
49
  overwrite: options[:overwrite],
43
50
  file_rename_map: make_rename_map(plugin_type, plugin_name, snake_case),
44
- skip_files: make_skip_list(template_vars["hooks"].keys),
51
+ skip_files: make_skip_list(template_vars["activators"].keys),
45
52
  }
46
53
 
47
54
  renderer = InspecPlugins::Init::Renderer.new(ui, render_opts)
@@ -71,12 +78,15 @@ module InspecPlugins
71
78
  {
72
79
  "inspec-plugin-template.gemspec" => plugin_name + ".gemspec",
73
80
  File.join("lib", "inspec-plugin-template") => File.join("lib", plugin_name),
74
- File.join("lib", "inspec-plugin-template.rb") => File.join("lib", plugin_name + ".rb"),
75
- File.join("lib", "inspec-plugin-template", "cli_command.rb") => File.join("lib", plugin_name, "cli_command.rb"),
76
- File.join("lib", "inspec-plugin-template", "reporter.rb") => File.join("lib", plugin_name, "reporter.rb"),
77
- File.join("lib", "inspec-plugin-template", "plugin.rb") => File.join("lib", plugin_name, "plugin.rb"),
78
- File.join("lib", "inspec-plugin-template", "version.rb") => File.join("lib", plugin_name, "version.rb"),
79
- File.join("test", "functional", "inspec_plugin_template_test.rb") => File.join("test", "functional", snake_case + "_test.rb"),
81
+ File.join("lib", "inspec-plugin-template.erb") => File.join("lib", plugin_name + ".rb"),
82
+ File.join("lib", "inspec-plugin-template", "cli_command.erb") => File.join("lib", plugin_name, "cli_command.rb"),
83
+ File.join("lib", "inspec-plugin-template", "reporter.erb") => File.join("lib", plugin_name, "reporter.rb"),
84
+ File.join("lib", "inspec-plugin-template", "plugin.erb") => File.join("lib", plugin_name, "plugin.rb"),
85
+ File.join("lib", "inspec-plugin-template", "version.erb") => File.join("lib", plugin_name, "version.rb"),
86
+ File.join("test", "functional", "inspec_plugin_template_test.erb") => File.join("test", "functional", snake_case + "_test.rb"),
87
+ File.join("test", "unit", "cli_args_test.erb") => File.join("test", "unit", "cli_args_test.rb"),
88
+ File.join("test", "unit", "plugin_def_test.erb") => File.join("test", "unit", "plugin_def_test.rb"),
89
+ File.join("test", "helper.erb") => File.join("test", "helper.rb"),
80
90
  }
81
91
  end
82
92
 
@@ -93,7 +103,7 @@ module InspecPlugins
93
103
  ui.error("You requested interactive prompting for the template variables, but this does not seem to be an interactive terminal.")
94
104
  ui.exit(:usage_error)
95
105
  end
96
- vars.merge(parse_hook_option(options[:hook]))
106
+ vars.merge(parse_activator_option(options[:activator]))
97
107
  end
98
108
 
99
109
  def vars_from_defaults
@@ -121,7 +131,7 @@ module InspecPlugins
121
131
  ],
122
132
  },
123
133
  homepage: { default_setter: proc { options[:homepage] ||= "https://github.com/" + options[:author_email].split("@").first + "/" + options[:plugin_name] } },
124
- # TODO: Handle hooks, when we ever have more than one type of plugin
134
+ # TODO: Handle activators, when we ever have more than one type of plugin
125
135
  }
126
136
 
127
137
  prompt_for_options(order)
@@ -153,26 +163,26 @@ module InspecPlugins
153
163
  end
154
164
  end
155
165
 
156
- def parse_hook_option(raw_option)
157
- hooks_by_type = {}
166
+ def parse_activator_option(raw_option)
167
+ activators_by_type = {}
158
168
  raw_option.each do |entry|
159
169
  parts = entry.split(":")
160
170
  type = parts.first.to_sym
161
171
  name = parts.last
162
- if hooks_by_type.key?(type)
163
- ui.error "The InSpec plugin generator can currently only generate one hook of each type"
172
+ if activators_by_type.key?(type)
173
+ ui.error "The InSpec plugin generator can currently only generate one activator of each type"
164
174
  ui.exit(:usage_error)
165
175
  end
166
- hooks_by_type[type] = name
176
+ activators_by_type[type] = name
167
177
  end
168
178
 
169
- vars = { hooks: hooks_by_type }
170
- if hooks_by_type.key?(:cli_command)
171
- vars[:command_name_dashes] = hooks_by_type[:cli_command].tr("_", "-")
172
- vars[:command_name_snake] = hooks_by_type[:cli_command].tr("-", "_")
173
- elsif hooks_by_type.key?(:reporter)
174
- vars[:reporter_name_dashes] = hooks_by_type[:reporter].tr("_", "-")
175
- vars[:reporter_name_snake] = hooks_by_type[:reporter].tr("-", "_")
179
+ vars = { activators: activators_by_type }
180
+ if activators_by_type.key?(:cli_command)
181
+ vars[:command_name_dashes] = activators_by_type[:cli_command].tr("_", "-")
182
+ vars[:command_name_snake] = activators_by_type[:cli_command].tr("-", "_")
183
+ elsif activators_by_type.key?(:reporter)
184
+ vars[:reporter_name_dashes] = activators_by_type[:reporter].tr("_", "-")
185
+ vars[:reporter_name_snake] = activators_by_type[:reporter].tr("-", "_")
176
186
  end
177
187
  vars
178
188
  end
@@ -210,7 +220,7 @@ module InspecPlugins
210
220
  end
211
221
  end
212
222
 
213
- def make_skip_list(requested_hooks)
223
+ def make_skip_list(requested_activators)
214
224
  skips = []
215
225
  case options[:detail]
216
226
  when "full" # rubocop: disable Lint/EmptyWhen
@@ -230,13 +240,13 @@ module InspecPlugins
230
240
  "Rakefile",
231
241
  File.join("test", "fixtures", "README.md"),
232
242
  File.join("test", "fixtures"),
233
- File.join("test", "functional", "inspec_plugin_template_test.rb"),
243
+ File.join("test", "functional", "inspec_plugin_template_test.erb"),
234
244
  File.join("test", "functional", "README.md"),
235
- File.join("test", "unit", "cli_args_test.rb"),
236
- File.join("test", "unit", "plugin_def_test.rb"),
245
+ File.join("test", "unit", "cli_args_test.erb"),
246
+ File.join("test", "unit", "plugin_def_test.erb"),
237
247
  File.join("test", "unit", "README.md"),
238
248
  File.join("test", "unit"),
239
- File.join("test", "helper.rb"),
249
+ File.join("test", "helper.erb"),
240
250
  File.join("test"),
241
251
  ]
242
252
  else
@@ -244,17 +254,17 @@ module InspecPlugins
244
254
  ui.exit(:usage_error)
245
255
  end
246
256
 
247
- # Remove hook-specific files
248
- unless requested_hooks.include?(:cli_command)
257
+ # Remove activator-specific files
258
+ unless requested_activators.include?(:cli_command)
249
259
  skips += [
250
- File.join("lib", "inspec-plugin-template", "cli_command.rb"),
251
- File.join("test", "unit", "cli_args_test.rb"),
252
- File.join("test", "functional", "inspec_plugin_template_test.rb"),
260
+ File.join("lib", "inspec-plugin-template", "cli_command.erb"),
261
+ File.join("test", "unit", "cli_args_test.erb"),
262
+ File.join("test", "functional", "inspec_plugin_template_test.erb"),
253
263
  ]
254
264
  end
255
- unless requested_hooks.include?(:reporter)
265
+ unless requested_activators.include?(:reporter)
256
266
  skips += [
257
- File.join("lib", "inspec-plugin-template", "reporter.rb"),
267
+ File.join("lib", "inspec-plugin-template", "reporter.erb"),
258
268
  ]
259
269
  end
260
270
 
@@ -65,6 +65,7 @@ module InspecPlugins
65
65
  # read & render content
66
66
  content = render(File.read(source_file), template_values)
67
67
  # write file content
68
+
68
69
  File.write(full_destination_item_path, content)
69
70
  else
70
71
  ui.warning "Ignoring #{ui.emphasis(source_file)}, because its not an file or directoy"
@@ -1,11 +1,11 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'bundler'
7
- gem 'byebug'
8
- gem 'minitest'
9
- gem 'rake'
10
- gem 'rubocop', '= 0.49.1' # Need to keep in sync with main InSpec project, so config files will work
6
+ gem "bundler"
7
+ gem "byebug"
8
+ gem "minitest"
9
+ gem "rake"
10
+ gem "rubocop", "= 0.49.1" # Need to keep in sync with main InSpec project, so config files will work
11
11
  end
@@ -7,13 +7,13 @@
7
7
 
8
8
  # This task template will make a task named 'test', and run
9
9
  # the tests that it finds.
10
- require 'rake/testtask'
10
+ require "rake/testtask"
11
11
 
12
12
  Rake::TestTask.new do |t|
13
- t.libs.push 'lib'
13
+ t.libs.push "lib"
14
14
  t.test_files = FileList[
15
- 'test/unit/*_test.rb',
16
- 'test/functional/*_test.rb',
15
+ "test/unit/*_test.rb",
16
+ "test/functional/*_test.rb",
17
17
  ]
18
18
  t.verbose = true
19
19
  # Ideally, we'd run tests with warnings enabled,
@@ -26,15 +26,15 @@ end
26
26
  #------------------------------------------------------------------#
27
27
  # Code Style Tasks
28
28
  #------------------------------------------------------------------#
29
- require 'rubocop/rake_task'
29
+ require "rubocop/rake_task"
30
30
 
31
31
  RuboCop::RakeTask.new(:lint) do |t|
32
32
  # Choices of RuboCop rules to enforce are deeply personal.
33
33
  # Here, we set things up so that your plugin will use the Bundler-installed
34
34
  # inspec gem's copy of the InSpec project's rubocop.yml file (which
35
35
  # is indeed packaged with the inspec gem).
36
- require 'inspec/globals'
37
- inspec_rubocop_yml = File.join(Inspec.src_root, '.rubocop.yml')
36
+ require "inspec/globals"
37
+ inspec_rubocop_yml = File.join(Inspec.src_root, ".rubocop.yml")
38
38
 
39
- t.options = ['--display-cop-names', '--config', inspec_rubocop_yml]
39
+ t.options = ["--display-cop-names", "--config", inspec_rubocop_yml]
40
40
  end
@@ -4,23 +4,23 @@
4
4
 
5
5
  # It is traditional in a gemspec to dynamically load the current version
6
6
  # from a file in the source tree. The next three lines make that happen.
7
- lib = File.expand_path('../lib', __FILE__)
7
+ lib = File.expand_path("../lib", __FILE__)
8
8
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
- require '<%= plugin_name %>/version'
9
+ require "<%= plugin_name %>/version"
10
10
 
11
11
  Gem::Specification.new do |spec|
12
12
  # Importantly, all InSpec plugins must be prefixed with `inspec-` (most
13
13
  # plugins) or `train-` (plugins which add new connectivity features).
14
- spec.name = '<%= plugin_name %>'
14
+ spec.name = "<%= plugin_name %>"
15
15
 
16
16
  # It is polite to namespace your plugin under InspecPlugins::YourPluginInCamelCase
17
17
  spec.version = InspecPlugins::<%= module_name %>::VERSION
18
- spec.authors = ['<%= author_name %>']
19
- spec.email = ['<%= author_email %>']
20
- spec.summary = '<%= summary %>'
21
- spec.description = '<%= description %>'
22
- spec.homepage = '<%= homepage %>'
23
- spec.license = '<%= license_name %>'
18
+ spec.authors = ["<%= author_name %>"]
19
+ spec.email = ["<%= author_email %>"]
20
+ spec.summary = "<%= summary %>"
21
+ spec.description = "<%= description.is_a?(Array) ? description.join(" "): description %>"
22
+ spec.homepage = "<%= homepage %>"
23
+ spec.license = "<%= license_name %>"
24
24
 
25
25
  # Though complicated-looking, this is pretty standard for a gemspec.
26
26
  # It just filters what will actually be packaged in the gem (leaving
@@ -28,9 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.files = %w{
29
29
  README.md <%= snake_case %>.gemspec Gemfile
30
30
  } + Dir.glob(
31
- 'lib/**/*', File::FNM_DOTMATCH
31
+ "lib/**/*", File::FNM_DOTMATCH
32
32
  ).reject { |f| File.directory?(f) }
33
- spec.require_paths = ['lib']
33
+ spec.require_paths = ["lib"]
34
34
 
35
35
  # If you rely on any other gems, list them here with any constraints.
36
36
  # This is how `inspec plugin install` is able to manage your dependencies.
@@ -39,5 +39,5 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  # All plugins should mention inspec, > 2.2.78
41
41
  # 2.2.78 included the v2 Plugin API
42
- spec.add_dependency 'inspec', '>=2.2.78', '<4.0.0'
42
+ spec.add_dependency "inspec", ">= 2.2.78", "< 4.0.0"
43
43
  end
@@ -11,4 +11,4 @@
11
11
  libdir = File.dirname(__FILE__)
12
12
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
13
13
 
14
- require '<%= plugin_name %>/plugin'
14
+ require "<%= plugin_name %>/plugin"
@@ -1,4 +1,4 @@
1
- require 'inspec/resource'
1
+ require "inspec/resource"
2
2
 
3
3
  module InspecPlugins::<%= module_name %>
4
4
  # This class will provide the actual CLI implementation.
@@ -21,31 +21,31 @@ module InspecPlugins::<%= module_name %>
21
21
  # Note: if you want your command (or subcommand) to have dashes in it,
22
22
  # use underscores where you want a dash, and Thor will convert them.
23
23
  # Thor will fail to find a command that is directly named with dashes.
24
- subcommand_desc '<%= command_name_snake %> [COMMAND]', 'Your Usage Message Here'
24
+ subcommand_desc "<%= command_name_snake %> [COMMAND]", "Your Usage Message Here"
25
25
 
26
26
  # The usual rhythm for a Thor CLI file is description, options, command method.
27
27
  # Thor just has you call DSL methods in sequence prior to each command.
28
28
 
29
29
  # Let's make a command, 'do_something'. This will then be available
30
- # as `inspec <%= command_name_dashes %> do-something
30
+ # as `inspec <%= command_name_dashes %> do-something`
31
31
  # (Change this method name to be something sensible for your plugin.)
32
32
 
33
33
  # First, provide a usage / description. This will appear
34
34
  # in `inspec help <%= command_name_dashes %>`.
35
35
  # As this is a usage message, you should write the command as it should appear
36
36
  # to the user (if you want it to have dashes, use dashes)
37
- desc 'do-something WHAT [OPTIONS]', 'Does something'
37
+ desc "do-something WHAT [OPTIONS]", "Does something"
38
38
 
39
39
  # Let's include an option, -s, to summarize
40
40
  # Refer to the Thors docs; there is a lot you can do here.
41
- option :summary, desc: 'Include a total at the bottom', \
41
+ option :summary, desc: "Include a total at the bottom", \
42
42
  type: :boolean, default: true, aliases: [:s]
43
43
 
44
- # OK, now the actual method itself. If you provide params, you're telling Thor that
44
+ # OK, now the actual method itself. If you provide params, you're telling Thor that
45
45
  # you accept CLI arguments after all options have been consumed.
46
46
  # Note again that the method name has an underscore, but when invoked
47
47
  # on the CLI, use a dash.
48
- def do_something(what = 'nothing')
48
+ def do_something(what = "nothing")
49
49
  # The code here will *only* be executed if someone actually
50
50
  # runs `inspec <%= command_name_dashes %> do-something`.
51
51
 
@@ -55,7 +55,7 @@ module InspecPlugins::<%= module_name %>
55
55
  # Talk to the user using the `ui` object (see Inspec::UI)
56
56
  # ui.error('Whoops!')
57
57
 
58
- ui.warning('This is a generated plugin with a default implementation. Edit lib/<%= plugin_name %>/cli_command.rb to make it do what you want.')
58
+ ui.warning("This is a generated plugin with a default implementation. Edit lib/<%= plugin_name %>/cli_command.rb to make it do what you want.")
59
59
  ui.exit(:success) # or :usage_error
60
60
  end
61
61
  end
@@ -1,49 +1,49 @@
1
1
  # Plugin Definition file
2
2
  # The purpose of this file is to declare to InSpec what plugin_types (capabilities)
3
- # are included in this plugin, and provide hooks that will load them as needed.
3
+ # are included in this plugin, and provide activator that will load them as needed.
4
4
 
5
5
  # It is important that this file load successfully and *quickly*.
6
6
  # Your plugin's functionality may never be used on this InSpec run; so we keep things
7
7
  # fast and light by only loading heavy things when they are needed.
8
8
 
9
9
  # Presumably this is light
10
- require '<%= plugin_name %>/version'
10
+ require "<%= plugin_name %>/version"
11
11
 
12
12
  # The InspecPlugins namespace is where all plugins should declare themselves.
13
- # The 'Inspec' capitalization is used throughout the InSpec source code; yes, it's
13
+ # The "Inspec" capitalization is used throughout the InSpec source code; yes, it's
14
14
  # strange.
15
15
  module InspecPlugins
16
- # Pick a reasonable namespace here for your plugin. A reasonable choice
16
+ # Pick a reasonable namespace here for your plugin. A reasonable choice
17
17
  # would be the CamelCase version of your plugin gem name.
18
18
  # <%= plugin_name %> => <%= module_name %>
19
19
  module <%= module_name %>
20
20
  # This simple class handles the plugin definition, so calling it simply Plugin is OK.
21
21
  # Inspec.plugin returns various Classes, intended to be superclasses for various
22
22
  # plugin components. Here, the one-arg form gives you the Plugin Definition superclass,
23
- # which mainly gives you access to the hook / plugin_type DSL.
23
+ # which mainly gives you access to the activator / plugin_type DSL.
24
24
  # The number '2' says you are asking for version 2 of the plugin API. If there are
25
25
  # future versions, InSpec promises plugin API v2 will work for at least two more InSpec
26
26
  # major versions.
27
27
  class Plugin < ::Inspec.plugin(2)
28
28
  # Internal machine name of the plugin. InSpec will use this in errors, etc.
29
- plugin_name :'<%= plugin_name %>'
29
+ plugin_name :"<%= plugin_name %>"
30
30
 
31
- <% if hooks[:cli_command] %>
31
+ <% if activators[:cli_command] %>
32
32
  # Define a new CLI subcommand.
33
33
  # The argument here will be used to match against the command line args,
34
- # and if the user said `inspec list-resources`, this hook will get called.
35
- # Notice that you can define multiple hooks with different names, and they
34
+ # and if the user said `inspec list-resources`, this activator will get called.
35
+ # Notice that you can define multiple activators with different names, and they
36
36
  # don't have to match the plugin name.
37
37
 
38
38
  # We'd like this to be list-resources, but Thor does not support hyphens
39
39
  # see https://github.com/erikhuda/thor/pull/613
40
40
  cli_command :<%= command_name_snake %> do
41
- # Calling this hook doesn't mean the subcommand is being executed - just
41
+ # Calling this activator doesn't mean the subcommand is being executed - just
42
42
  # that we should be ready to do so. So, load the file that defines the
43
43
  # functionality.
44
- # For example, InSpec will activate this hook when `inspec help` is
44
+ # For example, InSpec will activate this activator when `inspec help` is
45
45
  # executed, so that this plugin's usage message will be included in the help.
46
- require '<%= plugin_name %>/cli_command'
46
+ require "<%= plugin_name %>/cli_command"
47
47
 
48
48
  # Having loaded our functionality, return a class that will let the
49
49
  # CLI engine tap into it.
@@ -51,15 +51,15 @@ module InspecPlugins
51
51
  end
52
52
  <% end %>
53
53
 
54
- <% if hooks[:reporter] %>
54
+ <% if activators[:reporter] %>
55
55
  # Define a new Reporter.
56
56
  # The argument here will be used to match against the CLI --reporter option.
57
57
  # `--reporter <%= reporter_name_snake %>` will load your reporter and call its renderer.
58
58
  reporter :<%= reporter_name_snake %> do
59
- # Calling this hook doesn't mean the reporter is being executed - just
59
+ # Calling this activator doesn't mean the reporter is being executed - just
60
60
  # that we should be ready to do so. So, load the file that defines the
61
61
  # functionality.
62
- require '<%= plugin_name %>/reporter'
62
+ require "<%= plugin_name %>/reporter"
63
63
 
64
64
  # Having loaded our functionality, return a class that will let the
65
65
  # reporting engine tap into it.
@@ -3,6 +3,6 @@
3
3
  # to learn the current version.
4
4
  module InspecPlugins
5
5
  module <%= module_name %>
6
- VERSION = '0.1.0'.freeze
6
+ VERSION = "0.1.0".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.37.20
4
+ version: 4.37.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-20 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry
@@ -712,11 +712,11 @@ files:
712
712
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md
713
713
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile
714
714
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec
715
- - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb
716
- - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb
717
- - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb
718
- - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/reporter.rb
719
- - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb
715
+ - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.erb
716
+ - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.erb
717
+ - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.erb
718
+ - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/reporter.erb
719
+ - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.erb
720
720
  - lib/plugins/inspec-init/templates/profiles/aws/README.md
721
721
  - lib/plugins/inspec-init/templates/profiles/aws/controls/example.rb
722
722
  - lib/plugins/inspec-init/templates/profiles/aws/inputs.yml