mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
add rules to profile information
This commit is contained in:
parent
a62ce0e14b
commit
93b4db01ca
4 changed files with 33 additions and 72 deletions
|
@ -1,69 +0,0 @@
|
|||
# encoding: utf-8
|
||||
# Copyright 2014 Dominik Richter. All rights reserved.
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
# Spec file for Vulcano specs
|
||||
|
||||
# Get types
|
||||
module DummyTestTypes
|
||||
# a few commands with special handling
|
||||
def describe(*_args); end
|
||||
|
||||
def context(*_args); end
|
||||
|
||||
def os
|
||||
{}
|
||||
end
|
||||
|
||||
def command(_sth)
|
||||
res = OpenStruct.new
|
||||
res.stdout = ''
|
||||
res.stderr = ''
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
module DummyVulcanoTypes
|
||||
%w{
|
||||
attributes registry_key
|
||||
}.each do |name|
|
||||
define_method name do |*_arg|
|
||||
end
|
||||
end
|
||||
|
||||
def processes(*_args)
|
||||
[]
|
||||
end
|
||||
|
||||
def start_postgres_session(*_args)
|
||||
Describer.new
|
||||
end
|
||||
|
||||
def start_mysql_session(*_args)
|
||||
Describer.new
|
||||
end
|
||||
|
||||
class Describer
|
||||
def describe(*_args); end
|
||||
end
|
||||
end
|
||||
|
||||
class SshConf
|
||||
def initialize(*_args); end
|
||||
end
|
||||
class PostgresConf
|
||||
def initialize(*_args); end
|
||||
|
||||
def params(*_a, &_b)
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
class MysqlConf
|
||||
def initialize(*_args); end
|
||||
|
||||
def params(*_a, &_b)
|
||||
{}
|
||||
end
|
||||
end
|
|
@ -28,6 +28,21 @@ module Vulcano
|
|||
|
||||
@metadata = read_metadata
|
||||
@params = @metadata.params unless @metadata.nil?
|
||||
|
||||
@params['rules'] = rules = {}
|
||||
@runner = Runner.new(
|
||||
id: @profile_id,
|
||||
backend: :mock,
|
||||
)
|
||||
@runner.add_tests([@path])
|
||||
@runner.rules.each do |id, rule|
|
||||
rules[id] = {
|
||||
title: rule.title,
|
||||
desc: rule.desc,
|
||||
impact: rule.impact,
|
||||
code: rule.instance_variable_get(:@__code),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -70,7 +70,7 @@ module Vulcano
|
|||
end
|
||||
|
||||
def desc(v = nil)
|
||||
@desc = v unless v.nil?
|
||||
@desc = unindent(v) unless v.nil?
|
||||
@desc
|
||||
end
|
||||
|
||||
|
@ -136,5 +136,19 @@ module Vulcano
|
|||
return "#{pid}/#{rid}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Idio(ma)tic unindent
|
||||
# TODO replace this
|
||||
#
|
||||
# @param [String] text string which needs to be unindented
|
||||
# @return [String] input with indentation removed
|
||||
def unindent(text)
|
||||
return '' if text.nil?
|
||||
text.strip.split("\n").map(&:strip)
|
||||
.map { |x| x.empty? ? "\n" : x }
|
||||
.join(' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,9 @@ require 'vulcano/rspec_json_formatter'
|
|||
|
||||
module Vulcano
|
||||
class Runner
|
||||
attr_reader :tests, :backend
|
||||
attr_reader :tests, :backend, :rules
|
||||
def initialize(conf = {})
|
||||
@rules = []
|
||||
@rules = {}
|
||||
@profile_id = conf[:id]
|
||||
@conf = conf.dup
|
||||
@tests = RSpec::Core::World.new
|
||||
|
@ -102,6 +102,7 @@ module Vulcano
|
|||
end
|
||||
|
||||
def register_rule(ctx, rule_id, rule)
|
||||
@rules[rule_id] = rule
|
||||
checks = rule.instance_variable_get(:@checks)
|
||||
checks.each do |m, a, b|
|
||||
# resource skipping
|
||||
|
|
Loading…
Reference in a new issue