Search code examples
rubychef-infrainspec

Ho to use string concatenation in an http-block in Inspec?


I've got an Inspec-control containing a http-block. The URL is saved in a variable called DNScloudui['value'] - I want to add https:// to the beginning of the URL.

DNScloudui = attribute('DNS_name_cloudui')

control 'Website reachability' do
  title 'Check reachability by GET requests'
  describe http(DNScloudui['value'], method: 'GET') do
    its('status') { should cmp 200 }
  end
end

How can I achieve that?


Solution

  • assuming that DNScloudui returns you a non-nil value, then you can use string interpolation to get the value of the DNScloudui variable. for instance:

    DNScloudui = attribute('DNS_name_cloudui')
    
    control 'Website reachability' do
      title 'Check reachability by GET requests'
      describe http("https://#{DNScloudui['value']}", method: 'GET') do
        its('status') { should cmp 200 }
      end
    end
    

    also, looking at the name of your DNScloudui variable, i would suggest to stick to ruby naming conventions and style guides