Class: Iggy::InspecHelper
- Inherits:
-
Object
- Object
- Iggy::InspecHelper
- Defined in:
- lib/inspec-iggy/inspec_helper.rb
Constant Summary collapse
- RESOURCES =
constants for the InSpec resources
Inspec::Resource.registry.keys
- TERRAFORM_RESOURCES =
translate Terraform resource name to InSpec
{ "aws_instance" => "aws_ec2_instance", # 'aws_route' => 'aws_route_table' # needs route_table_id instead of id }
- COMMON_PROPERTIES =
a hack for sure, finds common methods as proxy for InSpec properties
Inspec::Resource.registry["aws_subnet"].instance_methods & Inspec::Resource.registry["directory"].instance_methods
Class Method Summary collapse
- .print_commands(extracted_profiles) ⇒ Object
- .print_controls(file, generated_controls) ⇒ Object
-
.resource_properties(resource) ⇒ Object
# there really should be some way to get this directly from InSpec’s resources.
Class Method Details
.print_commands(extracted_profiles) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inspec-iggy/inspec_helper.rb', line 32 def self.print_commands(extracted_profiles) extracted_profiles.keys.each do |cmd| type = extracted_profiles[cmd]["type"] url = extracted_profiles[cmd]["url"] key_name = extracted_profiles[cmd]["key_name"] if type == "aws_instance" ip = extracted_profiles[cmd]["public_ip"] puts "inspec exec #{url} -t ssh://#{ip} -i #{key_name}" else puts "inspec exec #{url} -t aws://us-west-2" end end end |
.print_controls(file, generated_controls) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/inspec-iggy/inspec_helper.rb', line 46 def self.print_controls(file, generated_controls) puts "# encoding: utf-8\n#" puts "\ntitle '#{File.absolute_path(file)} controls generated by Iggy v#{Iggy::VERSION}'" # write all controls puts generated_controls.flatten.map(&:to_ruby).join("\n\n") end |
.resource_properties(resource) ⇒ Object
# there really should be some way to get this directly from InSpec’s resources
22 23 24 25 26 27 28 29 30 |
# File 'lib/inspec-iggy/inspec_helper.rb', line 22 def self.resource_properties(resource) # remove the common methods, in theory only leaving only unique InSpec properties inspec_properties = Inspec::Resource.registry[resource].instance_methods - COMMON_PROPERTIES # get InSpec properties by method names inspec_properties.collect! { |x| x.to_s } Inspec::Log.debug "Iggy::InspecHelper.resource_properties #{resource} properties = #{inspec_properties}" inspec_properties end |