spice 1.0.0.rc → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +0 -14
  3. data/README.md +1 -1
  4. data/Rakefile +1 -1
  5. data/TODO.md +2 -1
  6. data/lib/spice.rb +47 -72
  7. data/lib/spice/authentication.rb +23 -45
  8. data/lib/spice/base.rb +104 -0
  9. data/lib/spice/client.rb +8 -48
  10. data/lib/spice/config.rb +37 -19
  11. data/lib/spice/connection.rb +33 -117
  12. data/lib/spice/connection/clients.rb +26 -6
  13. data/lib/spice/connection/cookbooks.rb +19 -14
  14. data/lib/spice/connection/data_bags.rb +31 -20
  15. data/lib/spice/connection/environments.rb +6 -7
  16. data/lib/spice/connection/nodes.rb +23 -6
  17. data/lib/spice/connection/roles.rb +5 -5
  18. data/lib/spice/connection/search.rb +12 -12
  19. data/lib/spice/cookbook.rb +3 -29
  20. data/lib/spice/cookbook_version.rb +9 -61
  21. data/lib/spice/core_ext/array.rb +7 -0
  22. data/lib/spice/core_ext/enumerable.rb +11 -0
  23. data/lib/spice/core_ext/hash.rb +49 -0
  24. data/lib/spice/core_ext/mash.rb +219 -0
  25. data/lib/spice/data_bag.rb +3 -37
  26. data/lib/spice/data_bag_item.rb +7 -47
  27. data/lib/spice/environment.rb +12 -27
  28. data/lib/spice/error.rb +22 -10
  29. data/lib/spice/identity_map.rb +8 -0
  30. data/lib/spice/node.rb +13 -34
  31. data/lib/spice/request.rb +73 -11
  32. data/lib/spice/response/parse_json.rb +8 -3
  33. data/lib/spice/role.rb +8 -33
  34. data/lib/spice/version.rb +1 -1
  35. data/spec/fixtures/client.pem +27 -0
  36. data/spec/fixtures/clients/create.json +4 -0
  37. data/spec/fixtures/clients/index.json +5 -0
  38. data/spec/fixtures/clients/reregister.json +5 -0
  39. data/spec/fixtures/clients/show.json +8 -0
  40. data/spec/fixtures/clients/update.json +5 -0
  41. data/spec/fixtures/cookbook_versions/show.json +108 -0
  42. data/spec/fixtures/cookbook_versions/update.json +62 -0
  43. data/spec/fixtures/cookbooks/index-0.10.json +28 -0
  44. data/spec/fixtures/cookbooks/index-0.9.json +4 -0
  45. data/spec/fixtures/cookbooks/show-0.10.json +15 -0
  46. data/spec/fixtures/cookbooks/show-apache2-0.9.json +5 -0
  47. data/spec/fixtures/cookbooks/show-unicorn-0.9.json +5 -0
  48. data/spec/fixtures/data_bag_items/create.json +1 -0
  49. data/spec/fixtures/data_bag_items/show.json +4 -0
  50. data/spec/fixtures/data_bag_items/update.json +4 -0
  51. data/spec/fixtures/data_bags/create.json +3 -0
  52. data/spec/fixtures/data_bags/index.json +3 -0
  53. data/spec/fixtures/data_bags/show.json +3 -0
  54. data/spec/fixtures/environments/cookbook.json +15 -0
  55. data/spec/fixtures/environments/cookbooks.json +28 -0
  56. data/spec/fixtures/environments/create.json +1 -0
  57. data/spec/fixtures/environments/delete.json +8 -0
  58. data/spec/fixtures/environments/index.json +3 -0
  59. data/spec/fixtures/environments/show.json +8 -0
  60. data/spec/fixtures/environments/update.json +8 -0
  61. data/spec/fixtures/nodes/cookbooks.json +41 -0
  62. data/spec/fixtures/nodes/create.json +1 -0
  63. data/spec/fixtures/nodes/delete.json +17 -0
  64. data/spec/fixtures/nodes/index.json +3 -0
  65. data/spec/fixtures/nodes/show.json +17 -0
  66. data/spec/fixtures/nodes/update.json +13 -0
  67. data/spec/fixtures/roles/create.json +1 -0
  68. data/spec/fixtures/roles/delete.json +11 -0
  69. data/spec/fixtures/roles/index.json +3 -0
  70. data/spec/fixtures/roles/show.json +12 -0
  71. data/spec/fixtures/roles/update.json +11 -0
  72. data/spec/fixtures/search/client.json +1 -0
  73. data/spec/fixtures/search/data_bag.json +1 -0
  74. data/spec/fixtures/search/environment.json +1 -0
  75. data/spec/fixtures/search/node.json +1 -0
  76. data/spec/fixtures/search/role.json +1 -0
  77. data/spec/spec_helper.rb +5 -4
  78. data/spec/spice/base_spec.rb +34 -0
  79. data/spec/spice/client_spec.rb +0 -61
  80. data/spec/spice/config_spec.rb +14 -0
  81. data/spec/spice/connection/clients_spec.rb +82 -0
  82. data/spec/spice/connection/cookbooks_spec.rb +86 -0
  83. data/spec/spice/connection/data_bags_spec.rb +126 -0
  84. data/spec/spice/connection_spec.rb +63 -0
  85. data/spec/spice/cookbook_spec.rb +0 -61
  86. data/spec/spice/data_bag_item_spec.rb +7 -0
  87. data/spec/spice/data_bag_spec.rb +0 -160
  88. data/spec/spice/environment_spec.rb +0 -89
  89. data/spec/spice/node_spec.rb +0 -74
  90. data/spec/spice/role_spec.rb +0 -61
  91. data/spec/spice_spec.rb +8 -116
  92. data/spec/support/helpers.rb +58 -0
  93. data/spice.gemspec +13 -15
  94. metadata +227 -87
  95. data/.watchr +0 -22
  96. data/lib/spice/connection/authentication.rb +0 -47
  97. data/lib/spice/mock.rb +0 -46
  98. data/lib/spice/persistence.rb +0 -62
  99. data/spec/spice/chef_spec.rb +0 -52
  100. data/spec/spice/search_spec.rb +0 -2
  101. data/spec/support/chef_requests.rb +0 -0
  102. data/spec/support/client_requests.rb +0 -95
  103. data/spec/support/cookbook_requests.rb +0 -95
  104. data/spec/support/data_bag_item_requests.rb +0 -138
  105. data/spec/support/data_bag_requests.rb +0 -95
  106. data/spec/support/environment_requests.rb +0 -221
  107. data/spec/support/node_requests.rb +0 -138
  108. data/spec/support/respond_with_matcher.rb +0 -53
  109. data/spec/support/role_requests.rb +0 -95
@@ -1,53 +0,0 @@
1
- RSpec::Matchers.define :respond_with do |code|
2
- match do |response|
3
- response.code == code
4
- end
5
-
6
- failure_message_for_should do |code|
7
- "expected to respond_with #{code}"
8
- end
9
-
10
- failure_message_for_should_not do |code|
11
- "expected to not respond with #{code}"
12
- end
13
-
14
- description do
15
- "respond with #{code}"
16
- end
17
- end
18
-
19
- RSpec::Matchers.define :have_body do |body|
20
- match do |response|
21
- response.body == body
22
- end
23
-
24
- failure_message_for_should do |body|
25
- "expected to have a body of #{body}"
26
- end
27
-
28
- failure_message_for_should_not do |body|
29
- "expected to not have a body of #{body}"
30
- end
31
-
32
- description do
33
- "have a valid response body"
34
- end
35
- end
36
-
37
- # RSpec::Matchers.define :have_header do |header|
38
- # match do |response|
39
- # response.headers.has_key?(header.to_sym)
40
- # end
41
- #
42
- # failure_message_for_should do |header|
43
- # "expected to have a header #{header}"
44
- # end
45
- #
46
- # failure_message_for_should_not do |header|
47
- # "expected to not have a header #{header}"
48
- # end
49
- #
50
- # description do
51
- # "have a header #{header}"
52
- # end
53
- # end
@@ -1,95 +0,0 @@
1
- def stub_role_list
2
- stub_request(:get, "http://localhost:4000/roles").
3
- to_return(
4
- :status => 200,
5
- :body => role_list_response
6
- )
7
- end
8
-
9
- def stub_role_show(status=200)
10
- case status
11
- when 200
12
- stub_request(:get, "http://localhost:4000/roles/testrole").
13
- to_return(
14
- :status => status,
15
- :body => role_show_response
16
- )
17
- when 404
18
- stub_request(:get, "http://localhost:4000/roles/testrole").
19
- to_return(
20
- :status => status,
21
- :body => role_not_found
22
- )
23
- end
24
- end
25
-
26
- def stub_role_create(status=201)
27
- case status
28
- when 201
29
- stub_request(:post, "http://localhost:4000/roles").
30
- with(
31
- :body => role_create_payload ).
32
- to_return(
33
- :status => status,
34
- :body => role_create_response
35
- )
36
- when 409
37
- stub_request(:post, "http://localhost:4000/roles").
38
- with(
39
- :body => role_create_payload ).
40
- to_return(
41
- :status => status,
42
- :body => role_conflict
43
- )
44
- end
45
- end
46
-
47
- def stub_role_delete(status=200)
48
- case status
49
- when 200
50
- stub_request(:delete, "http://localhost:4000/roles/testrole").
51
- with(:body => "").
52
- to_return(
53
- :status => status,
54
- :body => role_delete_response
55
- )
56
- when 404
57
- stub_request(:delete, "http://localhost:4000/roles/testrole").
58
- with(:body => "").
59
- to_return(
60
- :status => status,
61
- :body => role_not_found
62
- )
63
- end
64
- end
65
-
66
- # payloads and responses
67
-
68
- def role_list_response
69
- { "testrole" => "http://localhost:4000/roles/testrole" }
70
- end
71
-
72
- def role_show_response
73
- { "adam" => "http://localhost:4000/roles/testrole" }
74
- end
75
-
76
- def role_delete_response
77
- { "name" => "users", "json_class" => "Chef::Role", "chef_type" => "role" }
78
- end
79
-
80
- def role_not_found
81
- { "error" => [ "Could not load role testrole" ] }
82
- end
83
-
84
- def role_conflict
85
- { "error" => [ "Role already exists" ] }
86
- end
87
-
88
- def role_create_payload
89
- { "name" => "testrole" }
90
- end
91
-
92
- def role_create_response
93
- { "private_key"=>"-----BEGIN RSA PRIVATE KEY-----",
94
- "uri"=>"http://localhost:4000/roles/testrole" }
95
- end