Sha256: 75332dd593ea32127a77fec04ac19fb5ac29794d23965f96702e5f0faa4b6661

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

# DeployRubygem - deploy a gem using rake
# Containing a class
module DeployRubygem
  # Using Inspec to deploy and manage Inspec
  class Inspec
    attr_reader :inspec_name, :input_file, :waiver_file

    def initialize(inspec_name, input_file = nil, waiver_file = nil)
      @inspec_name = inspec_name
      @input_file = input_file
      @waiver_file = waiver_file
    end

    def inspec_options
      cmd_opt = []

      unless input_file.nil?
        cmd_opt << '--input-file'
        cmd_opt << input_file
      end

      unless waiver_file.nil?
        cmd_opt << '--waiver-file'
        cmd_opt << waiver_file
      end
      cmd_opt
    end

    def check
      system("inspec check compliance/profiles/#{inspec_name}")
    end

    def apply
      puts "ActuaL Dir #{Dir.pwd}"
      puts "inspec_name = #{inspec_name}"
      puts "input_file = #{input_file}"
      puts "waiver_file = #{waiver_file}"

      check
      system("inspec exec compliance/profiles/#{inspec_name} #{inspec_options.join(' ')}")
    end

    def update
      system("rm -rf compliance/profiles/#{inspec_name}/vendor")
      system("rm compliance/profiles/#{inspec_name}/inspec.lock")
      system("inspec vendor compliance/profiles/#{inspec_name}")
    end

    def save_as_html(html_file)
      check
      system("inspec exec compliance/profiles/#{inspec_name} #{inspec_options.join(' ')} --reporter html:#{html_file}")
    end

    def as_json
      check
      `inspec exec compliance/profiles/#{inspec_name} #{inspec_options.join(' ')} --reporter json")`
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
deploy_rubygem-0.60.18 lib/deploy_rubygem/inspec.rb