wmi-lite 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/wmi-lite.rb +1 -1
- data/lib/wmi-lite/version.rb +1 -1
- data/lib/wmi-lite/wmi.rb +1 -1
- data/lib/wmi-lite/wmi_exception.rb +2 -2
- data/lib/wmi-lite/wmi_instance.rb +1 -1
- metadata +15 -59
- data/.gitignore +0 -27
- data/.rspec +0 -2
- data/.travis.yml +0 -8
- data/CHANGELOG.md +0 -11
- data/CONTRIBUTING.md +0 -5
- data/Gemfile +0 -2
- data/README.md +0 -111
- data/Rakefile +0 -1
- data/spec/functional/wmi_spec.rb +0 -161
- data/spec/spec_helper.rb +0 -12
- data/spec/unit/wmi_spec.rb +0 -295
- data/wmi-lite.gemspec +0 -31
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OTEwODJlNGE4OTMzNTk4OTM0NDk1ZWQ2ZTNmYTdiODljODllNGQzZA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c3468b47692664e3588909b2f70738a71e67ca6ce9a5d34402e9e6a1956081b
|
4
|
+
data.tar.gz: 61696e1d2f0f5b86b7c2e61655ccbbb36aa9bea54d698595031527179eb4b81c
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTgzMGFiYTA3OGEyMzZiMTAxZWEwOGU4YjNlZjI3MDdiOGNlMzNjYjc2NzI4
|
11
|
-
YjM4NjZjNWY4YzAxNTM5NDU2MTUxMDcxZWVkNWE4M2NmYTA4ZDM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YWQ5ZTUyYzg5MTQ4ZDcwNmVkNmEwNzdhZmQxNTk2ZWI2NWMxMjlmOTA2N2Q4
|
14
|
-
NDJjZjYyYTc5NWNmNmUxYzZjMTY5ZjgxYTU5ODhlNGRjMDlkOWYyMTdlOTJh
|
15
|
-
NjhlOWEwOTk1YzgwMmQ2MGJhNjk3NjA3MWEzNDQ3OTBmNWRlMTk=
|
6
|
+
metadata.gz: 5368265ea9d677227a8bc03f9163db30e1630c4c44078eedf4ad0613d1e04d7da43c233d585951905094943151ae9b351072745aa86c07c9ae25983dba797a0f
|
7
|
+
data.tar.gz: 84eb54162d5f3c1b4eb2a9116cfe135348f64be04d6cfa00f3bd2b9c212d5ad0b677bbf88c4a675856a2d62e85dda74d304d473af79942da3ad47bdc769e2f62
|
data/lib/wmi-lite.rb
CHANGED
data/lib/wmi-lite/version.rb
CHANGED
data/lib/wmi-lite/wmi.rb
CHANGED
metadata
CHANGED
@@ -1,83 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wmi-lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Edwards
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ! '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry-debugger
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ! '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ! '>='
|
52
|
+
- - ">="
|
81
53
|
- !ruby/object:Gem::Version
|
82
54
|
version: '0'
|
83
55
|
description: A lightweight utility over win32ole for accessing basic WMI (Windows
|
@@ -85,32 +57,20 @@ description: A lightweight utility over win32ole for accessing basic WMI (Window
|
|
85
57
|
It has no runtime dependencies other than Ruby, so it can be used without concerns
|
86
58
|
around dependency issues.
|
87
59
|
email:
|
88
|
-
- dev@
|
60
|
+
- dev@chef.io
|
89
61
|
executables: []
|
90
62
|
extensions: []
|
91
63
|
extra_rdoc_files: []
|
92
64
|
files:
|
93
|
-
- .gitignore
|
94
|
-
- .rspec
|
95
|
-
- .travis.yml
|
96
|
-
- CHANGELOG.md
|
97
|
-
- CONTRIBUTING.md
|
98
|
-
- Gemfile
|
99
65
|
- LICENSE
|
100
|
-
- README.md
|
101
|
-
- Rakefile
|
102
66
|
- lib/wmi-lite.rb
|
103
67
|
- lib/wmi-lite/version.rb
|
104
68
|
- lib/wmi-lite/wmi.rb
|
105
69
|
- lib/wmi-lite/wmi_exception.rb
|
106
70
|
- lib/wmi-lite/wmi_instance.rb
|
107
|
-
|
108
|
-
- spec/spec_helper.rb
|
109
|
-
- spec/unit/wmi_spec.rb
|
110
|
-
- wmi-lite.gemspec
|
111
|
-
homepage: https://github.com/opscode/wmi-lite
|
71
|
+
homepage: https://github.com/chef/wmi-lite
|
112
72
|
licenses:
|
113
|
-
- Apache
|
73
|
+
- Apache-2.0
|
114
74
|
metadata: {}
|
115
75
|
post_install_message:
|
116
76
|
rdoc_options: []
|
@@ -118,23 +78,19 @@ require_paths:
|
|
118
78
|
- lib
|
119
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
80
|
requirements:
|
121
|
-
- -
|
81
|
+
- - ">="
|
122
82
|
- !ruby/object:Gem::Version
|
123
83
|
version: '0'
|
124
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
85
|
requirements:
|
126
|
-
- -
|
86
|
+
- - ">="
|
127
87
|
- !ruby/object:Gem::Version
|
128
88
|
version: '0'
|
129
89
|
requirements: []
|
130
90
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.7.7
|
132
92
|
signing_key:
|
133
93
|
specification_version: 4
|
134
94
|
summary: A lightweight utility library for accessing basic WMI (Windows Management
|
135
95
|
Instrumentation) functionality on Windows
|
136
|
-
test_files:
|
137
|
-
- spec/functional/wmi_spec.rb
|
138
|
-
- spec/spec_helper.rb
|
139
|
-
- spec/unit/wmi_spec.rb
|
140
|
-
has_rdoc:
|
96
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
.autotest
|
2
|
-
coverage
|
3
|
-
.DS_Store
|
4
|
-
pkg
|
5
|
-
*/tags
|
6
|
-
*~
|
7
|
-
|
8
|
-
# you should check in your Gemfile.lock in applications, and not in gems
|
9
|
-
Gemfile.lock
|
10
|
-
Gemfile.local
|
11
|
-
|
12
|
-
# Do not check in the .bundle directory, or any of the files inside it. Those files are specific to each particular machine, and are used to persist installation options between runs of the bundle install command.
|
13
|
-
.bundle
|
14
|
-
|
15
|
-
# ignore some common Bundler 'binstubs' directory names
|
16
|
-
# http://gembundler.com/man/bundle-exec.1.html
|
17
|
-
b/
|
18
|
-
binstubs/
|
19
|
-
|
20
|
-
# RVM and RBENV ruby version files
|
21
|
-
.rbenv-version
|
22
|
-
.rvmrc
|
23
|
-
|
24
|
-
# Documentation
|
25
|
-
_site/*
|
26
|
-
.yardoc/
|
27
|
-
doc/
|
data/.rspec
DELETED
data/.travis.yml
DELETED
data/CHANGELOG.md
DELETED
data/CONTRIBUTING.md
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
Wmi-Lite
|
2
|
-
========
|
3
|
-
|
4
|
-
`wmi-lite` is a lightweight Ruby gem utility library for accessing basic
|
5
|
-
[Windows Management Instrumentation (WMI)](http://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx)
|
6
|
-
functionality on Windows. It has no dependencies outside of the Ruby interpreter
|
7
|
-
and libraries and of course the Windows operating system.
|
8
|
-
|
9
|
-
Installation
|
10
|
-
------------
|
11
|
-
|
12
|
-
To install it, run:
|
13
|
-
|
14
|
-
gem install wmi-lite
|
15
|
-
|
16
|
-
Usage
|
17
|
-
-----
|
18
|
-
To use `wmi-lite` in your Ruby source code, just `require` it:
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
require 'wmi-lite'
|
22
|
-
```
|
23
|
-
|
24
|
-
You can then instantiate an object through `WmiLite::Wmi.new` that will allow you to query a WMI namespace by calling methods on
|
25
|
-
that object.
|
26
|
-
|
27
|
-
* The default namespace if no argument is specified to `new` is `root\cimv2`. To override, pass the desired WMI
|
28
|
-
namespace string as an argument to the constructor.
|
29
|
-
* To execute queries against the object's namespace, use the `instances_of`, `first_of`, and `query` methods.
|
30
|
-
* The `instances_of` method will return all instances of a given class in the namespace as an array of instances.
|
31
|
-
* The `query` method returns the results of an arbitrary WMI Query Language (WQL) query as an array of instances.
|
32
|
-
* The `first_of` method will return the first of all instances of a given class in the namespace.
|
33
|
-
* Each instance is represented by a Ruby `Hash` for which each property value of the instance is indexed by
|
34
|
-
the string name of the property as documented in the [WMI Schema](http://technet.microsoft.com/en-us/library/cc180287.aspx) or
|
35
|
-
as registered in the local system's WMI repository.
|
36
|
-
* The string name specified to the aformentioned `Hash` is case insensitive.
|
37
|
-
|
38
|
-
#### Examples
|
39
|
-
Use of the `instances_of`, `query`, and `first_of` methods of the `WmiLite::Wmi` object is demonstrated below.
|
40
|
-
|
41
|
-
##### Count cores in the system
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
cores = 0
|
45
|
-
wmi = WmiLite::Wmi.new
|
46
|
-
processors = wmi.instances_of('Win32_Processor')
|
47
|
-
processors.each do | processor |
|
48
|
-
cores += processor['numberofcores']
|
49
|
-
end
|
50
|
-
puts "\nThis system has #{cores} core(s).\n"
|
51
|
-
```
|
52
|
-
|
53
|
-
##### Determine if the system is domain-joined
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
wmi = WmiLite::Wmi.new
|
57
|
-
computer_system = wmi.first_of('Win32_ComputerSystem')
|
58
|
-
is_in_domain = computer_system['partofdomain']
|
59
|
-
puts "\nThis system is #{is_in_domain ? '' : 'not '}domain joined.\n"
|
60
|
-
```
|
61
|
-
|
62
|
-
##### List Group Policy Objects (GPOs) applied to the system
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
wmi = WmiLite::Wmi.new('root\rsop\computer')
|
66
|
-
gpos = wmi.instances_of('RSOP_GPO')
|
67
|
-
puts "\n#{'GPO Id'.ljust(40)}\tName"
|
68
|
-
puts "#{'------'.ljust(40)}\t----\n"
|
69
|
-
gpos.each do | gpo |
|
70
|
-
gpo_id = gpo['guidname']
|
71
|
-
gpo_display_name = gpo['name']
|
72
|
-
puts "#{gpo_id.ljust(40)}\t#{gpo_display_name}"
|
73
|
-
end
|
74
|
-
puts 'No GPOs' if gpos.count == 0
|
75
|
-
puts
|
76
|
-
```
|
77
|
-
|
78
|
-
##### List ruby-related processes
|
79
|
-
```ruby
|
80
|
-
puts "Ruby processes:\n"
|
81
|
-
wmi = WmiLite::Wmi.new
|
82
|
-
processes = wmi.query('select * from Win32_Process where Name LIKE \'%ruby%\'')
|
83
|
-
puts "\n#{'Process Id'.ljust(10)} Name"
|
84
|
-
puts "#{'----------'.ljust(10)} ----\n"
|
85
|
-
processes.each do | process |
|
86
|
-
pid = process['processid']
|
87
|
-
name = process['name']
|
88
|
-
puts "#{pid.to_s.ljust(10)} #{name}"
|
89
|
-
end
|
90
|
-
puts
|
91
|
-
```
|
92
|
-
|
93
|
-
License & Authors
|
94
|
-
-----------------
|
95
|
-
|
96
|
-
Author:: Adam Edwards (<adamed@getchef.com>)
|
97
|
-
Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
98
|
-
License:: Apache License, Version 2.0
|
99
|
-
|
100
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
101
|
-
you may not use this file except in compliance with the License.
|
102
|
-
You may obtain a copy of the License at
|
103
|
-
|
104
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
105
|
-
|
106
|
-
Unless required by applicable law or agreed to in writing, software
|
107
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
108
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
109
|
-
See the License for the specific language governing permissions and
|
110
|
-
limitations under the License.
|
111
|
-
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
data/spec/functional/wmi_spec.rb
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Edwards (<adamed@getchef.com>)
|
3
|
-
#
|
4
|
-
# Copyright:: 2014, Chef Software, Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'spec_helper'
|
20
|
-
|
21
|
-
describe WmiLite::Wmi, :windows_only do
|
22
|
-
let(:wmi) { WmiLite::Wmi.new(namespace) }
|
23
|
-
|
24
|
-
def validate_wmi_results(results, class_name)
|
25
|
-
result_collection = cardinality_transform.call(results)
|
26
|
-
result_collection.each do | result |
|
27
|
-
# make sure the class name of the instance is what we asked for
|
28
|
-
expect(result['creationclassname'].downcase).to eql(class_name.downcase)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
shared_examples_for 'a valid WMI query result' do
|
33
|
-
it 'should successfully return multiple results' do
|
34
|
-
query_parameter = wmi_query.nil? ? wmi_class : wmi_query
|
35
|
-
results = wmi.send(query_method, query_parameter)
|
36
|
-
validate_wmi_results(results, wmi_class)
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'when the namespace is invalid' do
|
40
|
-
it_behaves_like 'an invalid namespace'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
shared_examples_for 'an invalid query' do
|
45
|
-
it 'should raise an exception' do
|
46
|
-
expect { wmi.send(query_method, wmi_query) }.to raise_error(WmiLite::WmiException)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
shared_examples_for 'an invalid namespace' do
|
51
|
-
it 'should raise an exception if an invalid namespace is specified' do
|
52
|
-
invalid_wmi = WmiLite::Wmi.new('root/notvalid')
|
53
|
-
expect { invalid_wmi.send(query_method, wmi_query) }.to raise_error(WmiLite::WmiException)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
shared_examples_for 'a valid WMI query' do
|
58
|
-
let(:wmi_class) { 'Win32_LogicalDisk' }
|
59
|
-
it_behaves_like 'a valid WMI query result'
|
60
|
-
|
61
|
-
let(:wmi_class) { 'Win32_ComputerSystem' }
|
62
|
-
it_behaves_like 'a valid WMI query result'
|
63
|
-
|
64
|
-
let(:wmi_class) { 'Win32_Process' }
|
65
|
-
it_behaves_like 'a valid WMI query result'
|
66
|
-
|
67
|
-
context 'that return 0 results' do
|
68
|
-
let(:wmi_class) { 'Win32_TapeDrive' }
|
69
|
-
it_behaves_like 'a valid WMI query result'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'when making valid queries' do
|
74
|
-
let(:namespace) { nil }
|
75
|
-
let(:wmi_query) { nil }
|
76
|
-
let(:cardinality_transform) { lambda{|x| x} }
|
77
|
-
context 'using first_of' do
|
78
|
-
let(:cardinality_transform) { lambda{|x| x.nil? ? [] : [x] } }
|
79
|
-
let(:query_method) { :first_of }
|
80
|
-
it_behaves_like 'a valid WMI query'
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'using instances_of' do
|
84
|
-
let(:query_method) { :instances_of }
|
85
|
-
it_behaves_like 'a valid WMI query'
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'using query' do
|
89
|
-
let(:wmi_query) { "select * from #{wmi_class}" }
|
90
|
-
let(:query_method) { :query }
|
91
|
-
it_behaves_like 'a valid WMI query'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'when making invalid queries' do
|
96
|
-
let(:namespace) { nil }
|
97
|
-
|
98
|
-
let(:wmi_query) { 'invalidclass' }
|
99
|
-
let(:query_method) { :first_of }
|
100
|
-
it_behaves_like 'an invalid query'
|
101
|
-
|
102
|
-
let(:query_method) { :instances_of }
|
103
|
-
it_behaves_like 'an invalid query'
|
104
|
-
|
105
|
-
let(:query_method) { :query }
|
106
|
-
let(:wmi_query) { 'nosql_4_life' }
|
107
|
-
it_behaves_like 'an invalid query'
|
108
|
-
end
|
109
|
-
|
110
|
-
let(:namespace) { nil }
|
111
|
-
describe 'when querying Win32_Environment' do
|
112
|
-
it 'should have the same environment variables as the Ruby ENV environment hash' do
|
113
|
-
results = wmi.instances_of('Win32_Environment')
|
114
|
-
|
115
|
-
variables = {}
|
116
|
-
|
117
|
-
# Skip some environment variables because we can't compare them against what's in ENV.
|
118
|
-
# Path, pathext, psmodulepath are special, they ares "merged" between the user and system value.
|
119
|
-
# PROCESSOR_ARCHITECTURE is actually the real processor arch of the system, so #{ENV['processor_architecture']} will
|
120
|
-
# report X86, while WMI will (correctly) report X64.
|
121
|
-
# And username is oddly the username of the WMI service, i.e. 'SYSTEM'.
|
122
|
-
ignore = {'path' => true, 'pathext' => true, 'processor_architecture' => true, 'psmodulepath' => true, 'username' => true}
|
123
|
-
results.each do | result |
|
124
|
-
if ! variables.has_key?(result['name']) || result['username'] != '<SYSTEM>'
|
125
|
-
variables[result['name']] = result['variablevalue']
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
verified_count = 0
|
130
|
-
variables.each_pair do | name, value |
|
131
|
-
if ignore[name.downcase] != true
|
132
|
-
|
133
|
-
# Turn %SYSTEMROOT% into c:\windows
|
134
|
-
# so we can compare with what's in ENV
|
135
|
-
evaluated_value = `echo #{value}`.strip
|
136
|
-
|
137
|
-
expect(evaluated_value).to eql(`echo #{ENV[name]}`.strip)
|
138
|
-
verified_count += 1
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# There are at least 3 variables we could verify in a default
|
143
|
-
# Windows configuration, make sure we saw some
|
144
|
-
expect(verified_count).to be >= 3
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
let(:namespace) { nil }
|
149
|
-
it 'should ignore case when retrieving WMI properties' do
|
150
|
-
result = wmi.first_of('Win32_ComputerSystem')
|
151
|
-
caption_mixed = result['Caption']
|
152
|
-
caption_lower = result['caption']
|
153
|
-
|
154
|
-
expect(caption_mixed.nil?).to eql(false)
|
155
|
-
expect(caption_lower.nil?).to eql(false)
|
156
|
-
|
157
|
-
expect(caption_mixed.length).to be > 0
|
158
|
-
expect(caption_lower.length).to be > 0
|
159
|
-
expect(caption_mixed).to eql(caption_lower)
|
160
|
-
end
|
161
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# $:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
require 'rspec'
|
3
|
-
require 'wmi-lite'
|
4
|
-
|
5
|
-
RSpec.configure do |config|
|
6
|
-
config.include(RSpec::Matchers)
|
7
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
-
config.filter_run :focus => true
|
9
|
-
config.filter_run_excluding :windows_only => true if ! (RUBY_PLATFORM =~ /mswin|mingw32|windows/)
|
10
|
-
config.run_all_when_everything_filtered = true
|
11
|
-
end
|
12
|
-
|
data/spec/unit/wmi_spec.rb
DELETED
@@ -1,295 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Edwards (<adamed@getchef.com>)
|
3
|
-
#
|
4
|
-
# Copyright:: 2014, Chef Software, Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'spec_helper'
|
20
|
-
|
21
|
-
describe WmiLite::Wmi do
|
22
|
-
|
23
|
-
let(:wbem_locator) { double 'WIN32OLE', :ConnectServer => wbem_connection }
|
24
|
-
let(:wmi_query_instance1) { double 'Wmi::Instance', :wmi_ole_object => native_query_instance1, :[] => native_properties1 }
|
25
|
-
let(:wmi_query_instance2) { double 'Wmi::Instance', :wmi_ole_object => native_query_instance2, :[] => native_properties2 }
|
26
|
-
let(:wmi_query_result1) { [ wmi_query_instance1 ].to_enum }
|
27
|
-
let(:wmi_query_result2) { [ wmi_query_instance1, wmi_query_instance2 ].to_enum }
|
28
|
-
let(:native_query_result1) { [ native_query_instance1 ].to_enum }
|
29
|
-
let(:native_query_result2) { [ native_query_instance1, native_query_instance2 ].to_enum }
|
30
|
-
let(:wmi_query_result_empty) { [].to_enum }
|
31
|
-
let(:native_properties1) { wmi_properties1.map { | property, value | double 'WIN32OLE', :name => property } }
|
32
|
-
let(:native_properties2) { wmi_properties2.map { | property, value | double 'WIN32OLE', :name => property } }
|
33
|
-
let(:native_query_instance1) { double 'WIN32OLE', :properties_ => native_properties1, :invoke => 'value1' }
|
34
|
-
let(:native_query_instance2) { double 'WIN32OLE', :properties_ => native_properties2, :invoke => 'value2' }
|
35
|
-
let(:wbem_connection) { double 'WIN32OLE', :ExecQuery => native_query_result }
|
36
|
-
|
37
|
-
def validate_query_result(actual, expected)
|
38
|
-
expect(actual.count).to eql(expected.count)
|
39
|
-
|
40
|
-
index = 0
|
41
|
-
|
42
|
-
expected.each do | expected_value |
|
43
|
-
actual_value = actual[index]
|
44
|
-
expected_value.wmi_ole_object.invoke == actual_value.wmi_ole_object.invoke
|
45
|
-
expected_value.wmi_ole_object.properties_.each do | expected_property |
|
46
|
-
|
47
|
-
expect(actual_value[expected_property.name]).not_to eql(nil)
|
48
|
-
|
49
|
-
names = actual_value.wmi_ole_object.properties_.map { | property | property.name }
|
50
|
-
|
51
|
-
expect(names.include?(expected_property.name)).to eql(true)
|
52
|
-
|
53
|
-
end
|
54
|
-
index += 1
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
before(:each) do
|
59
|
-
stub_const('WIN32OLE', Class.new)
|
60
|
-
WIN32OLE.stub(:new).with("WbemScripting.SWbemLocator").and_return(wbem_locator)
|
61
|
-
stub_const('WIN32OLERuntimeError', Class.new(Exception))
|
62
|
-
end
|
63
|
-
|
64
|
-
let(:wmi) { WmiLite::Wmi.new }
|
65
|
-
let(:wmi_query_result) { wmi_query_result_empty }
|
66
|
-
let(:native_query_result) { [].to_enum }
|
67
|
-
|
68
|
-
it "should not fail with empty query results" do
|
69
|
-
results = wmi.query('')
|
70
|
-
result_count = 0
|
71
|
-
results.each { | result | result_count += 1 }
|
72
|
-
|
73
|
-
expect( result_count ).to eq(0)
|
74
|
-
end
|
75
|
-
|
76
|
-
shared_examples_for "the first_of method" do
|
77
|
-
|
78
|
-
let(:wmi_properties1) { { 'cores' => 4, 'name' => 'mycomputer1', 'diskspace' => 400, 'os' => 'windows' } }
|
79
|
-
let(:wmi_properties2) { { 'cores' => 2, 'name' => 'mycomputer2', 'bios' => 'ami', 'os' => 'windows' } }
|
80
|
-
let(:native_query_result) { [].to_enum }
|
81
|
-
|
82
|
-
it "should not fail with empty query results" do
|
83
|
-
results = wmi.first_of('vm')
|
84
|
-
expect( results ).to eq(nil)
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when returning one instance in the query" do
|
88
|
-
let(:wmi_query_result) { wmi_query_result1 }
|
89
|
-
let(:native_query_result) { native_query_result1 }
|
90
|
-
|
91
|
-
it "should get one instance" do
|
92
|
-
results = wmi.first_of('vm')
|
93
|
-
expected_result = WmiLite::Wmi::Instance.new(native_query_result.first)
|
94
|
-
validate_query_result([results], [expected_result])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "when returning more than one instance in the query" do
|
99
|
-
let(:wmi_query_result) { wmi_query_result2 }
|
100
|
-
let(:native_query_result) { native_query_result2 }
|
101
|
-
|
102
|
-
it "should get one instance" do
|
103
|
-
results = wmi.first_of('vm')
|
104
|
-
expected_result = WmiLite::Wmi::Instance.new(native_query_result.first)
|
105
|
-
validate_query_result([results], [expected_result])
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
shared_examples_for "the instances_of method" do
|
112
|
-
|
113
|
-
let(:wmi_properties1) { { 'cores' => 4, 'name' => 'mycomputer1', 'diskspace' => 400, 'os' => 'windows' } }
|
114
|
-
let(:wmi_properties2) { { 'cores' => 2, 'name' => 'mycomputer2', 'bios' => 'ami', 'os' => 'windows' } }
|
115
|
-
let(:native_query_result) { [].to_enum }
|
116
|
-
|
117
|
-
it "should not fail with empty query results" do
|
118
|
-
results = wmi.instances_of('vm')
|
119
|
-
expect( results ).to eq([])
|
120
|
-
end
|
121
|
-
|
122
|
-
context "when returning one instance in the query" do
|
123
|
-
let(:wmi_query_result) { wmi_query_result1 }
|
124
|
-
let(:native_query_result) { native_query_result1 }
|
125
|
-
|
126
|
-
it "should get one instance" do
|
127
|
-
results = wmi.instances_of('vm')
|
128
|
-
index = 0
|
129
|
-
expected_result = results.map do | result |
|
130
|
-
WmiLite::Wmi::Instance.new(result.wmi_ole_object)
|
131
|
-
end
|
132
|
-
validate_query_result(results, expected_result)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when returning one instance in the query" do
|
137
|
-
let(:wmi_query_result) { wmi_query_result2 }
|
138
|
-
let(:native_query_result) { native_query_result2 }
|
139
|
-
|
140
|
-
it "should get one instance" do
|
141
|
-
results = wmi.instances_of('vm')
|
142
|
-
index = 0
|
143
|
-
expected_result = results.map do | result |
|
144
|
-
WmiLite::Wmi::Instance.new(result.wmi_ole_object)
|
145
|
-
end
|
146
|
-
validate_query_result(results, expected_result)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
shared_examples_for 'an invalid query' do
|
153
|
-
let(:unparseable_error) { 'unparseableerror' }
|
154
|
-
it 'should raise an exception' do
|
155
|
-
wbem_connection.should_receive(:ExecQuery).and_raise(WIN32OLERuntimeError)
|
156
|
-
wmi_service = WmiLite::Wmi.new
|
157
|
-
expect { wmi_service.send(query_method, wmi_query) }.to raise_error(WmiLite::WmiException)
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should raise an exception that ends with the original exception message' do
|
161
|
-
wbem_connection.should_receive(:ExecQuery).and_raise(WIN32OLERuntimeError.new(unparseable_error))
|
162
|
-
wmi_service = WmiLite::Wmi.new
|
163
|
-
error_message = nil
|
164
|
-
begin
|
165
|
-
wmi_service.send(query_method, wmi_query)
|
166
|
-
rescue WmiLite::WmiException => e
|
167
|
-
error_message = e.message
|
168
|
-
end
|
169
|
-
|
170
|
-
# Exception messages look a like a customized error string followed by
|
171
|
-
# the original, less friendly message. A change here affects only
|
172
|
-
# aestethics of human diagnostics, this may be changed with no effect
|
173
|
-
# on libraries or applications.
|
174
|
-
expect(error_message).not_to eql(nil)
|
175
|
-
expect(e.message.start_with?(unparseable_error)).to eql(false)
|
176
|
-
expect(e.message.end_with?(unparseable_error)).to eql(true)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
shared_examples_for 'an invalid namespace' do
|
181
|
-
let(:unparseable_error) { 'unparseableerror' }
|
182
|
-
it 'should raise an exception' do
|
183
|
-
wbem_locator.should_receive(:ConnectServer).and_raise(WIN32OLERuntimeError)
|
184
|
-
wmi_service = WmiLite::Wmi.new('notavalidnamespace')
|
185
|
-
expect { wmi_service.send(query_method, wmi_query) }.to raise_error(WmiLite::WmiException)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should raise an exception that starts with the original exception message' do
|
189
|
-
wbem_locator.should_receive(:ConnectServer).and_raise(WIN32OLERuntimeError.new(unparseable_error))
|
190
|
-
wmi_service = WmiLite::Wmi.new
|
191
|
-
error_message = nil
|
192
|
-
begin
|
193
|
-
wmi_service.send(query_method, wmi_query)
|
194
|
-
rescue WmiLite::WmiException => e
|
195
|
-
error_message = e.message
|
196
|
-
end
|
197
|
-
|
198
|
-
# See previous comment on this validation of human readability -- a change
|
199
|
-
# to the format / content of these messages will not break applications.
|
200
|
-
expect(error_message).not_to eql(nil)
|
201
|
-
expect(error_message.start_with?(unparseable_error)).to eql(false)
|
202
|
-
expect(error_message.end_with?(unparseable_error)).to eql(true)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
shared_examples_for "the query method" do
|
207
|
-
|
208
|
-
let(:wmi_properties1) { { 'cores' => 4, 'name' => 'mycomputer1', 'diskspace' => 400, 'os' => 'windows' } }
|
209
|
-
let(:wmi_properties2) { { 'cores' => 2, 'name' => 'mycomputer2', 'bios' => 'ami', 'os' => 'windows' } }
|
210
|
-
let(:native_query_result) { [].to_enum }
|
211
|
-
|
212
|
-
it "should not fail with empty query results" do
|
213
|
-
results = wmi.query('vm')
|
214
|
-
expect( results ).to eq([])
|
215
|
-
end
|
216
|
-
|
217
|
-
context "when returning one instance in the query" do
|
218
|
-
let(:wmi_query_result) { wmi_query_result1 }
|
219
|
-
let(:native_query_result) { native_query_result1 }
|
220
|
-
|
221
|
-
it "should get one instance" do
|
222
|
-
results = wmi.query('vm')
|
223
|
-
index = 0
|
224
|
-
expected_result = results.map do | result |
|
225
|
-
WmiLite::Wmi::Instance.new(result.wmi_ole_object)
|
226
|
-
end
|
227
|
-
validate_query_result(results, expected_result)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "when returning one instance in the query" do
|
232
|
-
let(:wmi_query_result) { wmi_query_result2 }
|
233
|
-
let(:native_query_result) { native_query_result2 }
|
234
|
-
|
235
|
-
it "should get one instance" do
|
236
|
-
results = wmi.query('vm')
|
237
|
-
index = 0
|
238
|
-
expected_result = results.map do | result |
|
239
|
-
WmiLite::Wmi::Instance.new(result.wmi_ole_object)
|
240
|
-
end
|
241
|
-
validate_query_result(results, expected_result)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
context "when constructing a Ruby class instance" do
|
248
|
-
it "should not connect to WMI in the constructor" do
|
249
|
-
WmiLite::Wmi.any_instance.should_not_receive(:connect_to_namespace)
|
250
|
-
wmi_service_nil_namespace = WmiLite::Wmi.new
|
251
|
-
wmi_service_explicit_namespace = WmiLite::Wmi.new('root/cimv2')
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
context "when calling query methods" do
|
256
|
-
it "should only connect to WMI on the first query execution" do
|
257
|
-
WIN32OLE.should_receive(:new).with("WbemScripting.SWbemLocator").exactly(1).times.and_return(wbem_locator)
|
258
|
-
wmi_service = WmiLite::Wmi.new
|
259
|
-
|
260
|
-
# Make a lot of queries to be sure the connection is only created once
|
261
|
-
wmi_service.query('select * from Win32_Process')
|
262
|
-
wmi_service.query('select * from Win32_Process')
|
263
|
-
wmi_service.instances_of('Win32_Processor')
|
264
|
-
wmi_service.instances_of('Win32_Processor')
|
265
|
-
wmi_service.first_of('Win32_Group')
|
266
|
-
wmi_service.first_of('Win32_Group')
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'when making invalid queries' do
|
271
|
-
let(:namespace) { nil }
|
272
|
-
|
273
|
-
let(:wmi_query) { 'invalidclass' }
|
274
|
-
let(:query_method) { :first_of }
|
275
|
-
|
276
|
-
it_behaves_like 'an invalid query'
|
277
|
-
it_behaves_like 'an invalid namespace'
|
278
|
-
|
279
|
-
let(:query_method) { :instances_of }
|
280
|
-
it_behaves_like 'an invalid query'
|
281
|
-
it_behaves_like 'an invalid namespace'
|
282
|
-
|
283
|
-
let(:query_method) { :query }
|
284
|
-
let(:wmi_query) { 'nosql_4_life' }
|
285
|
-
it_behaves_like 'an invalid query'
|
286
|
-
it_behaves_like 'an invalid namespace'
|
287
|
-
end
|
288
|
-
|
289
|
-
it_should_behave_like "the first_of method"
|
290
|
-
|
291
|
-
it_should_behave_like "the instances_of method"
|
292
|
-
|
293
|
-
it_should_behave_like "the query method"
|
294
|
-
|
295
|
-
end
|
data/wmi-lite.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'wmi-lite/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'wmi-lite'
|
8
|
-
spec.version = WmiLite::VERSION
|
9
|
-
spec.authors = ['Adam Edwards']
|
10
|
-
spec.email = ['dev@getchef.com']
|
11
|
-
spec.description = 'A lightweight utility over win32ole for accessing basic ' \
|
12
|
-
'WMI (Windows Management Instrumentation) functionality ' \
|
13
|
-
'in the Microsoft Windows operating system. It has no ' \
|
14
|
-
'runtime dependencies other than Ruby, so it can be used ' \
|
15
|
-
'without concerns around dependency issues.'
|
16
|
-
spec.summary = 'A lightweight utility library for accessing basic WMI ' \
|
17
|
-
'(Windows Management Instrumentation) functionality on Windows'
|
18
|
-
spec.homepage = 'https://github.com/opscode/wmi-lite'
|
19
|
-
spec.license = 'Apache 2.0'
|
20
|
-
|
21
|
-
spec.files = `git ls-files`.split($/)
|
22
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
-
spec.require_paths = ['lib']
|
25
|
-
|
26
|
-
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
-
spec.add_development_dependency 'rspec'
|
28
|
-
spec.add_development_dependency 'rake'
|
29
|
-
spec.add_development_dependency 'pry'
|
30
|
-
spec.add_development_dependency 'pry-debugger'
|
31
|
-
end
|