inspec 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '0.32.0'.freeze
7
+ VERSION = '0.33.0'.freeze
8
8
  end
@@ -232,7 +232,7 @@ end
232
232
  RSpec::Matchers.define :cmp do |first_expected|
233
233
 
234
234
  def integer?(value)
235
- !(value =~ /\A[1-9]\d*\Z/).nil?
235
+ !(value =~ /\A0+\Z|\A[1-9]\d*\Z/).nil?
236
236
  end
237
237
 
238
238
  def float?(value)
@@ -21,7 +21,7 @@ module Inspec::Resources
21
21
 
22
22
  def initialize(conf_path = nil)
23
23
  @conf_path = conf_path || inspec.apache.conf_path
24
- @conf_dir = File.dirname(@conf_path)
24
+ @conf_dir = conf_path ? File.dirname(@conf_path) : inspec.apache.conf_dir
25
25
  @files_contents = {}
26
26
  @content = nil
27
27
  @params = nil
@@ -33,7 +33,7 @@ module Inspec::Resources
33
33
  @log_dir = '/var/log/'
34
34
  @log_path = '/var/log/mysql.log'
35
35
  @log_group = 'adm'
36
- case os[:release]
36
+ case inspec.os[:release]
37
37
  when '14.04'
38
38
  @log_dir_group = 'syslog'
39
39
  else
@@ -22,13 +22,9 @@ module Inspec::Resources
22
22
  unless inspec.os.windows?
23
23
  return skip_resource 'The `script` resource is not supported on your OS yet.'
24
24
  end
25
-
26
- # encodes a script as base64 to run as powershell encodedCommand
27
- # this comes with performance issues: @see https://gist.github.com/fnichol/7b20596b950e65fb96f9
28
- require 'winrm'
29
- script = WinRM::PowershellScript.new(script)
30
- cmd = "powershell -encodedCommand #{script.encoded}"
31
- super(cmd)
25
+ # since WinRM 2.0 and the default use of powershell for local execution in
26
+ # train, we do not need to wrap the script here anymore
27
+ super(script)
32
28
  end
33
29
 
34
30
  # we cannot determine if a command exists, because that does not work for scripts
@@ -407,9 +407,9 @@ module Inspec::Resources
407
407
  # read all enabled services from runlevel
408
408
  # on rhel via: 'chkconfig --list', is not installed by default
409
409
  # bash: for i in `find /etc/rc*.d -name S*`; do basename $i | sed -r 's/^S[0-9]+//'; done | sort | uniq
410
- enabled_services_cmd = inspec.command('find /etc/rc*.d -name S*')
410
+ enabled_services_cmd = inspec.command('find /etc/rc*.d /etc/init.d/rc*.d -name S*').stdout
411
411
  service_line = %r{rc(?<runlevel>[0-6])\.d/S[^/]*?#{Regexp.escape service_name}$}
412
- all_services = enabled_services_cmd.stdout.split("\n").map { |line|
412
+ all_services = enabled_services_cmd.split("\n").map { |line|
413
413
  service_line.match(line)
414
414
  }.compact
415
415
  enabled = !all_services.empty?
@@ -575,7 +575,7 @@ module Inspec::Resources
575
575
  # - 6: Pause Pending
576
576
  # - 7: Paused
577
577
  def info(service_name)
578
- cmd = inspec.command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name #{service_name}| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq '#{service_name}' -or $_.DisplayName -eq '#{service_name}'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json")
578
+ cmd = inspec.command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name '#{service_name}'| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq '#{service_name}' -or $_.DisplayName -eq '#{service_name}'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json")
579
579
 
580
580
  # cannot rely on exit code for now, successful command returns exit code 1
581
581
  # return nil if cmd.exit_status != 0
@@ -2,6 +2,8 @@
2
2
  # author: Christoph Hartmann
3
3
  # author: Dominik Richter
4
4
 
5
+ require 'securerandom'
6
+
5
7
  module Inspec::Resources
6
8
  # This resource allows users to run vbscript on windows machines. We decided
7
9
  # not to use scriptcontrol, due to the fact that it works on 32 bit systems only:
@@ -34,10 +36,11 @@ module Inspec::Resources
34
36
 
35
37
  def initialize(vbscript)
36
38
  return skip_resource 'The `vbscript` resource is not supported on your OS yet.' unless inspec.os.windows?
37
-
39
+ @seperator = SecureRandom.uuid
38
40
  cmd = <<-EOH
39
41
  $vbscript = @"
40
42
  #{vbscript}
43
+ Wscript.Stdout.Write "#{@seperator}"
41
44
  "@
42
45
  $filename = [System.IO.Path]::GetTempFileName() + ".vbs"
43
46
  New-Item $filename -type file -force -value $vbscript | Out-Null
@@ -47,8 +50,21 @@ EOH
47
50
  super(cmd)
48
51
  end
49
52
 
53
+ def result
54
+ @result ||= parse_stdout
55
+ end
56
+
50
57
  def to_s
51
58
  'Windows VBScript'
52
59
  end
60
+
61
+ private
62
+
63
+ def parse_stdout
64
+ res = inspec.backend.run_command(@command)
65
+ parsed_result = res.stdout.gsub(/#{@seperator}\r\n$/, '')
66
+ res.stdout = parsed_result
67
+ res
68
+ end
53
69
  end
54
70
  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: 0.32.0
4
+ version: 0.33.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: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.16.0
19
+ version: 0.19.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '1.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.16.0
29
+ version: 0.19.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.0'
@@ -296,6 +296,7 @@ files:
296
296
  - lib/inspec/cli.rb
297
297
  - lib/inspec/completions/bash.sh.erb
298
298
  - lib/inspec/completions/zsh.sh.erb
299
+ - lib/inspec/control_eval_context.rb
299
300
  - lib/inspec/dependencies/dependency_set.rb
300
301
  - lib/inspec/dependencies/lockfile.rb
301
302
  - lib/inspec/dependencies/requirement.rb
@@ -303,10 +304,12 @@ files:
303
304
  - lib/inspec/dependencies/vendor_index.rb
304
305
  - lib/inspec/describe.rb
305
306
  - lib/inspec/dsl.rb
307
+ - lib/inspec/dsl_shared.rb
306
308
  - lib/inspec/env_printer.rb
307
309
  - lib/inspec/errors.rb
308
310
  - lib/inspec/expect.rb
309
311
  - lib/inspec/fetcher.rb
312
+ - lib/inspec/library_eval_context.rb
310
313
  - lib/inspec/log.rb
311
314
  - lib/inspec/metadata.rb
312
315
  - lib/inspec/objects.rb