inspec 2.2.102 → 2.2.112
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +25 -7
- data/Rakefile +8 -2
- data/docs/profiles.md +9 -0
- data/docs/resources/aws_security_group.md.erb +19 -2
- data/docs/resources/gem.md.erb +24 -5
- data/docs/resources/mssql_session.md.erb +8 -0
- data/lib/inspec/plugin/v2/loader.rb +33 -7
- data/lib/inspec/reporters/json_automate.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/plugins/README.md +16 -0
- data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +12 -0
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +162 -0
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +114 -0
- data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +46 -0
- data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +11 -0
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +39 -0
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +394 -0
- data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +184 -0
- data/lib/{bundles → plugins}/inspec-init/README.md +0 -0
- data/lib/plugins/inspec-init/lib/inspec-init.rb +12 -0
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +28 -0
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +81 -0
- data/lib/{bundles → plugins/inspec-init/lib}/inspec-init/templates/profile/README.md +0 -0
- data/lib/{bundles → plugins/inspec-init/lib}/inspec-init/templates/profile/controls/example.rb +0 -0
- data/lib/{bundles → plugins/inspec-init/lib}/inspec-init/templates/profile/inspec.yml +0 -0
- data/lib/{bundles → plugins/inspec-init/lib}/inspec-init/templates/profile/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/test/functional/inspec_init_test.rb +30 -0
- data/lib/plugins/shared/core_plugin_test_helper.rb +50 -0
- data/lib/resources/aws/aws_security_group.rb +38 -6
- data/lib/resources/gem.rb +7 -1
- data/lib/resources/mssql_session.rb +4 -2
- metadata +21 -17
- data/lib/bundles/inspec-artifact.rb +0 -7
- data/lib/bundles/inspec-artifact/README.md +0 -1
- data/lib/bundles/inspec-artifact/cli.rb +0 -278
- data/lib/bundles/inspec-habitat.rb +0 -12
- data/lib/bundles/inspec-habitat/cli.rb +0 -37
- data/lib/bundles/inspec-habitat/log.rb +0 -10
- data/lib/bundles/inspec-habitat/profile.rb +0 -391
- data/lib/bundles/inspec-init.rb +0 -12
- data/lib/bundles/inspec-init/cli.rb +0 -39
- data/lib/bundles/inspec-init/renderer.rb +0 -79
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
module Init
|
5
|
-
class Renderer
|
6
|
-
# Creates a renderer able to render the given template type
|
7
|
-
# 1. iterate over all files
|
8
|
-
# 2. read content in erb
|
9
|
-
# 3. write to full_destination_root_path
|
10
|
-
|
11
|
-
attr_reader :overwrite_mode, :ui
|
12
|
-
def initialize(cli_ui, cli_options = {})
|
13
|
-
@ui = cli_ui
|
14
|
-
@overwrite_mode = cli_options['overwrite']
|
15
|
-
end
|
16
|
-
|
17
|
-
# rubocop: disable Metrics/AbcSize
|
18
|
-
def render_with_values(template_type, template_values = {})
|
19
|
-
# look for template directory
|
20
|
-
base_dir = File.join(File.dirname(__FILE__), 'templates', template_type)
|
21
|
-
# prepare glob for all subdirectories and files
|
22
|
-
template_glob = File.join(base_dir, '**', '{*,.*}')
|
23
|
-
# Use the name attribute to define the path to the profile.
|
24
|
-
profile_path = template_values[:name]
|
25
|
-
# Use slashes (\, /) to split up the name into an Array then use the last entry
|
26
|
-
# to reset the name of the profile.
|
27
|
-
template_values[:name] = template_values[:name].split(%r{\\|\/}).last
|
28
|
-
# Generate the full full_destination_root_path path on disk
|
29
|
-
full_destination_root_path = Pathname.new(Dir.pwd).join(profile_path)
|
30
|
-
ui.plain_text "Create new #{template_type} at #{ui.mark_text(full_destination_root_path)}"
|
31
|
-
|
32
|
-
# check that the directory does not exist
|
33
|
-
if File.exist?(full_destination_root_path) && !overwrite_mode
|
34
|
-
ui.plain_text "#{ui.mark_text(full_destination_root_path)} exists already, use --overwrite"
|
35
|
-
ui.exit(1)
|
36
|
-
end
|
37
|
-
|
38
|
-
# ensure that full_destination_root_path directory is available
|
39
|
-
FileUtils.mkdir_p(full_destination_root_path)
|
40
|
-
|
41
|
-
# iterate over files and write to full_destination_root_path
|
42
|
-
Dir.glob(template_glob) do |file|
|
43
|
-
relative_destination_item_path = Pathname.new(file).relative_path_from(Pathname.new(base_dir))
|
44
|
-
full_destination_item_path = Pathname.new(full_destination_root_path).join(relative_destination_item_path)
|
45
|
-
if File.directory?(file)
|
46
|
-
ui.li "Create directory #{ui.mark_text(relative_destination_item_path)}"
|
47
|
-
FileUtils.mkdir_p(full_destination_item_path)
|
48
|
-
elsif File.file?(file)
|
49
|
-
ui.li "Create file #{ui.mark_text(relative_destination_item_path)}"
|
50
|
-
# read & render content
|
51
|
-
content = render(File.read(file), template_values)
|
52
|
-
# write file content
|
53
|
-
File.write(full_destination_item_path, content)
|
54
|
-
else
|
55
|
-
ui.plain_text "Ignore #{file}, because its not an file or directoy"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
# rubocop: enable Metrics/AbcSize
|
60
|
-
|
61
|
-
# This is a render helper to bind hash values to a ERB template
|
62
|
-
# ERB provides result_with_hash in ruby 2.5.0+, which does exactly this
|
63
|
-
def render(template_content, hash)
|
64
|
-
# create a new binding class
|
65
|
-
cls = Class.new do
|
66
|
-
hash.each do |key, value|
|
67
|
-
define_method key.to_sym do
|
68
|
-
value
|
69
|
-
end
|
70
|
-
end
|
71
|
-
# expose binding
|
72
|
-
define_method :bind do
|
73
|
-
binding
|
74
|
-
end
|
75
|
-
end
|
76
|
-
ERB.new(template_content).result(cls.new.bind)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|