knife-api 0.1.6 → 0.1.7

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: 2e2058634a5ec5f5e48fbb926e2ce9a4d40bdee4
4
- data.tar.gz: 8a2b599294f9ed0f1b1bed7edc6d6b0569a01869
3
+ metadata.gz: 133c78523dfdc03c78812813cfe4e3b8bc3afb46
4
+ data.tar.gz: b345e8e05f3589958a8527ac744cb99c04e220df
5
5
  SHA512:
6
- metadata.gz: 0d092f430d8ce506b3306c00adf13e5257cce08b03b219488960b84ec2efaaeae8665ec18faf30ea7e6541a71a8b1c6184a91d22606dea183808d91947545541
7
- data.tar.gz: 68343cbd5ec83ade5b4c70141ce6ac41543a8d855a31ee15736804954b999ac81f2775151dc95d24137a605e42692e9dac1e2a18c52a55217afba4d449826d4b
6
+ metadata.gz: d2a1c44ffe320c70f148c2a52d691a04616bbf0eaae07366ea97b53bf9315cd33138c10a45ca8528747439f15502bb0b8692b920ea97a41c7ad04931b62b91c9
7
+ data.tar.gz: 95bd4bf5c30a8f1657bcefa87fce41bba4c6b65639491bead4bcacc6e080f005ea90033a9b71f90615d897d70c76294aeedc115be12f42da119b7e9ee38b03bc
@@ -3,4 +3,10 @@ Change Log
3
3
 
4
4
  2015-02-26
5
5
  added a CodeShip badge to the README.md file
6
- added a CHANGELOG.md file to better document project changes
6
+ added a CHANGELOG.md file to better document project changes
7
+
8
+ 2016-01-15
9
+ found that both Ruby Mine and Atom tricked out with linter, linter-ruby,
10
+ linter-rubocop, linter-foodcritic were unhappy with the Ruby code as it was
11
+ so I cleaned it up, primarily by refactoring the knife_capture method
12
+
data/Rakefile CHANGED
@@ -1 +1,17 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ require 'knife/api'
4
+ require 'pp'
5
+ require 'json'
6
+
7
+ task :list_nodes do
8
+ status = knife :node_list
9
+ puts "status is #{status}"
10
+ fail if status > 0
11
+ end
12
+
13
+ task :show_node, :node_name do |task_name, args|
14
+ stdout, stderr, status = knife_capture :node_show, [args[:node_name], '-F', 'j']
15
+ fail if status > 0
16
+ pp JSON.load(stdout)
17
+ end
@@ -17,10 +17,11 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency 'chef', '>= 10.32', '< 13.0.0'
20
+ gem.add_dependency 'chef', '>= 10.32', '<= 12.6.0'
21
21
  gem.add_dependency 'chef-zero', '>= 2.2.1'
22
22
  gem.add_dependency 'ohai', '> 7.0.0', '< 9.0.0'
23
23
  gem.add_dependency 'json', '>= 1.8.2'
24
24
 
25
25
  gem.add_development_dependency 'rake', '>= 10.4.2'
26
+ gem.add_development_dependency 'codeclimate-test-reporter', '>= 0.4.8' # , group: :test, require: nil
26
27
  end
@@ -2,6 +2,8 @@ require 'chef/application/knife'
2
2
  require 'knife/api/version'
3
3
  require 'stringio'
4
4
 
5
+ # Chef::Knife classes are opened to expose the Knife entry points to code
6
+ # via the injected API module
5
7
  class Chef
6
8
  class Knife
7
9
  # adding API module to existing Chef::Knife packaging
@@ -9,21 +11,17 @@ class Chef
9
11
  # adding Support module
10
12
  module Support
11
13
  def self.run_knife(command, args)
12
- unless command.is_a?(Array)
13
- command = command.to_s.split(/[\s_]+/)
14
- end
15
-
14
+ command = command.to_s.split(/[\s_]+/) unless command.is_a?(Array)
16
15
  command += args
17
-
18
- if ENV['CHEF_CONFIG']
19
- command += ['-c', ENV['CHEF_CONFIG']]
20
- end
16
+ command += ['-c', ENV['CHEF_CONFIG']] if ENV['CHEF_CONFIG']
21
17
 
22
18
  opts = Chef::Application::Knife.new.options
23
19
  Chef::Knife.run(command, opts)
24
- return 0
20
+ # believe this to be a problem -- if knife command would otherwise
21
+ # indicate a chef error this creates a false positive
22
+ 0
25
23
  rescue SystemExit => e
26
- return e.status
24
+ abort("Chef run failed with status " + e.status.to_s)
27
25
  end
28
26
  end
29
27
 
@@ -32,33 +30,52 @@ class Chef
32
30
  end
33
31
 
34
32
  def knife_capture(command, args = [], input = nil)
35
- null = Gem.win_platform? ? File.open('NUL:', 'r') : File.open('/dev/null', 'r')
36
-
37
- warn = $VERBOSE
38
- $VERBOSE = nil
39
- stderr, stdout, stdin = STDERR, STDOUT, STDIN
33
+ @input = input
34
+ set_null
40
35
 
41
- Object.const_set('STDERR', StringIO.new('', 'r+'))
42
- Object.const_set('STDOUT', StringIO.new('', 'r+'))
43
- Object.const_set('STDIN', input ? StringIO.new(input, 'r') : null)
44
- $VERBOSE = warn
36
+ assign_io_channels
45
37
 
46
38
  status = Chef::Knife::API::Support.run_knife(command, args)
47
39
  return STDOUT.string, STDERR.string, status
48
40
  ensure
49
- warn = $VERBOSE
50
- $VERBOSE = nil
51
- Object.const_set('STDERR', stderr)
52
- Object.const_set('STDOUT', stdout)
53
- Object.const_set('STDIN', stdin)
54
- $VERBOSE = warn
55
- null.close
41
+ revert_io_channels
56
42
  end
57
43
  end
58
44
  end
45
+
46
+ def set_null
47
+ if Gem.win_platform? == null
48
+ File.open('NUL:', 'r')
49
+ else
50
+ File.open('/dev/null', 'r')
51
+ end
52
+ end
53
+
54
+ def assign_io_channels
55
+ @warn = $VERBOSE
56
+ $VERBOSE = nil
57
+ @stderr = STDERR
58
+ @stdout = STDOUT
59
+ @stdin = STDIN
60
+
61
+ Object.const_set('STDERR', StringIO.new('', 'r+'))
62
+ Object.const_set('STDOUT', StringIO.new('', 'r+'))
63
+ Object.const_set('STDIN', @input ? StringIO.new(@input, 'r') : null)
64
+ $VERBOSE = @warn
65
+ end
66
+
67
+ def revert_io_channels
68
+ @warn = $VERBOSE
69
+ $VERBOSE = nil
70
+ Object.const_set('STDERR', @stderr)
71
+ Object.const_set('STDOUT', @stdout)
72
+ Object.const_set('STDIN', @stdin)
73
+ $VERBOSE = @warn
74
+ null.close
75
+ end
59
76
  end
60
77
 
61
- class << eval("self", TOPLEVEL_BINDING)
78
+ class << eval('self', TOPLEVEL_BINDING)
62
79
  include Chef::Knife::API
63
80
  end
64
81
 
@@ -2,7 +2,7 @@ class Chef
2
2
  class Knife
3
3
  # adding API module to existing Chef::Knife packaging
4
4
  module API
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.7'
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Hollensbe
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-05-08 00:00:00.000000000 Z
13
+ date: 2016-06-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chef
@@ -19,9 +19,9 @@ dependencies:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '10.32'
22
- - - "<"
22
+ - - "<="
23
23
  - !ruby/object:Gem::Version
24
- version: 13.0.0
24
+ version: 12.6.0
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,9 +29,9 @@ dependencies:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
31
  version: '10.32'
32
- - - "<"
32
+ - - "<="
33
33
  - !ruby/object:Gem::Version
34
- version: 13.0.0
34
+ version: 12.6.0
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: chef-zero
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 10.4.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.4.8
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.8
97
111
  description: A small library that lets you drive Chef's 'knife' programmatically
98
112
  email:
99
113
  - andyglick@gmailcom
@@ -130,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
144
  version: '0'
131
145
  requirements: []
132
146
  rubyforge_project:
133
- rubygems_version: 2.4.4
147
+ rubygems_version: 2.5.2
134
148
  signing_key:
135
149
  specification_version: 4
136
150
  summary: A small library that lets you drive Chef's 'knife' programmatically