Method: Compliance::API.target_is_automate_server?

Defined in:
lib/bundles/inspec-compliance/api.rb

.target_is_automate_server?(url, insecure) ⇒ Boolean

Returns:

  • (Boolean)


308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/bundles/inspec-compliance/api.rb', line 308

def self.target_is_automate_server?(url, insecure)
  automate_endpoint = '/compliance/version'
  response = Compliance::HTTP.get(url + automate_endpoint, nil, insecure)
  case response.code
  when '401'
    Inspec::Log.debug(
      "Received 401 from #{url}#{automate_endpoint} - " \
      'assuming target is a Chef Automate instance',
    )
    true
  when '200'
    # Chef Automate currently returns 401 for `/compliance/version` but some
    # versions of OpsWorks Chef Automate return 200 and a Chef Manage page
    # when unauthenticated requests are received.
    if response.body.include?('Are You Looking For the Chef Server?')
      Inspec::Log.debug(
        "Received 200 from #{url}#{automate_endpoint} - " \
        'assuming target is an OpsWorks Chef Automate instance',
      )
      true
    else
      Inspec::Log.debug(
        "Received 200 from #{url}#{automate_endpoint} " \
        'but did not receive the Chef Manage page - ' \
        'assuming target is not a Chef Automate instance',
      )
      false
    end
  else
    Inspec::Log.debug(
      "Received unexpected status code #{response.code} " \
      "from #{url}#{automate_endpoint} - " \
      'assuming target is not a Chef Automate instance',
    )
    false
  end
end