inspec 0.21.3 → 0.21.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6b6f3f9425e2fdd338472f8b5ce2f8a8b9d7f68
4
- data.tar.gz: 0fbf58b53e5cd374f8078f3e159655d61bda41e7
3
+ metadata.gz: 6c4b9ddfdd938125e49d0de346cd3ddc680102ec
4
+ data.tar.gz: 611a23c93ca0a9a88f0bca9c904c8976ea42b34f
5
5
  SHA512:
6
- metadata.gz: 9107c45334fb70cba6cfba959270e698d09482029fda4a596e63f9067e9bccfb58e82e9e4e4555fd77b682eccc08c0d4a35721ff0d220bae97bc58c829b08e16
7
- data.tar.gz: 18313760dd162fc7ec7e4876d17e00bb06972f16064e7a3ecc457cbcb01fd2ce70713c3cc707baf201dbd0569a562439748c2de9d54307b47f21619b303489a3
6
+ metadata.gz: 9ef13914cdf0244f62ec4e77bf978d4397fd35698394be0d0b1cf4369ea2eaea6b34b9091c7d2467040ede39e2696e8c1bf91031ab7c53c598c953013aff6cb8
7
+ data.tar.gz: f5decb00ff30769b253d841566798f55a6dc3f8f1582f76d6a712188ddbf9bb25e8e325b8ea7c1296b52b9c7e27e497bdd37c18f2c91e42b6d3e28294349afc3
@@ -1,7 +1,14 @@
1
1
  # Change Log
2
2
 
3
- ## [0.21.3](https://github.com/chef/inspec/tree/0.21.3) (2016-05-12)
4
- [Full Changelog](https://github.com/chef/inspec/compare/v0.21.2...0.21.3)
3
+ ## [0.21.4](https://github.com/chef/inspec/tree/0.21.4) (2016-05-13)
4
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.21.3...0.21.4)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - use struct for processes list [\#744](https://github.com/chef/inspec/pull/744) ([arlimus](https://github.com/arlimus))
9
+
10
+ ## [v0.21.3](https://github.com/chef/inspec/tree/v0.21.3) (2016-05-11)
11
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.21.2...v0.21.3)
5
12
 
6
13
  **Fixed bugs:**
7
14
 
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ # copyright: 2016, Chef Software Inc.
3
+ # author: Dominik Richter
4
+ # author: Christoph Hartmann
5
+ # license: All rights reserved
6
+
7
+ class Struct
8
+ unless instance_methods.include? :to_h
9
+ def to_h
10
+ Hash[each_pair.to_a]
11
+ end
12
+ end
13
+ end
@@ -4,6 +4,7 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  require 'forwardable'
7
+ require 'inspec/polyfill'
7
8
  require 'inspec/fetcher'
8
9
  require 'inspec/source_reader'
9
10
  require 'inspec/metadata'
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.21.3'.freeze
6
+ VERSION = '0.21.4'.freeze
7
7
  end
@@ -26,7 +26,6 @@ module Inspec::Resources
26
26
  grep = '(/[^/]*)*'+grep if grep[0] != '/'
27
27
  grep = Regexp.new('^' + grep + '(\s|$)')
28
28
  end
29
-
30
29
  all_cmds = ps_aux
31
30
  @list = all_cmds.find_all do |hm|
32
31
  hm[:command] =~ grep
@@ -57,7 +56,12 @@ module Inspec::Resources
57
56
  build_process_list(command, regex, os)
58
57
  end
59
58
 
60
- def build_process_list(command, regex, os) # rubocop:disable MethodLength, Metrics/AbcSize
59
+ Process = Struct.new(:label, :user, :pid,
60
+ :cpu, :mem, :vsz,
61
+ :rss, :tty, :stat,
62
+ :start, :time, :command)
63
+
64
+ def build_process_list(command, regex, os)
61
65
  cmd = inspec.command(command)
62
66
  all = cmd.stdout.split("\n")[1..-1]
63
67
  return [] if all.nil?
@@ -66,40 +70,13 @@ module Inspec::Resources
66
70
  line.match(regex)
67
71
  end.compact
68
72
 
69
- if os.linux?
70
- lines.map do |m|
71
- {
72
- label: m[1],
73
- user: m[2],
74
- pid: m[3].to_i,
75
- cpu: m[4],
76
- mem: m[5],
77
- vsz: m[6].to_i,
78
- rss: m[7].to_i,
79
- tty: m[8],
80
- stat: m[9],
81
- start: m[10],
82
- time: m[11],
83
- command: m[12],
84
- }
85
- end
86
- else
87
- lines.map do |m|
88
- {
89
- label: nil,
90
- user: m[1],
91
- pid: m[2].to_i,
92
- cpu: m[3],
93
- mem: m[4],
94
- vsz: m[5].to_i,
95
- rss: m[6].to_i,
96
- tty: m[7],
97
- stat: m[8],
98
- start: m[9],
99
- time: m[10],
100
- command: m[11],
101
- }
102
- end
73
+ lines.map do |m|
74
+ a = m.to_a[1..-1] # grab all matching groups
75
+ a.unshift(nil) unless os.linux?
76
+ a[2] = a[2].to_i
77
+ a[5] = a[5].to_i
78
+ a[6] = a[6].to_i
79
+ Process.new(*a)
103
80
  end
104
81
  end
105
82
  end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+
5
+ class HashMap
6
+ class << self
7
+ def [](hash, *keys)
8
+ return hash if keys.empty? || hash.nil?
9
+ key = keys.shift
10
+ if hash.is_a?(Array)
11
+ map = hash.map { |i| [i, key] }
12
+ else
13
+ map = hash[key]
14
+ end
15
+ [map, *keys]
16
+ rescue NoMethodError => _
17
+ nil
18
+ end
19
+ end
20
+ end
21
+
22
+ class StringMap
23
+ class << self
24
+ def [](hash, *keys)
25
+ return hash if keys.empty? || hash.nil?
26
+ key = keys.shift
27
+ if hash.is_a?(Array)
28
+ map = hash.map { |i| [i, key] }
29
+ else
30
+ map = hash[key]
31
+ end
32
+ [map, *keys]
33
+ rescue NoMethodError => _
34
+ nil
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ name: complete
2
+ title: complete example profile
3
+ maintainer: Chef Software, Inc.
4
+ copyright: Chef Software, Inc.
5
+ copyright_email: support@chef.io
6
+ license: Proprietary, All rights reserved
7
+ summary: Testing stub
8
+ version: 1.0.0
9
+ supports:
10
+ - os-family: linux
@@ -0,0 +1,3 @@
1
+ class Tiny < Inspec.resource(1)
2
+ name 'tiny'
3
+ end
@@ -13,7 +13,8 @@ describe 'Inspec::Resources::Processes' do
13
13
 
14
14
  it 'verify processes resource' do
15
15
  resource = MockLoader.new(:freebsd10).load_resource('processes', '/bin/bash')
16
- _(resource.list).must_equal [{
16
+ _(resource.list.length).must_equal 1
17
+ _(resource.list[0].to_h).must_equal({
17
18
  label: nil,
18
19
  user: 'root',
19
20
  pid: 1,
@@ -26,14 +27,13 @@ describe 'Inspec::Resources::Processes' do
26
27
  start: '14:15',
27
28
  time: '0:00',
28
29
  command: '/bin/bash',
29
- }]
30
-
31
- _(resource.list.length).must_equal 1
30
+ })
32
31
  end
33
32
 
34
33
  it 'verify processes resource on linux os' do
35
34
  resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
36
- _(resource.list).must_equal [{
35
+ _(resource.list.length).must_equal 1
36
+ _(resource.list[0].to_h).must_equal({
37
37
  label: 'system_u:system_r:kernel_t:s0',
38
38
  user: 'root',
39
39
  pid: 1,
@@ -46,9 +46,16 @@ describe 'Inspec::Resources::Processes' do
46
46
  start: 'May04',
47
47
  time: '0:01',
48
48
  command: '/sbin/init',
49
- }]
49
+ })
50
+ end
50
51
 
51
- _(resource.list.length).must_equal 1
52
+ it 'access attributes of a process' do
53
+ resource = MockLoader.new(:centos6).load_resource('processes', '/sbin/init')
54
+ process = resource.list[0]
55
+ process.user.must_equal 'root'
56
+ process[:user].must_equal 'root'
57
+ process['user'].must_equal 'root'
58
+ process[1].must_equal 'root'
52
59
  end
53
60
 
54
61
  it 'retrieves the users and states as arrays' do
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: 0.21.3
4
+ version: 0.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r-train
@@ -279,6 +279,7 @@ files:
279
279
  - lib/inspec/plugins/fetcher.rb
280
280
  - lib/inspec/plugins/resource.rb
281
281
  - lib/inspec/plugins/source_reader.rb
282
+ - lib/inspec/polyfill.rb
282
283
  - lib/inspec/profile.rb
283
284
  - lib/inspec/profile_context.rb
284
285
  - lib/inspec/resource.rb
@@ -358,6 +359,7 @@ files:
358
359
  - lib/utils/filter_array.rb
359
360
  - lib/utils/find_files.rb
360
361
  - lib/utils/hash.rb
362
+ - lib/utils/hash_map.rb
361
363
  - lib/utils/json_log.rb
362
364
  - lib/utils/modulator.rb
363
365
  - lib/utils/object_traversal.rb
@@ -549,6 +551,8 @@ files:
549
551
  - test/unit/mock/profiles/legacy-empty-metadata/metadata.rb
550
552
  - test/unit/mock/profiles/legacy-simple-metadata/metadata.rb
551
553
  - test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep
554
+ - test/unit/mock/profiles/resource-tiny/inspec.yml
555
+ - test/unit/mock/profiles/resource-tiny/libraries/resource.rb
552
556
  - test/unit/mock/profiles/simple-metadata/inspec.yml
553
557
  - test/unit/mock/profiles/skippy-profile-os/controls/one.rb
554
558
  - test/unit/mock/profiles/skippy-profile-os/inspec.yml
@@ -635,7 +639,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
635
639
  version: '0'
636
640
  requirements: []
637
641
  rubyforge_project:
638
- rubygems_version: 2.4.6
642
+ rubygems_version: 2.5.1
639
643
  signing_key:
640
644
  specification_version: 4
641
645
  summary: Infrastructure and compliance testing.
@@ -824,6 +828,8 @@ test_files:
824
828
  - test/unit/mock/profiles/legacy-empty-metadata/metadata.rb
825
829
  - test/unit/mock/profiles/legacy-simple-metadata/metadata.rb
826
830
  - test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep
831
+ - test/unit/mock/profiles/resource-tiny/inspec.yml
832
+ - test/unit/mock/profiles/resource-tiny/libraries/resource.rb
827
833
  - test/unit/mock/profiles/simple-metadata/inspec.yml
828
834
  - test/unit/mock/profiles/skippy-profile-os/controls/one.rb
829
835
  - test/unit/mock/profiles/skippy-profile-os/inspec.yml