inspec 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -2
- data/Gemfile +0 -7
- data/docs/migration.md +232 -0
- data/docs/profiles.md +1 -0
- data/lib/bundles/inspec-compliance/api.rb +10 -0
- data/lib/bundles/inspec-compliance/cli.rb +29 -0
- data/lib/bundles/inspec-compliance/target.rb +1 -11
- data/lib/bundles/inspec-supermarket/api.rb +1 -1
- data/lib/bundles/inspec-supermarket/cli.rb +1 -1
- data/lib/inspec/cli.rb +6 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/json.rb +1 -1
- data/lib/resources/package.rb +4 -2
- data/lib/resources/postgres_conf.rb +18 -5
- data/lib/resources/yum.rb +4 -0
- data/lib/utils/latest_version.rb +20 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f94253412c3c460db42fc5f03154c96a51a4c7b
|
4
|
+
data.tar.gz: 460e9aa3231989faa7af89b29cc51d4f2a518eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb44eed7117103ec33fb7ed1f69f236637798124533f1daa2fc0039f86871599d47d1e67506abd904ab3915cb9a6f8078caafdb78465da9ad6c4845f311a08ab
|
7
|
+
data.tar.gz: c10829d5c72a263cbf7794a2e8617a5aae54765de056226604527d3a5dd1217b04006f449da51b11325f2113b4949ca12dc6f6c70b887facc0e935e317aa1ad7
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,45 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [1.
|
4
|
-
[Full Changelog](https://github.com/chef/inspec/compare/v1.
|
3
|
+
## [1.9.0](https://github.com/chef/inspec/tree/1.9.0) (2017-01-06)
|
4
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v1.8.0...1.9.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Optimize regular expression for postgres config parsing [\#1395](https://github.com/chef/inspec/pull/1395) ([chris-rock](https://github.com/chris-rock))
|
9
|
+
- print name for supermarket profiles [\#1376](https://github.com/chef/inspec/pull/1376) ([chris-rock](https://github.com/chris-rock))
|
10
|
+
- call ssh cookbook from prepare cookbook [\#1369](https://github.com/chef/inspec/pull/1369) ([chris-rock](https://github.com/chris-rock))
|
11
|
+
- display if inspec version is outdated [\#1365](https://github.com/chef/inspec/pull/1365) ([chris-rock](https://github.com/chris-rock))
|
12
|
+
|
13
|
+
**Fixed bugs:**
|
14
|
+
|
15
|
+
- profile upload fails to compliance server [\#1298](https://github.com/chef/inspec/issues/1298)
|
16
|
+
- undefined method `max\_connections' for PostgreSQL [\#825](https://github.com/chef/inspec/issues/825)
|
17
|
+
- bugfix: expose postgres\_conf parameters via `its` [\#826](https://github.com/chef/inspec/pull/826) ([arlimus](https://github.com/arlimus))
|
18
|
+
|
19
|
+
**Closed issues:**
|
20
|
+
|
21
|
+
- Yum.repo should show correct name [\#1390](https://github.com/chef/inspec/issues/1390)
|
22
|
+
- The 'package' resource is broken in OSX \(with brew as package manager\) [\#1386](https://github.com/chef/inspec/issues/1386)
|
23
|
+
- JUnit XML dumping fails [\#1383](https://github.com/chef/inspec/issues/1383)
|
24
|
+
- json.rb produces stacktrace when a target file is unreadable [\#1382](https://github.com/chef/inspec/issues/1382)
|
25
|
+
- Document Serverspec Migration [\#804](https://github.com/chef/inspec/issues/804)
|
26
|
+
|
27
|
+
**Merged pull requests:**
|
28
|
+
|
29
|
+
- Download InSpec profiles from Chef Compliance [\#1402](https://github.com/chef/inspec/pull/1402) ([chris-rock](https://github.com/chris-rock))
|
30
|
+
- Yum.repo should show correct name [\#1391](https://github.com/chef/inspec/pull/1391) ([Wing924](https://github.com/Wing924))
|
31
|
+
- fixes brew json parsing [\#1389](https://github.com/chef/inspec/pull/1389) ([chris-rock](https://github.com/chris-rock))
|
32
|
+
- Fix wrong description for the Solaris cases in the unit tests of the 'package' resource [\#1388](https://github.com/chef/inspec/pull/1388) ([jvrplmlmn](https://github.com/jvrplmlmn))
|
33
|
+
- Unit test the 'package' resource for OSX \(with brew\) [\#1387](https://github.com/chef/inspec/pull/1387) ([jvrplmlmn](https://github.com/jvrplmlmn))
|
34
|
+
- drop ruby 1.9.3 [\#1384](https://github.com/chef/inspec/pull/1384) ([chris-rock](https://github.com/chris-rock))
|
35
|
+
- Make "permission denied" condition match that of Train [\#1381](https://github.com/chef/inspec/pull/1381) ([makotots](https://github.com/makotots))
|
36
|
+
- mention inspec vendor for compliance dependency [\#1380](https://github.com/chef/inspec/pull/1380) ([alexpop](https://github.com/alexpop))
|
37
|
+
- control and lib\_eval\_context unit tests [\#1373](https://github.com/chef/inspec/pull/1373) ([jeremymv2](https://github.com/jeremymv2))
|
38
|
+
- Fix Learn Chef tutorial link [\#1372](https://github.com/chef/inspec/pull/1372) ([tpetchel](https://github.com/tpetchel))
|
39
|
+
- add guidance for Serverspec migration [\#1368](https://github.com/chef/inspec/pull/1368) ([chris-rock](https://github.com/chris-rock))
|
40
|
+
|
41
|
+
## [v1.8.0](https://github.com/chef/inspec/tree/v1.8.0) (2016-12-16)
|
42
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v1.7.2...v1.8.0)
|
5
43
|
|
6
44
|
**Fixed bugs:**
|
7
45
|
|
data/Gemfile
CHANGED
@@ -2,13 +2,6 @@
|
|
2
2
|
source 'https://rubygems.org'
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
# pin dependency for Ruby 1.9.3 since bundler is not
|
6
|
-
# detecting that net-ssh 3 does not work with 1.9.3
|
7
|
-
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.9.3')
|
8
|
-
gem 'net-ssh', '~> 2.9'
|
9
|
-
gem 'tins', '~> 1.6.0'
|
10
|
-
end
|
11
|
-
|
12
5
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
|
13
6
|
gem 'json', '~> 1.8'
|
14
7
|
gem 'rack', '< 2.0'
|
data/docs/migration.md
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
---
|
2
|
+
title: InSpec Migration Guide
|
3
|
+
---
|
4
|
+
|
5
|
+
# Migrate from Serverspec to InSpec
|
6
|
+
|
7
|
+
## How is InSpec different from Serverspec
|
8
|
+
|
9
|
+
We've written a complete blog post about that topic: [The Road to InSpec](https://blog.chef.io/2015/11/04/the-road-to-inspec/)
|
10
|
+
|
11
|
+
## Is InSpec suitable for infrastructure testing?
|
12
|
+
|
13
|
+
InSpec is a framework that allows you to run infrastructure testing as well as compliance testing. The compliance features are always optional and provide customers a way to use InSpec for both use-cases. To ensure we build the best infrastructure testing, we migrate our cookbooks [chef-cookbooks](https://github.com/chef-cookbooks) to InSpec.
|
14
|
+
|
15
|
+
## Which Serverspec resources are available in InSpec?
|
16
|
+
|
17
|
+
The following resources are available in InSpec:
|
18
|
+
|
19
|
+
[`bond`](http://inspec.io/docs/reference/resources/bond/), [`bridge`](http://inspec.io/docs/reference/resources/bridge/), [`command`](http://inspec.io/docs/reference/resources/command/), [`file`](http://inspec.io/docs/reference/resources/file/), [`group`](http://inspec.io/docs/reference/resources/group/), [`host`](http://inspec.io/docs/reference/resources/host/), [`interface`](http://inspec.io/docs/reference/resources/interface/), [`iis_website`](http://inspec.io/docs/reference/resources/iis_site/), [`iptables`](http://inspec.io/docs/reference/resources/iptables/), [`kernel_module`](http://inspec.io/docs/reference/resources/kernel_module/), [`linux_kernel_parameter`](http://inspec.io/docs/reference/resources/kernel_parameter/), [`mysql_config`](http://inspec.io/docs/reference/resources/mysql_config/), [`package`](http://inspec.io/docs/reference/resources/package/), [`port`](http://inspec.io/docs/reference/resources/port/), [`ppa`](http://inspec.io/docs/reference/resources/ppa/), [`process`](http://inspec.io/docs/reference/resources/process/), [`service`](http://inspec.io/docs/reference/resources/service/), [`user`](http://inspec.io/docs/reference/resources/user/), [`windows_feature`](http://inspec.io/docs/reference/resources/windows_feature/), [`windows_registry_key`](http://inspec.io/docs/reference/resources/windows_registry_key/), [`yumrepo`](http://inspec.io/docs/reference/resources/yum/)
|
20
|
+
|
21
|
+
Some Serverspec resources are not available yet. We implement those resources based on user feedback. If you need a resource that is not available in InSpec, please open an [Github issue](https://github.com/chef/inspec/issues). The list of resources that are not available in InSpec:
|
22
|
+
|
23
|
+
`cgroup`, `cron`, `default_gateway`, `docker_container`, `docker_image`, `iis_app_pool`, `ip6tables`, `ipfilter`, `ipnat`, `linux_audit_system`, `lxc`, `mail_alias`, `php_config`, `routing_table`, `selinux`, `selinux_module`, `x509_certificate`, `x509_private_key`, `zfs`
|
24
|
+
|
25
|
+
In addition InSpec provides additional [resources](http://inspec.io/docs/reference/resources/) that are not available in Serverspec:
|
26
|
+
[`apache_conf`](http://inspec.io/docs/reference/resources/apache_conf/), [`apt`](http://inspec.io/docs/reference/resources/apt/), [`audit_policy`](http://inspec.io/docs/reference/resources/audit_policy/), [`auditd_conf`](http://inspec.io/docs/reference/resources/auditd_conf/), [`bash`](http://inspec.io/docs/reference/resources/bash/), [`csv`](http://inspec.io/docs/reference/resources/csv/), [`etc_shadow`](http://inspec.io/docs/reference/resources/etc_shadow/), [`gem`](http://inspec.io/docs/reference/resources/gem/), [`grub_conf`](http://inspec.io/docs/reference/resources/grub_conf/), [`inetd_conf`](http://inspec.io/docs/reference/resources/inetd_conf/), [`ini`](http://inspec.io/docs/reference/resources/ini/), [`json`](http://inspec.io/docs/reference/resources/json/), [`npm`](http://inspec.io/docs/reference/resources/npm/), [`ntp_conf`](http://inspec.io/docs/reference/resources/ntp_conf/), [`oneget`](http://inspec.io/docs/reference/resources/oneget/), [`pip`](http://inspec.io/docs/reference/resources/pip/), [`powershell`](http://inspec.io/docs/reference/resources/powershell/), [`security_policy`](http://inspec.io/docs/reference/resources/security_policy/), [`ssh_config`](http://inspec.io/docs/reference/resources/ssh_config/), [`sshd_config`](http://inspec.io/docs/reference/resources/sshd_config/), [`sys_info`](http://inspec.io/docs/reference/resources/sys_info/)
|
27
|
+
|
28
|
+
## How do I migrate my Serverspec tests to InSpec
|
29
|
+
|
30
|
+
For most cases, the migration to InSpec is pretty straight forward. First, replace the current verifier in `kitchen.yml` configuration with:
|
31
|
+
|
32
|
+
```
|
33
|
+
verifier:
|
34
|
+
name: inspec
|
35
|
+
```
|
36
|
+
|
37
|
+
Second, rename the directory `test/integration/default/serverspec` to
|
38
|
+
`test/integration/default/inspec`
|
39
|
+
|
40
|
+
Third, remove the Serverspec-specific code from the test files.
|
41
|
+
|
42
|
+
```
|
43
|
+
require 'serverspec'
|
44
|
+
|
45
|
+
# Required by serverspec
|
46
|
+
set :backend, :exec
|
47
|
+
```
|
48
|
+
|
49
|
+
InSpec is now configured with Test-Kitchen:
|
50
|
+
|
51
|
+
```
|
52
|
+
kitchen verify package-install-centos-72
|
53
|
+
-----> Starting Kitchen (v1.14.2)
|
54
|
+
-----> Verifying <package-install-centos-72>...
|
55
|
+
Detected alternative framework tests for `inspec`
|
56
|
+
Loaded
|
57
|
+
|
58
|
+
Target: ssh://vagrant@127.0.0.1:2200
|
59
|
+
|
60
|
+
|
61
|
+
PHP has
|
62
|
+
✔ php
|
63
|
+
✔ the pear.php.net channel
|
64
|
+
✔ the pecl.php.net channel
|
65
|
+
|
66
|
+
Test Summary: 3 successful, 0 failures, 0 skipped
|
67
|
+
Finished verifying <package-install-centos-72> (0m0.40s).
|
68
|
+
-----> Kitchen is finished. (0m3.31s)
|
69
|
+
```
|
70
|
+
|
71
|
+
Some real-world migrations are available:
|
72
|
+
|
73
|
+
* [docker](https://github.com/chef-cookbooks/docker)
|
74
|
+
* [nginx](https://github.com/chef-cookbooks/chef_nginx/pull/5/files)
|
75
|
+
* [mysql](https://github.com/chef-cookbooks/mysql/pull/430/files)
|
76
|
+
* [php](https://github.com/chef-cookbooks/php/pull/189/files)
|
77
|
+
|
78
|
+
Some general recommendations:
|
79
|
+
|
80
|
+
* use test-kitchen 1.14+
|
81
|
+
* in case of errors, increase the log level `kitchen verify package-install-centos-72 -l debug`
|
82
|
+
|
83
|
+
## Do I still need the backend configuration?
|
84
|
+
|
85
|
+
InSpec does not attach backend information to test files. All tests are defined independently of any backend. Therefore a Serverspec test file:
|
86
|
+
|
87
|
+
```
|
88
|
+
require 'serverspec'
|
89
|
+
|
90
|
+
# Required by serverspec
|
91
|
+
set :backend, :exec
|
92
|
+
|
93
|
+
describe 'PHP' do
|
94
|
+
it 'has php' do
|
95
|
+
expect(command('php -v').exit_status).to eq(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'has the pear.php.net channel' do
|
99
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'has the pecl.php.net channel' do
|
103
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
will become the following InSpec test file:
|
109
|
+
|
110
|
+
```
|
111
|
+
describe 'PHP' do
|
112
|
+
it 'has php' do
|
113
|
+
expect(command('php -v').exit_status).to eq(0)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'has the pear.php.net channel' do
|
117
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'has the pecl.php.net channel' do
|
121
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
As you can see, the InSpec test files just focuses on tests and tries to avoid all clutter.
|
127
|
+
|
128
|
+
## Nested describe blocks
|
129
|
+
|
130
|
+
Serverspec and RSpec allow you to define nested describe blocks. We did a survey and found out that most users use nested describe blocks only to improve their output report. We believe the code structure should not change to improve the output of a report. Nevertheless we understand that nested describe blocks help you to structure test code. A sample code block looks like:
|
131
|
+
|
132
|
+
```
|
133
|
+
describe 'chef-server-directories' do
|
134
|
+
describe file('/etc/opscode') do
|
135
|
+
it { should be_directory }
|
136
|
+
it { should be_owned_by 'root' }
|
137
|
+
end
|
138
|
+
|
139
|
+
describe file('/etc/opscode-analytics') do
|
140
|
+
it { should be_directory }
|
141
|
+
it { should be_owned_by 'opscode' }
|
142
|
+
it { should be_grouped_into 'opscode' }
|
143
|
+
end
|
144
|
+
|
145
|
+
describe file('/var/log/opscode') do
|
146
|
+
it { should be_directory }
|
147
|
+
it { should be_owned_by 'opscode' }
|
148
|
+
it { should be_grouped_into 'opscode' }
|
149
|
+
end
|
150
|
+
|
151
|
+
describe file('/var/opt/opscode') do
|
152
|
+
it { should be_directory }
|
153
|
+
it { should be_owned_by 'root' }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
In InSpec you would split up groups into files.
|
159
|
+
|
160
|
+
```
|
161
|
+
tests
|
162
|
+
├── server-directories.rb
|
163
|
+
├── other-tests.rb
|
164
|
+
└── further-tests.rb
|
165
|
+
```
|
166
|
+
|
167
|
+
Each file can have a top-level description of its content:
|
168
|
+
|
169
|
+
```
|
170
|
+
title "Chef Server Directories"
|
171
|
+
|
172
|
+
describe file('/etc/opscode') do
|
173
|
+
it { should be_directory }
|
174
|
+
it { should be_owned_by 'root' }
|
175
|
+
end
|
176
|
+
|
177
|
+
describe file('/etc/opscode-analytics') do
|
178
|
+
it { should be_directory }
|
179
|
+
it { should be_owned_by 'opscode' }
|
180
|
+
it { should be_grouped_into 'opscode' }
|
181
|
+
end
|
182
|
+
|
183
|
+
describe file('/var/log/opscode') do
|
184
|
+
it { should be_directory }
|
185
|
+
it { should be_owned_by 'opscode' }
|
186
|
+
it { should be_grouped_into 'opscode' }
|
187
|
+
end
|
188
|
+
|
189
|
+
describe file('/var/opt/opscode') do
|
190
|
+
it { should be_directory }
|
191
|
+
it { should be_owned_by 'root' }
|
192
|
+
end
|
193
|
+
|
194
|
+
```
|
195
|
+
|
196
|
+
## Are you supporting the `expect` syntax?
|
197
|
+
|
198
|
+
Of course. We still prefer the `should` syntax for UX reasons. We did surveys with various types of customers like devops engineers, auditors, managers. All participants who prefered the `expect` syntax have been Ruby experts. All non-Ruby developers found it easier to understand the `should` syntax.
|
199
|
+
|
200
|
+
### `should` syntax with InSpec
|
201
|
+
|
202
|
+
```
|
203
|
+
describe command('php -v') do
|
204
|
+
its('exit_status') { should eq 0 }
|
205
|
+
end
|
206
|
+
|
207
|
+
describe command('pear list-channels') do
|
208
|
+
its('stdout') { should include('pear.php.net')}
|
209
|
+
end
|
210
|
+
|
211
|
+
describe command('pear list-channels') do
|
212
|
+
its('stdout') { should include('pecl.php.net')}
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
216
|
+
### `expect` syntax with InSpec
|
217
|
+
|
218
|
+
```
|
219
|
+
describe 'PHP' do
|
220
|
+
it 'has php' do
|
221
|
+
expect(command('php -v').exit_status).to eq(0)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'has the pear.php.net channel' do
|
225
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'has the pecl.php.net channel' do
|
229
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
230
|
+
end
|
231
|
+
end
|
232
|
+
```
|
data/docs/profiles.md
CHANGED
@@ -190,6 +190,7 @@ For example:
|
|
190
190
|
- name: linux
|
191
191
|
compliance: base/linux
|
192
192
|
|
193
|
+
You need to `inspec vendor` the profile before uploading it to Chef Compliance version 1.7.7 or newer. The vendor subcommand fetches all dependent profiles and stores them in the `vendor` directory.
|
193
194
|
|
194
195
|
## Define in inspec.yml
|
195
196
|
|
@@ -143,5 +143,15 @@ Please login using `inspec compliance login https://compliance.test --user admin
|
|
143
143
|
end
|
144
144
|
headers
|
145
145
|
end
|
146
|
+
|
147
|
+
def self.target_url(config, profile)
|
148
|
+
if config['server_type'] == 'automate'
|
149
|
+
target = "#{config['server']}/#{profile}/tar"
|
150
|
+
else
|
151
|
+
owner, id = profile.split('/')
|
152
|
+
target = "#{config['server']}/owners/#{owner}/compliance/#{id}/tar"
|
153
|
+
end
|
154
|
+
target
|
155
|
+
end
|
146
156
|
end
|
147
157
|
end
|
@@ -116,6 +116,35 @@ module Compliance
|
|
116
116
|
run_tests(tests, opts)
|
117
117
|
end
|
118
118
|
|
119
|
+
desc 'download PROFILE', 'downloads a profile from Chef Compliance'
|
120
|
+
option :name, type: :string,
|
121
|
+
desc: 'Name of the archive filename (file type will be added)'
|
122
|
+
def download(profile_name)
|
123
|
+
o = options.dup
|
124
|
+
configure_logger(o)
|
125
|
+
|
126
|
+
config = Compliance::Configuration.new
|
127
|
+
return if !loggedin(config)
|
128
|
+
|
129
|
+
if Compliance::API.exist?(config, profile_name)
|
130
|
+
puts "Downloading `#{profile_name}`"
|
131
|
+
|
132
|
+
fetcher = Compliance::Fetcher.resolve(
|
133
|
+
{
|
134
|
+
compliance: profile_name,
|
135
|
+
},
|
136
|
+
)
|
137
|
+
|
138
|
+
# we provide a name, the fetcher adds the extension
|
139
|
+
_owner, id = profile_name.split('/')
|
140
|
+
file_name = fetcher.fetch(o.name || id)
|
141
|
+
puts "Profile stored to #{file_name}"
|
142
|
+
else
|
143
|
+
puts "Profile #{profile_name} is not available in Chef Compliance."
|
144
|
+
exit 1
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
119
148
|
desc 'upload PATH', 'uploads a local profile to Chef Compliance'
|
120
149
|
option :overwrite, type: :boolean, default: false,
|
121
150
|
desc: 'Overwrite existing profile on Chef Compliance.'
|
@@ -53,23 +53,13 @@ EOF
|
|
53
53
|
if !Compliance::API.exist?(config, profile)
|
54
54
|
fail Inspec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
|
55
55
|
end
|
56
|
-
profile_fetch_url = target_url(
|
56
|
+
profile_fetch_url = Compliance::API.target_url(config, profile)
|
57
57
|
end
|
58
58
|
new(profile_fetch_url, config)
|
59
59
|
rescue URI::Error => _e
|
60
60
|
nil
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.target_url(profile, config)
|
64
|
-
if config['server_type'] == 'automate'
|
65
|
-
target = "#{config['server']}/#{profile}/tar"
|
66
|
-
else
|
67
|
-
owner, id = profile.split('/')
|
68
|
-
target = "#{config['server']}/owners/#{owner}/compliance/#{id}/tar"
|
69
|
-
end
|
70
|
-
target
|
71
|
-
end
|
72
|
-
|
73
63
|
# We want to save compliance: in the lockfile rather than url: to
|
74
64
|
# make sure we go back through the Compliance API handling.
|
75
65
|
def resolved_source
|
@@ -12,7 +12,7 @@ module Supermarket
|
|
12
12
|
# displays a list of profiles
|
13
13
|
def self.profiles(supermarket_url = SUPERMARKET_URL)
|
14
14
|
url = "#{supermarket_url}/api/v1/tools-search"
|
15
|
-
_success, data = get(url, { type: 'compliance_profile', items: 100
|
15
|
+
_success, data = get(url, { type: 'compliance_profile', items: 100 })
|
16
16
|
if !data.nil?
|
17
17
|
profiles = JSON.parse(data)
|
18
18
|
profiles['items'].map { |x|
|
data/lib/inspec/cli.rb
CHANGED
@@ -9,6 +9,7 @@ require 'thor'
|
|
9
9
|
require 'json'
|
10
10
|
require 'pp'
|
11
11
|
require 'utils/json_log'
|
12
|
+
require 'utils/latest_version'
|
12
13
|
require 'inspec/base_cli'
|
13
14
|
require 'inspec/plugins'
|
14
15
|
require 'inspec/runner_mock'
|
@@ -223,6 +224,11 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
|
|
223
224
|
desc 'version', 'prints the version of this tool'
|
224
225
|
def version
|
225
226
|
puts Inspec::VERSION
|
227
|
+
# display outdated version
|
228
|
+
latest = LatestInSpecVersion.new.latest
|
229
|
+
if Gem::Version.new(Inspec::VERSION) < Gem::Version.new(latest)
|
230
|
+
puts "\nYour version of InSpec is out of date! The latest version is #{latest}."
|
231
|
+
end
|
226
232
|
end
|
227
233
|
|
228
234
|
private
|
data/lib/inspec/version.rb
CHANGED
data/lib/resources/json.rb
CHANGED
data/lib/resources/package.rb
CHANGED
@@ -143,11 +143,13 @@ module Inspec::Resources
|
|
143
143
|
# parse data
|
144
144
|
pkg = JSON.parse(cmd.stdout)[0]
|
145
145
|
{
|
146
|
-
name: pkg
|
146
|
+
name: pkg['name'],
|
147
147
|
installed: true,
|
148
|
-
version: pkg
|
148
|
+
version: pkg['installed'][0]['version'],
|
149
149
|
type: 'brew',
|
150
150
|
}
|
151
|
+
rescue JSON::ParserError => _e
|
152
|
+
return nil
|
151
153
|
end
|
152
154
|
end
|
153
155
|
|
@@ -42,6 +42,20 @@ module Inspec::Resources
|
|
42
42
|
res
|
43
43
|
end
|
44
44
|
|
45
|
+
def method_missing(name)
|
46
|
+
param = params[name.to_s]
|
47
|
+
return nil if param.nil?
|
48
|
+
# extract first value if we have only one value in array
|
49
|
+
return param[0] if param.length == 1
|
50
|
+
param
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
'PostgreSQL Configuration'
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
45
59
|
def read_content
|
46
60
|
@content = ''
|
47
61
|
@params = {}
|
@@ -60,7 +74,10 @@ module Inspec::Resources
|
|
60
74
|
raw_conf = read_file(to_read[0])
|
61
75
|
@content += raw_conf
|
62
76
|
|
63
|
-
|
77
|
+
opts = {
|
78
|
+
assignment_re: /^\s*([^=]*?)\s*=\s*[']?\s*(.*?)\s*[']?\s*$/,
|
79
|
+
}
|
80
|
+
params = SimpleConfig.new(raw_conf, opts).params
|
64
81
|
@params.merge!(params)
|
65
82
|
|
66
83
|
to_read = to_read.drop(1)
|
@@ -87,9 +104,5 @@ module Inspec::Resources
|
|
87
104
|
def read_file(path)
|
88
105
|
@files_contents[path] ||= inspec.file(path).content
|
89
106
|
end
|
90
|
-
|
91
|
-
def to_s
|
92
|
-
'PostgreSQL Configuration'
|
93
|
-
end
|
94
107
|
end
|
95
108
|
end
|
data/lib/resources/yum.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
class LatestInSpecVersion
|
8
|
+
# fetches the latest version from rubygems server
|
9
|
+
def latest
|
10
|
+
uri = URI('https://rubygems.org/api/v1/gems/inspec.json')
|
11
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') {|http|
|
12
|
+
http.read_timeout = 0.5
|
13
|
+
http.get(uri.path)
|
14
|
+
}
|
15
|
+
inspec_info = JSON.parse(res.body)
|
16
|
+
inspec_info['version']
|
17
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- docs/dsl_resource.md
|
246
246
|
- docs/inspec_and_friends.md
|
247
247
|
- docs/matchers.md
|
248
|
+
- docs/migration.md
|
248
249
|
- docs/plugin_kitchen_inspec.html.md
|
249
250
|
- docs/profiles.md
|
250
251
|
- docs/resources/apache_conf.md.erb
|
@@ -524,6 +525,7 @@ files:
|
|
524
525
|
- lib/utils/find_files.rb
|
525
526
|
- lib/utils/hash.rb
|
526
527
|
- lib/utils/json_log.rb
|
528
|
+
- lib/utils/latest_version.rb
|
527
529
|
- lib/utils/modulator.rb
|
528
530
|
- lib/utils/object_traversal.rb
|
529
531
|
- lib/utils/parser.rb
|
@@ -549,7 +551,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
549
551
|
version: '0'
|
550
552
|
requirements: []
|
551
553
|
rubyforge_project:
|
552
|
-
rubygems_version: 2.
|
554
|
+
rubygems_version: 2.5.2
|
553
555
|
signing_key:
|
554
556
|
specification_version: 4
|
555
557
|
summary: Infrastructure and compliance testing.
|