inspec-core 3.5.0 → 3.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/etc/deprecations.json +9 -0
- data/lib/bundles/inspec-supermarket/cli.rb +1 -1
- data/lib/inspec/backend.rb +9 -8
- data/lib/inspec/base_cli.rb +12 -170
- data/lib/inspec/cli.rb +17 -16
- data/lib/inspec/config.rb +391 -0
- data/lib/inspec/control_eval_context.rb +2 -1
- data/lib/inspec/dsl.rb +2 -2
- data/lib/inspec/errors.rb +5 -0
- data/lib/inspec/plugin/v1/plugin_types/resource.rb +1 -1
- data/lib/inspec/plugin/v2/activator.rb +24 -3
- data/lib/inspec/plugin/v2/loader.rb +1 -1
- data/lib/inspec/plugin/v2/registry.rb +8 -12
- data/lib/inspec/profile.rb +3 -2
- data/lib/inspec/profile_vendor.rb +2 -1
- data/lib/inspec/rspec_extensions.rb +2 -2
- data/lib/inspec/runner.rb +5 -5
- data/lib/inspec/shell.rb +1 -1
- data/lib/inspec/ui.rb +2 -2
- data/lib/inspec/version.rb +1 -1
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +1 -1
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +3 -28
- data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +245 -0
- data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +49 -0
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +43 -31
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +12 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/LICENSE +2 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md +28 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile +40 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +45 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +16 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +64 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +55 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +10 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +24 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +12 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +110 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +26 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +17 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +67 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +51 -0
- data/lib/plugins/inspec-init/{lib/inspec-init/templates → templates}/profiles/os/README.md +0 -0
- data/lib/plugins/inspec-init/{lib/inspec-init/templates → templates}/profiles/os/controls/example.rb +0 -0
- data/lib/plugins/inspec-init/{lib/inspec-init/templates → templates}/profiles/os/inspec.yml +0 -0
- data/lib/plugins/inspec-init/{lib/inspec-init/templates → templates}/profiles/os/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +173 -0
- data/lib/plugins/inspec-init/test/functional/{inspec_init_test.rb → inspec_init_profile_test.rb} +7 -7
- data/lib/resources/filesystem.rb +40 -12
- metadata +31 -11
data/lib/plugins/inspec-init/test/functional/{inspec_init_test.rb → inspec_init_profile_test.rb}
RENAMED
@@ -11,7 +11,7 @@ class InitCli < MiniTest::Test
|
|
11
11
|
profile = File.join(dir, 'test-profile')
|
12
12
|
out = run_inspec_process("init profile test-profile", prefix: "cd #{dir} &&")
|
13
13
|
assert_equal 0, out.exit_status
|
14
|
-
assert_includes out.stdout, '
|
14
|
+
assert_includes out.stdout, 'Creating new profile at'
|
15
15
|
assert_includes out.stdout, profile
|
16
16
|
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
17
17
|
assert_includes Dir.entries(profile).join, 'README.md'
|
@@ -23,7 +23,7 @@ class InitCli < MiniTest::Test
|
|
23
23
|
profile = File.join(dir, 'test-profile')
|
24
24
|
out = run_inspec_process("init profile --platform os test-profile", prefix: "cd #{dir} &&")
|
25
25
|
assert_equal 0, out.exit_status
|
26
|
-
assert_includes out.stdout, '
|
26
|
+
assert_includes out.stdout, 'Creating new profile at'
|
27
27
|
assert_includes out.stdout, profile
|
28
28
|
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
29
29
|
assert_includes Dir.entries(profile).join, 'README.md'
|
@@ -55,19 +55,19 @@ class InitCli < MiniTest::Test
|
|
55
55
|
profile = File.join(dir, 'test-gcp-profile')
|
56
56
|
out = run_inspec_process("init profile --platform gcp test-gcp-profile", prefix: "cd #{dir} &&")
|
57
57
|
assert_equal 0, out.exit_status
|
58
|
-
assert_includes out.stdout, '
|
58
|
+
assert_includes out.stdout, 'Creating new profile at'
|
59
59
|
assert_includes out.stdout, profile
|
60
60
|
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
61
61
|
assert_includes Dir.entries(profile).join, 'README.md'
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
65
|
+
def test_generating_inspec_profile_os
|
66
66
|
Dir.mktmpdir do |dir|
|
67
|
-
profile = File.join(dir,'test-
|
68
|
-
out = run_inspec_process("init profile --platform
|
67
|
+
profile = File.join(dir,'test-os-profile')
|
68
|
+
out = run_inspec_process("init profile --platform os test-os-profile", prefix: "cd #{dir} &&")
|
69
69
|
assert_equal 0, out.exit_status
|
70
|
-
assert_includes out.stdout, '
|
70
|
+
assert_includes out.stdout, 'Creating new profile at'
|
71
71
|
assert_includes out.stdout, profile
|
72
72
|
assert_includes Dir.entries(profile).join, 'inspec.yml'
|
73
73
|
assert_includes Dir.entries(profile).join, 'README.md'
|
data/lib/resources/filesystem.rb
CHANGED
@@ -6,12 +6,16 @@ module Inspec::Resources
|
|
6
6
|
desc 'Use the filesystem InSpec resource to test file system'
|
7
7
|
example "
|
8
8
|
describe filesystem('/') do
|
9
|
-
its('
|
10
|
-
its('
|
9
|
+
its('size_kb') { should be >= 32000 }
|
10
|
+
its('free_kb') { should be >= 3200 }
|
11
|
+
its('type') { should cmp 'ext4' }
|
12
|
+
its('percent_free') { should be >= 20 }
|
11
13
|
end
|
12
14
|
describe filesystem('c:') do
|
13
|
-
its('
|
14
|
-
its('
|
15
|
+
its('size_kb') { should be >= 9000 }
|
16
|
+
its('free_kb') { should be >= 3200 }
|
17
|
+
its('type') { should cmp 'NTFS' }
|
18
|
+
its('percent_free') { should be >= 20 }
|
15
19
|
end
|
16
20
|
"
|
17
21
|
attr_reader :partition
|
@@ -42,9 +46,30 @@ module Inspec::Resources
|
|
42
46
|
"FileSystem #{@partition}"
|
43
47
|
end
|
44
48
|
|
49
|
+
def size_kb
|
50
|
+
info = @fsman.info(@partition)
|
51
|
+
info[:size_kb]
|
52
|
+
end
|
53
|
+
|
45
54
|
def size
|
55
|
+
Inspec.deprecate(:filesystem_property_size, 'The `size` property did not reliably use the correct units. Please use `size_kb` instead.')
|
56
|
+
if inspec.os.windows?
|
57
|
+
# On windows, we had a bug prior to #3767 in which the
|
58
|
+
# 'size' value was be scaled to GB in powershell.
|
59
|
+
# We now collect it in KB.
|
60
|
+
(size_kb / (1024 * 1024)).to_i
|
61
|
+
else
|
62
|
+
size_kb
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def free_kb
|
46
67
|
info = @fsman.info(@partition)
|
47
|
-
info[:
|
68
|
+
info[:free_kb]
|
69
|
+
end
|
70
|
+
|
71
|
+
def percent_free
|
72
|
+
100 * free_kb / size_kb
|
48
73
|
end
|
49
74
|
|
50
75
|
def type
|
@@ -67,13 +92,14 @@ module Inspec::Resources
|
|
67
92
|
|
68
93
|
class LinuxFileSystemResource < FsManagement
|
69
94
|
def info(partition)
|
70
|
-
cmd = inspec.command("df #{partition}
|
95
|
+
cmd = inspec.command("df #{partition} -T")
|
71
96
|
raise Inspec::Exceptions::ResourceFailed, "Unable to get available space for partition #{partition}" if cmd.stdout.nil? || cmd.stdout.empty? || !cmd.exit_status.zero?
|
72
|
-
value = cmd.stdout.
|
97
|
+
value = cmd.stdout.split(/\n/)[1].strip.split(' ')
|
73
98
|
{
|
74
99
|
name: partition,
|
75
|
-
|
76
|
-
|
100
|
+
size_kb: value[2].to_i,
|
101
|
+
free_kb: value[4].to_i,
|
102
|
+
type: value[1].to_s,
|
77
103
|
}
|
78
104
|
end
|
79
105
|
end
|
@@ -82,8 +108,9 @@ module Inspec::Resources
|
|
82
108
|
def info(partition)
|
83
109
|
cmd = inspec.command <<-EOF.gsub(/^\s*/, '')
|
84
110
|
$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='#{partition}'"
|
85
|
-
$disk.Size = $disk.Size /
|
86
|
-
$disk
|
111
|
+
$disk.Size = $disk.Size / 1KB
|
112
|
+
$disk.FreeSpace = $disk.FreeSpace / 1KB
|
113
|
+
$disk | select -property DeviceID,Size,FileSystem,FreeSpace | ConvertTo-Json
|
87
114
|
EOF
|
88
115
|
|
89
116
|
raise Inspec::Exceptions::ResourceSkipped, "Unable to get available space for partition #{partition}" if cmd.stdout == '' || cmd.exit_status.to_i != 0
|
@@ -96,7 +123,8 @@ module Inspec::Resources
|
|
96
123
|
end
|
97
124
|
{
|
98
125
|
name: fs['DeviceID'],
|
99
|
-
|
126
|
+
size_kb: fs['Size'].to_i,
|
127
|
+
free_kb: fs['FreeSpace'].to_i,
|
100
128
|
type: fs['FileSystem'],
|
101
129
|
}
|
102
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train-core
|
@@ -17,9 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.7.
|
22
|
+
version: 1.7.2
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +27,9 @@ dependencies:
|
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.5'
|
30
|
-
- -
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.7.
|
32
|
+
version: 1.7.2
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: thor
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -355,6 +355,7 @@ files:
|
|
355
355
|
- lib/inspec/completions/bash.sh.erb
|
356
356
|
- lib/inspec/completions/fish.sh.erb
|
357
357
|
- lib/inspec/completions/zsh.sh.erb
|
358
|
+
- lib/inspec/config.rb
|
358
359
|
- lib/inspec/control_eval_context.rb
|
359
360
|
- lib/inspec/dependencies/cache.rb
|
360
361
|
- lib/inspec/dependencies/dependency_set.rb
|
@@ -468,12 +469,31 @@ files:
|
|
468
469
|
- lib/plugins/inspec-init/README.md
|
469
470
|
- lib/plugins/inspec-init/lib/inspec-init.rb
|
470
471
|
- lib/plugins/inspec-init/lib/inspec-init/cli.rb
|
472
|
+
- lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb
|
473
|
+
- lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb
|
471
474
|
- lib/plugins/inspec-init/lib/inspec-init/renderer.rb
|
472
|
-
- lib/plugins/inspec-init/
|
473
|
-
- lib/plugins/inspec-init/
|
474
|
-
- lib/plugins/inspec-init/
|
475
|
-
- lib/plugins/inspec-init/
|
476
|
-
- lib/plugins/inspec-init/
|
475
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile
|
476
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/LICENSE
|
477
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md
|
478
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile
|
479
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec
|
480
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb
|
481
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb
|
482
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb
|
483
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb
|
484
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md
|
485
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md
|
486
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb
|
487
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb
|
488
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md
|
489
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb
|
490
|
+
- lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb
|
491
|
+
- lib/plugins/inspec-init/templates/profiles/os/README.md
|
492
|
+
- lib/plugins/inspec-init/templates/profiles/os/controls/example.rb
|
493
|
+
- lib/plugins/inspec-init/templates/profiles/os/inspec.yml
|
494
|
+
- lib/plugins/inspec-init/templates/profiles/os/libraries/.gitkeep
|
495
|
+
- lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb
|
496
|
+
- lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb
|
477
497
|
- lib/plugins/inspec-plugin-manager-cli/README.md
|
478
498
|
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb
|
479
499
|
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb
|