ridley 0.10.2 → 0.11.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/README.md +147 -216
  2. data/lib/ridley.rb +2 -0
  3. data/lib/ridley/bootstrap_bindings/unix_template_binding.rb +21 -25
  4. data/lib/ridley/bootstrap_bindings/windows_template_binding.rb +29 -34
  5. data/lib/ridley/bootstrapper.rb +2 -2
  6. data/lib/ridley/bootstrapper/context.rb +5 -5
  7. data/lib/ridley/chef.rb +0 -1
  8. data/lib/ridley/chef/cookbook.rb +0 -9
  9. data/lib/ridley/chef_object.rb +128 -0
  10. data/lib/ridley/chef_objects.rb +3 -0
  11. data/lib/ridley/chef_objects/client_object.rb +55 -0
  12. data/lib/ridley/chef_objects/cookbook_object.rb +190 -0
  13. data/lib/ridley/chef_objects/data_bag_item_obect.rb +104 -0
  14. data/lib/ridley/chef_objects/data_bag_object.rb +31 -0
  15. data/lib/ridley/chef_objects/environment_object.rb +59 -0
  16. data/lib/ridley/chef_objects/node_object.rb +161 -0
  17. data/lib/ridley/chef_objects/role_object.rb +62 -0
  18. data/lib/ridley/chef_objects/sandbox_object.rb +58 -0
  19. data/lib/ridley/client.rb +76 -45
  20. data/lib/ridley/connection.rb +1 -1
  21. data/lib/ridley/errors.rb +8 -1
  22. data/lib/ridley/host_connector.rb +26 -6
  23. data/lib/ridley/host_connector/ssh.rb +3 -3
  24. data/lib/ridley/host_connector/ssh/worker.rb +7 -9
  25. data/lib/ridley/host_connector/winrm/worker.rb +4 -5
  26. data/lib/ridley/mixin/bootstrap_binding.rb +1 -12
  27. data/lib/ridley/resource.rb +51 -171
  28. data/lib/ridley/resources/client_resource.rb +18 -68
  29. data/lib/ridley/resources/cookbook_resource.rb +181 -381
  30. data/lib/ridley/resources/data_bag_item_resource.rb +55 -161
  31. data/lib/ridley/resources/data_bag_resource.rb +20 -61
  32. data/lib/ridley/resources/environment_resource.rb +9 -64
  33. data/lib/ridley/resources/node_resource.rb +135 -311
  34. data/lib/ridley/resources/role_resource.rb +1 -57
  35. data/lib/ridley/resources/sandbox_resource.rb +80 -65
  36. data/lib/ridley/resources/search_resource.rb +99 -0
  37. data/lib/ridley/sandbox_uploader.rb +12 -52
  38. data/lib/ridley/version.rb +1 -1
  39. data/spec/acceptance/bootstrapping_spec.rb +1 -1
  40. data/spec/acceptance/client_resource_spec.rb +15 -37
  41. data/spec/acceptance/data_bag_item_resource_spec.rb +8 -14
  42. data/spec/acceptance/data_bag_resource_spec.rb +1 -1
  43. data/spec/acceptance/environment_resource_spec.rb +13 -22
  44. data/spec/acceptance/node_resource_spec.rb +10 -29
  45. data/spec/acceptance/role_resource_spec.rb +14 -13
  46. data/spec/acceptance/sandbox_resource_spec.rb +2 -2
  47. data/spec/support/shared_examples/ridley_resource.rb +2 -23
  48. data/spec/unit/ridley/bootstrap_bindings/unix_template_binding_spec.rb +3 -4
  49. data/spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb +3 -5
  50. data/spec/unit/ridley/bootstrapper/context_spec.rb +2 -3
  51. data/spec/unit/ridley/bootstrapper_spec.rb +1 -1
  52. data/spec/unit/ridley/chef_object_spec.rb +240 -0
  53. data/spec/unit/ridley/chef_objects/client_object_spec.rb +11 -0
  54. data/spec/unit/ridley/chef_objects/cookbook_object_spec.rb +93 -0
  55. data/spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb +74 -0
  56. data/spec/unit/ridley/chef_objects/data_bag_object_spec.rb +9 -0
  57. data/spec/unit/ridley/chef_objects/environment_object_spec.rb +57 -0
  58. data/spec/unit/ridley/chef_objects/node_object_spec.rb +252 -0
  59. data/spec/unit/ridley/chef_objects/role_object_spec.rb +57 -0
  60. data/spec/unit/ridley/chef_objects/sandbox_object_spec.rb +66 -0
  61. data/spec/unit/ridley/client_spec.rb +51 -51
  62. data/spec/unit/ridley/host_connector/ssh/worker_spec.rb +4 -4
  63. data/spec/unit/ridley/host_connector/ssh_spec.rb +26 -24
  64. data/spec/unit/ridley/host_connector/winrm/worker_spec.rb +3 -4
  65. data/spec/unit/ridley/host_connector/winrm_spec.rb +4 -4
  66. data/spec/unit/ridley/host_connector_spec.rb +40 -3
  67. data/spec/unit/ridley/mixin/bootstrap_binding_spec.rb +1 -1
  68. data/spec/unit/ridley/resource_spec.rb +81 -109
  69. data/spec/unit/ridley/resources/client_resource_spec.rb +18 -33
  70. data/spec/unit/ridley/resources/cookbook_resource_spec.rb +56 -230
  71. data/spec/unit/ridley/resources/data_bag_item_resource_spec.rb +2 -57
  72. data/spec/unit/ridley/resources/data_bag_resource_spec.rb +12 -7
  73. data/spec/unit/ridley/resources/environment_resource_spec.rb +10 -118
  74. data/spec/unit/ridley/resources/node_resource_spec.rb +83 -394
  75. data/spec/unit/ridley/resources/role_resource_spec.rb +2 -56
  76. data/spec/unit/ridley/resources/sandbox_resource_spec.rb +139 -136
  77. data/spec/unit/ridley/resources/search_resource_spec.rb +234 -0
  78. data/spec/unit/ridley/sandbox_uploader_spec.rb +13 -58
  79. metadata +36 -17
  80. data/lib/ridley/chef/chefignore.rb +0 -76
  81. data/lib/ridley/resources/encrypted_data_bag_item_resource.rb +0 -55
  82. data/lib/ridley/resources/search.rb +0 -101
  83. data/spec/fixtures/chefignore +0 -8
  84. data/spec/unit/ridley/chef/chefignore_spec.rb +0 -40
  85. data/spec/unit/ridley/resources/search_spec.rb +0 -221
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ridley::SandboxUploader do
4
- let(:connection) { double('chef-conn') }
5
- let(:client) do
6
- double('client',
7
- client_name: 'reset',
8
- client_key: fixtures_path.join('reset.pem'),
9
- options: {},
10
- connection: connection
4
+ let(:client_name) { "reset" }
5
+ let(:client_key) { fixtures_path.join('reset.pem') }
6
+ let(:connection) do
7
+ double('connection',
8
+ client_name: client_name,
9
+ client_key: client_key,
10
+ options: {}
11
11
  )
12
12
  end
13
-
13
+ let(:resource) { double('resource', connection: connection) }
14
14
  let(:checksums) do
15
15
  {
16
16
  "oGCPHrQ+5MylEL+V+NIJ9w==" => {
@@ -20,22 +20,10 @@ describe Ridley::SandboxUploader do
20
20
  }
21
21
  end
22
22
 
23
- let(:sandbox) do
24
- Ridley::SandboxResource.new(client, checksums: checksums)
25
- end
23
+ let(:sandbox) { Ridley::SandboxObject.new(resource, checksums: checksums) }
26
24
 
27
25
  describe "ClassMethods" do
28
26
  subject { described_class }
29
- describe "::upload" do
30
- it "terminates the uploader after upload" do
31
- uploader = double('uploader', alive?: true)
32
- Ridley::SandboxUploader.should_receive(:pool).with(size: 12, args: [sandbox]).and_return(uploader)
33
- uploader.should_receive(:multi_upload).with(checksums)
34
- uploader.should_receive(:terminate)
35
-
36
- subject.upload(sandbox, checksums)
37
- end
38
- end
39
27
 
40
28
  describe "::checksum" do
41
29
  subject { described_class.checksum(path) }
@@ -54,24 +42,12 @@ describe Ridley::SandboxUploader do
54
42
  end
55
43
  end
56
44
 
57
- subject { described_class.new(sandbox) }
58
-
59
- describe "#multi_upload" do
60
- it "sends an upload command for each pair of checksum/path" do
61
- subject.should_receive(:upload).with(checksums.first[0], checksums.first[1])
62
-
63
- subject.multi_upload(checksums)
64
- end
65
- end
45
+ subject { described_class.new(client_name, client_key, {}) }
66
46
 
67
47
  describe "#upload" do
68
48
  let(:chk_id) { "oGCPHrQ+5MylEL+V+NIJ9w==" }
69
49
  let(:path) { fixtures_path.join('reset.pem').to_s }
70
50
 
71
- before do
72
- connection.stub(foss?: false)
73
- end
74
-
75
51
  context "when the checksum needs uploading" do
76
52
  let(:checksums) do
77
53
  {
@@ -85,7 +61,7 @@ describe Ridley::SandboxUploader do
85
61
  it "uploads each checksum to their target URL" do
86
62
  stub_request(:put, checksums[chk_id][:url])
87
63
 
88
- subject.upload(chk_id, path)
64
+ subject.upload(sandbox, chk_id, path)
89
65
  end
90
66
  end
91
67
 
@@ -99,32 +75,11 @@ describe Ridley::SandboxUploader do
99
75
  end
100
76
 
101
77
  let(:sandbox) do
102
- Ridley::SandboxResource.new(client, checksums: checksums)
78
+ Ridley::SandboxObject.new(double, checksums: checksums)
103
79
  end
104
80
 
105
81
  it "returns nil" do
106
- subject.upload(chk_id, path).should be_nil
107
- end
108
- end
109
-
110
- context "when the connection is an open source server connection with a non-80 port" do
111
- before do
112
- connection.stub(foss?: true, server_url: "http://localhost:8889")
113
- end
114
-
115
- let(:checksums) do
116
- {
117
- chk_id => {
118
- url: "http://localhost/sandboxes/bd091b150b0a4578b97771af6abf3e05",
119
- needs_upload: true
120
- }
121
- }
122
- end
123
-
124
- it "does not strip the port from the target to upload to" do
125
- stub_request(:put, "http://localhost:8889/sandboxes/bd091b150b0a4578b97771af6abf3e05")
126
-
127
- subject.upload(chk_id, path)
82
+ subject.upload(sandbox, chk_id, path).should be_nil
128
83
  end
129
84
  end
130
85
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
5
- prerelease:
4
+ version: 0.11.0.rc1
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie Winsor
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -308,11 +308,20 @@ files:
308
308
  - lib/ridley/bootstrapper/context.rb
309
309
  - lib/ridley/chain_link.rb
310
310
  - lib/ridley/chef.rb
311
- - lib/ridley/chef/chefignore.rb
312
311
  - lib/ridley/chef/cookbook.rb
313
312
  - lib/ridley/chef/cookbook/metadata.rb
314
313
  - lib/ridley/chef/cookbook/syntax_check.rb
315
314
  - lib/ridley/chef/digester.rb
315
+ - lib/ridley/chef_object.rb
316
+ - lib/ridley/chef_objects.rb
317
+ - lib/ridley/chef_objects/client_object.rb
318
+ - lib/ridley/chef_objects/cookbook_object.rb
319
+ - lib/ridley/chef_objects/data_bag_item_obect.rb
320
+ - lib/ridley/chef_objects/data_bag_object.rb
321
+ - lib/ridley/chef_objects/environment_object.rb
322
+ - lib/ridley/chef_objects/node_object.rb
323
+ - lib/ridley/chef_objects/role_object.rb
324
+ - lib/ridley/chef_objects/sandbox_object.rb
316
325
  - lib/ridley/client.rb
317
326
  - lib/ridley/connection.rb
318
327
  - lib/ridley/errors.rb
@@ -342,12 +351,11 @@ files:
342
351
  - lib/ridley/resources/cookbook_resource.rb
343
352
  - lib/ridley/resources/data_bag_item_resource.rb
344
353
  - lib/ridley/resources/data_bag_resource.rb
345
- - lib/ridley/resources/encrypted_data_bag_item_resource.rb
346
354
  - lib/ridley/resources/environment_resource.rb
347
355
  - lib/ridley/resources/node_resource.rb
348
356
  - lib/ridley/resources/role_resource.rb
349
357
  - lib/ridley/resources/sandbox_resource.rb
350
- - lib/ridley/resources/search.rb
358
+ - lib/ridley/resources/search_resource.rb
351
359
  - lib/ridley/sandbox_uploader.rb
352
360
  - lib/ridley/version.rb
353
361
  - ridley.gemspec
@@ -360,7 +368,6 @@ files:
360
368
  - spec/acceptance/role_resource_spec.rb
361
369
  - spec/acceptance/sandbox_resource_spec.rb
362
370
  - spec/acceptance/search_resource_spec.rb
363
- - spec/fixtures/chefignore
364
371
  - spec/fixtures/encrypted_data_bag_secret
365
372
  - spec/fixtures/example_cookbook/README.md
366
373
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -386,9 +393,17 @@ files:
386
393
  - spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb
387
394
  - spec/unit/ridley/bootstrapper/context_spec.rb
388
395
  - spec/unit/ridley/bootstrapper_spec.rb
389
- - spec/unit/ridley/chef/chefignore_spec.rb
390
396
  - spec/unit/ridley/chef/cookbook_spec.rb
391
397
  - spec/unit/ridley/chef/digester_spec.rb
398
+ - spec/unit/ridley/chef_object_spec.rb
399
+ - spec/unit/ridley/chef_objects/client_object_spec.rb
400
+ - spec/unit/ridley/chef_objects/cookbook_object_spec.rb
401
+ - spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb
402
+ - spec/unit/ridley/chef_objects/data_bag_object_spec.rb
403
+ - spec/unit/ridley/chef_objects/environment_object_spec.rb
404
+ - spec/unit/ridley/chef_objects/node_object_spec.rb
405
+ - spec/unit/ridley/chef_objects/role_object_spec.rb
406
+ - spec/unit/ridley/chef_objects/sandbox_object_spec.rb
392
407
  - spec/unit/ridley/client_spec.rb
393
408
  - spec/unit/ridley/connection_spec.rb
394
409
  - spec/unit/ridley/errors_spec.rb
@@ -412,7 +427,7 @@ files:
412
427
  - spec/unit/ridley/resources/node_resource_spec.rb
413
428
  - spec/unit/ridley/resources/role_resource_spec.rb
414
429
  - spec/unit/ridley/resources/sandbox_resource_spec.rb
415
- - spec/unit/ridley/resources/search_spec.rb
430
+ - spec/unit/ridley/resources/search_resource_spec.rb
416
431
  - spec/unit/ridley/sandbox_uploader_spec.rb
417
432
  - spec/unit/ridley_spec.rb
418
433
  homepage: https://github.com/reset/ridley
@@ -431,12 +446,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
431
446
  required_rubygems_version: !ruby/object:Gem::Requirement
432
447
  none: false
433
448
  requirements:
434
- - - ! '>='
449
+ - - ! '>'
435
450
  - !ruby/object:Gem::Version
436
- version: '0'
437
- segments:
438
- - 0
439
- hash: -2279939140045068051
451
+ version: 1.3.1
440
452
  requirements: []
441
453
  rubyforge_project:
442
454
  rubygems_version: 1.8.23
@@ -453,7 +465,6 @@ test_files:
453
465
  - spec/acceptance/role_resource_spec.rb
454
466
  - spec/acceptance/sandbox_resource_spec.rb
455
467
  - spec/acceptance/search_resource_spec.rb
456
- - spec/fixtures/chefignore
457
468
  - spec/fixtures/encrypted_data_bag_secret
458
469
  - spec/fixtures/example_cookbook/README.md
459
470
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -479,9 +490,17 @@ test_files:
479
490
  - spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb
480
491
  - spec/unit/ridley/bootstrapper/context_spec.rb
481
492
  - spec/unit/ridley/bootstrapper_spec.rb
482
- - spec/unit/ridley/chef/chefignore_spec.rb
483
493
  - spec/unit/ridley/chef/cookbook_spec.rb
484
494
  - spec/unit/ridley/chef/digester_spec.rb
495
+ - spec/unit/ridley/chef_object_spec.rb
496
+ - spec/unit/ridley/chef_objects/client_object_spec.rb
497
+ - spec/unit/ridley/chef_objects/cookbook_object_spec.rb
498
+ - spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb
499
+ - spec/unit/ridley/chef_objects/data_bag_object_spec.rb
500
+ - spec/unit/ridley/chef_objects/environment_object_spec.rb
501
+ - spec/unit/ridley/chef_objects/node_object_spec.rb
502
+ - spec/unit/ridley/chef_objects/role_object_spec.rb
503
+ - spec/unit/ridley/chef_objects/sandbox_object_spec.rb
485
504
  - spec/unit/ridley/client_spec.rb
486
505
  - spec/unit/ridley/connection_spec.rb
487
506
  - spec/unit/ridley/errors_spec.rb
@@ -505,7 +524,7 @@ test_files:
505
524
  - spec/unit/ridley/resources/node_resource_spec.rb
506
525
  - spec/unit/ridley/resources/role_resource_spec.rb
507
526
  - spec/unit/ridley/resources/sandbox_resource_spec.rb
508
- - spec/unit/ridley/resources/search_spec.rb
527
+ - spec/unit/ridley/resources/search_resource_spec.rb
509
528
  - spec/unit/ridley/sandbox_uploader_spec.rb
510
529
  - spec/unit/ridley_spec.rb
511
530
  has_rdoc:
@@ -1,76 +0,0 @@
1
- module Ridley::Chef
2
- # Borrowed and modified from:
3
- # {https://raw.github.com/opscode/chef/62f9b0e3be8e22eef092163c331b7d3f8d350f94/lib/chef/cookbook/chefignore.rb}
4
- #
5
- # Copyright:: Copyright (c) 2011 Opscode, Inc.
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- class Chefignore
19
- class << self
20
- # Traverse a path in relative context to find a Chefignore file
21
- #
22
- # @param [String] path
23
- # path to traverse
24
- #
25
- # @return [String, nil]
26
- def find_relative_to(path)
27
- [
28
- File.join(path, FILENAME),
29
- File.join(path, 'cookbooks', FILENAME)
30
- ].find { |f| File.exists?(f) }
31
- end
32
- end
33
-
34
- FILENAME = "chefignore".freeze
35
- COMMENTS_AND_WHITESPACE = /^\s*(?:#.*)?$/
36
-
37
- attr_reader :ignores
38
-
39
- def initialize(ignore_file_or_repo)
40
- @ignore_file = find_ignore_file(ignore_file_or_repo)
41
- @ignores = parse_ignore_file
42
- end
43
-
44
- def remove_ignores_from(file_list)
45
- Array(file_list).inject([]) do |unignored, file|
46
- ignored?(file) ? unignored : unignored << file
47
- end
48
- end
49
-
50
- def ignored?(file_name)
51
- @ignores.any? { |glob| File.fnmatch?(glob, file_name) }
52
- end
53
-
54
- private
55
-
56
- def parse_ignore_file
57
- ignore_globs = []
58
-
59
- if File.exist?(@ignore_file) && File.readable?(@ignore_file)
60
- File.foreach(@ignore_file) do |line|
61
- ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE
62
- end
63
- end
64
-
65
- ignore_globs
66
- end
67
-
68
- def find_ignore_file(path)
69
- if File.basename(path) =~ /#{FILENAME}/
70
- path
71
- else
72
- File.join(path, FILENAME)
73
- end
74
- end
75
- end
76
- end
@@ -1,55 +0,0 @@
1
- module Ridley
2
- # @author Jamie Winsor <reset@riotgames.com>
3
- class EncryptedDataBagItemResource
4
- class << self
5
- # Finds a data bag item and decrypts it.
6
- #
7
- # @param [Ridley::Client] client
8
- # @param [Ridley::DataBagResource] data_bag
9
- # @param [String, #chef_id] object
10
- #
11
- # @return [nil, Ridley::DataBagItemResource]
12
- def find(client, data_bag, object)
13
- find!(client, data_bag, object)
14
- rescue Errors::HTTPNotFound
15
- nil
16
- end
17
-
18
- # Finds a data bag item and decrypts it. Throws an exception if the item doesn't exist.
19
- #
20
- # @param [Ridley::Client] client
21
- # @param [Ridley::DataBagResource] data_bag
22
- # @param [String, #chef_id] object
23
- #
24
- # @raise [Errors::HTTPNotFound]
25
- # if a resource with the given chef_id is not found
26
- #
27
- # @return [nil, Ridley::DataBagItemResource]
28
- def find!(client, data_bag, object)
29
- data_bag_item = DataBagItemResource.find!(client, data_bag, object)
30
- data_bag_item.decrypt
31
- new(client, data_bag, data_bag_item.attributes)
32
- end
33
- end
34
-
35
- attr_reader :data_bag
36
- attr_reader :attributes
37
-
38
- # @param [Ridley::Client] client
39
- # @param [Ridley::DataBagResource] data_bag
40
- # @param [#to_hash] attributes
41
- def initialize(client, data_bag, attributes = {})
42
- @client = client
43
- @data_bag = data_bag
44
- @attributes = attributes
45
- end
46
-
47
- def to_s
48
- self.attributes
49
- end
50
-
51
- private
52
-
53
- attr_reader :client
54
- end
55
- end
@@ -1,101 +0,0 @@
1
- module Ridley
2
- class Search
3
- class << self
4
- # Returns an array of possible search indexes to be search on
5
- #
6
- # @param [Ridley::Client] client
7
- #
8
- # @example
9
- #
10
- # Search.indexes(client) => [ :client, :environment, :node, :role ]
11
- #
12
- # @return [Array<String, Symbol>]
13
- def indexes(client)
14
- client.connection.get("search").body.collect { |name, _| name }
15
- end
16
- end
17
-
18
- # @return [Ridley::Client]
19
- attr_reader :client
20
- attr_reader :index
21
- attr_reader :query
22
-
23
- attr_accessor :sort
24
- attr_accessor :rows
25
- attr_accessor :start
26
-
27
- # @param [Ridley::Client] client
28
- # @param [#to_sym] index
29
- # @param [#to_s] query
30
- #
31
- # @option options [String] :sort
32
- # a sort string such as 'name DESC'
33
- # @option options [Integer] :rows
34
- # how many rows to return
35
- # @option options [Integer] :start
36
- # the result number to start from
37
- def initialize(client, index, query, options = {})
38
- @client = client
39
- @index = index.to_sym
40
- @query = query
41
- @sort = options[:sort]
42
- @rows = options[:rows]
43
- @start = options[:start]
44
- end
45
-
46
- # Executes the built up query on the search's client
47
- #
48
- # @example
49
- # Search.new(client, :role)
50
- # search.run =>
51
- # {
52
- # total: 1,
53
- # start: 0,
54
- # rows: [
55
- # {
56
- # name: "ridley-test-role",
57
- # default_attributes: {},
58
- # json_class: "Chef::Role",
59
- # env_run_lists: {},
60
- # run_list: [],
61
- # description: "a test role for Ridley!",
62
- # chef_type: "role",
63
- # override_attributes: {}
64
- # }
65
- # ]
66
- # }
67
- #
68
- # @return [Hash]
69
- def run
70
- response = client.connection.get(query_uri, query_options).body
71
-
72
- case index
73
- when :node
74
- response[:rows].collect { |row| Ridley::NodeResource.new(client, row) }
75
- when :role
76
- response[:rows].collect { |row| Ridley::RoleResource.new(client, row) }
77
- when :client
78
- response[:rows].collect { |row| Ridley::ClientResource.new(client, row) }
79
- when :environment
80
- response[:rows].collect { |row| Ridley::EnvironmentResource.new(client, row) }
81
- else
82
- response[:rows]
83
- end
84
- end
85
-
86
- private
87
-
88
- def query_uri
89
- File.join("search", self.index.to_s)
90
- end
91
-
92
- def query_options
93
- {}.tap do |options|
94
- options[:q] = self.query unless self.query.nil?
95
- options[:sort] = self.sort unless self.sort.nil?
96
- options[:rows] = self.rows unless self.rows.nil?
97
- options[:start] = self.start unless self.start.nil?
98
- end
99
- end
100
- end
101
- end