knife-partial-search 0.0.1 → 0.0.2

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: fbf495000ed0411a315071d3cf33e502c6a21683
4
- data.tar.gz: 6cecc9edfae5dfa76bb5366731d780a02c8b7de3
3
+ metadata.gz: d0140db7060838ec89c3434595f4ac4e774966d2
4
+ data.tar.gz: 546c379a20b3bcd01d4050b1576f92600a723a55
5
5
  SHA512:
6
- metadata.gz: 3705d9db8584020d30d0c95fc1011f8cecd75a1d36659a3623eae45c1c6943ad62be40bd1b9bc67f4c17a55062fceee145e4b986f496b4737cd5266ee0b01e8e
7
- data.tar.gz: 5120a07a77c623c4f2ff0f07bdd9dc500b42f5afebb4ba7d196c6f150476c6cba6e06b725da2d0123d1e286ec3f6bc420d354873623bde48666fb002af7f9bc6
6
+ metadata.gz: dd85f2bb33952214317b4755a8fd8a6ca6c80df6cd47886b66e37bd2d5b1f2cc8f7eda4f64d5f4f0c038ede08063ff43f09068d1c28cd32c906774e1bbb00ddc
7
+ data.tar.gz: 6b3ab64123301b6426ac2a0367440f8f2cfb5372942390dbe279dac97301d7ab5a3eaf026b589b70b30f885012d9b3a61dc65f6c923485d81cb5ca150291f594
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Gregoire Seux"]
10
10
  spec.email = ["g.seux@criteo.com"]
11
11
  spec.summary = "Improve usual knife commands thanks to partial-search"
12
- spec.homepage = "https://gitlab.criteois.lan/ruby-gems/knife-partial-search"
12
+ spec.homepage = "https://github.com/criteo/knife-partial-search"
13
13
  spec.license = "Apache 2.0"
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
@@ -1,3 +1,5 @@
1
+ require_relative 'partial_search/fake_node.rb'
1
2
  require_relative 'partial_search/partial_search.rb'
2
3
  require_relative 'partial_search/fast_status.rb'
3
4
  require_relative 'partial_search/fast_ssh.rb'
5
+ require_relative 'partial_search/fast_search.rb'
@@ -0,0 +1,29 @@
1
+ class Chef
2
+ class Knife
3
+ class PartialSearch
4
+ class FakeNode < Hash
5
+ def name
6
+ self['name']
7
+ end
8
+ def chef_environment
9
+ self['chef_environment']
10
+ end
11
+ def run_list
12
+ self['run_list'].join(', ')
13
+ end
14
+
15
+ def [](key)
16
+ super(key.to_s)
17
+ end
18
+
19
+ def kind_of?(klass)
20
+ if klass.to_s == 'Chef::Node'
21
+ true
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ class Chef
2
+ class Knife
3
+ class Search
4
+
5
+ include Chef::Knife::PartialSearch
6
+
7
+ deps do
8
+ begin
9
+ require 'partial_search'
10
+ rescue LoadError => e
11
+ end
12
+ end
13
+
14
+ alias_method :classic_run, :run unless method_defined? :classic_run
15
+
16
+ def run
17
+ if defined?(Chef::PartialSearch)
18
+ keys = {}
19
+ if config[:attribute]
20
+ keys['name'] = ['name']
21
+ Array(config[:attribute]).each do |nested_value_spec|
22
+ keys[nested_value_spec] = nested_value_spec.split('.')
23
+ end
24
+ define_partial_search(keys)
25
+ else
26
+ define_partial_search({
27
+ 'name' => ['name'],
28
+ 'chef_environment' => ['chef_environment'],
29
+ 'fqdn' => ['fqdn'],
30
+ 'ipaddress' => ['ipaddress'],
31
+ 'run_list' => ['run_list'],
32
+ 'roles' => ['roles'],
33
+ 'recipes' => ['recipes'],
34
+ 'platform' => ['platform'],
35
+ 'tags' => ['tags'],
36
+ 'platform_version' => ['platform_version'],
37
+ })
38
+ end
39
+ end
40
+ classic_run
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
@@ -8,12 +8,20 @@ class Chef
8
8
 
9
9
  alias_method :old_search, :search unless method_defined? :old_search
10
10
 
11
- def search(type, query, args={}, &block)
11
+ def search(type, query="*:*", sort='X_CHEF_id_CHEF_X asc', start=0, rows=1000, &block)
12
12
  q = Chef::PartialSearch.new
13
+ args = Hash.new
13
14
  args[:keys] = @@keys
15
+ args[:sort] = sort
16
+ args[:start] = start
17
+ args[:rows] = rows
14
18
  if block_given?
15
19
  q.search(type, query, args) do |node_hash|
16
- n = FakeNode.new do |h,k| node_hash[k] end
20
+ n = Chef::Knife::PartialSearch::FakeNode.new do |h,k|
21
+ h[k] = node_hash[k]
22
+ end
23
+ @@keys.each do |k,v| n[k] end
24
+
17
25
  block.call(n)
18
26
  end
19
27
  else
@@ -26,3 +34,22 @@ class Chef
26
34
  end
27
35
  end
28
36
  end
37
+
38
+ class Chef
39
+ class Knife
40
+ module Core
41
+ class GenericPresenter
42
+
43
+ alias_method :old_extract, :extract_nested_value unless method_defined? :old_extract
44
+
45
+ def extract_nested_value(data, nested_value_spec)
46
+ if data.kind_of?(Chef::Knife::PartialSearch::FakeNode)
47
+ data[nested_value_spec]
48
+ else
49
+ old_extract(data, nested_value_spec)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module PartialSearch
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-partial-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -80,11 +80,13 @@ files:
80
80
  - Rakefile
81
81
  - knife-partial-search.gemspec
82
82
  - lib/chef/knife/partial_search.rb
83
+ - lib/chef/knife/partial_search/fake_node.rb
84
+ - lib/chef/knife/partial_search/fast_search.rb
83
85
  - lib/chef/knife/partial_search/fast_ssh.rb
84
86
  - lib/chef/knife/partial_search/fast_status.rb
85
87
  - lib/chef/knife/partial_search/partial_search.rb
86
88
  - lib/chef/knife/version.rb
87
- homepage: https://gitlab.criteois.lan/ruby-gems/knife-partial-search
89
+ homepage: https://github.com/criteo/knife-partial-search
88
90
  licenses:
89
91
  - Apache 2.0
90
92
  metadata: {}
@@ -109,3 +111,4 @@ signing_key:
109
111
  specification_version: 4
110
112
  summary: Improve usual knife commands thanks to partial-search
111
113
  test_files: []
114
+ has_rdoc: