stacker_bee 2.0.0 → 2.1.0.pre180

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +13 -1
  3. data/README.md +134 -64
  4. data/bin/stacker_bee +4 -3
  5. data/config.default.yml +1 -1
  6. data/lib/stacker_bee/api.rb +2 -3
  7. data/lib/stacker_bee/client.rb +101 -19
  8. data/lib/stacker_bee/connection.rb +31 -16
  9. data/lib/stacker_bee/{middleware → http_middleware}/detokenizer.rb +3 -2
  10. data/lib/stacker_bee/http_middleware/graylog.rb +14 -0
  11. data/lib/stacker_bee/{middleware → http_middleware}/signed_query.rb +1 -1
  12. data/lib/stacker_bee/middleware/adapter.rb +16 -0
  13. data/lib/stacker_bee/middleware/base.rb +33 -0
  14. data/lib/stacker_bee/middleware/clean_response.rb +42 -0
  15. data/lib/stacker_bee/middleware/cloud_stack_api.rb +17 -0
  16. data/lib/stacker_bee/middleware/console_access.rb +38 -0
  17. data/lib/stacker_bee/middleware/de_namespace.rb +15 -0
  18. data/lib/stacker_bee/middleware/dictionary_flattener.rb +44 -0
  19. data/lib/stacker_bee/middleware/endpoint_normalizer.rb +23 -0
  20. data/lib/stacker_bee/middleware/environment.rb +23 -0
  21. data/lib/stacker_bee/middleware/format_keys.rb +13 -0
  22. data/lib/stacker_bee/middleware/format_values.rb +13 -0
  23. data/lib/stacker_bee/middleware/http_status.rb +14 -0
  24. data/lib/stacker_bee/middleware/json_body.rb +14 -0
  25. data/lib/stacker_bee/middleware/raise_on_http_error.rb +11 -0
  26. data/lib/stacker_bee/middleware/rashify_response.rb +21 -0
  27. data/lib/stacker_bee/middleware/remove_empty_strings.rb +11 -0
  28. data/lib/stacker_bee/middleware/remove_nils.rb +9 -0
  29. data/lib/stacker_bee/request_error.rb +8 -16
  30. data/lib/stacker_bee/utilities.rb +30 -0
  31. data/lib/stacker_bee/version.rb +1 -1
  32. data/lib/stacker_bee.rb +1 -1
  33. data/spec/cassettes/A_request_sent_to_CloudStack_for_console_access/returns_html_for_console_access.yml +33 -0
  34. data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/{a_request_parameter_with_a_Map → a_request_parameter_with_a_map}/can_create_an_object.yml +0 -0
  35. data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/a_request_that_triggers_an_error/properly_signs_the_request.yml +35 -0
  36. data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/middleware/a_middleware_that_doesn_t_match_the_content_type/uses_the_middleware.yml +33 -0
  37. data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/middleware/a_middleware_that_matches_the_content_type/uses_the_middleware.yml +33 -0
  38. data/spec/integration/check_spec.rb +48 -0
  39. data/spec/integration/configure_middleware_spec.rb +54 -16
  40. data/spec/integration/console_spec.rb +21 -0
  41. data/spec/integration/request_spec.rb +57 -2
  42. data/spec/spec_helper.rb +11 -1
  43. data/spec/units/faraday_graylog_middleware_spec.rb +1 -1
  44. data/spec/units/stacker_bee/client_spec.rb +47 -78
  45. data/spec/units/stacker_bee/connection_spec.rb +34 -11
  46. data/spec/units/stacker_bee/console_spec.rb +0 -0
  47. data/spec/units/stacker_bee/{graylog_faraday_middleware_spec.rb → http_middleware/graylog_spec.rb} +18 -2
  48. data/spec/units/stacker_bee/middleware/adapter_spec.rb +54 -0
  49. data/spec/units/stacker_bee/middleware/base_spec.rb +128 -0
  50. data/spec/units/stacker_bee/middleware/cloudstack_api_spec.rb +37 -0
  51. data/spec/units/stacker_bee/middleware/console_access_spec.rb +59 -0
  52. data/spec/units/stacker_bee/{dictionary_flattener_spec.rb → middleware/dictionary_flattener_spec.rb} +7 -7
  53. data/spec/units/stacker_bee/middleware/endpoint_normalizer_spec.rb +36 -0
  54. data/spec/units/stacker_bee/middleware/format_keys_spec.rb +18 -0
  55. data/spec/units/stacker_bee/middleware/format_values_spec.rb +15 -0
  56. data/spec/units/stacker_bee/middleware/http_status_spec.rb +34 -0
  57. data/spec/units/stacker_bee/middleware/raise_on_http_errors_spec.rb +5 -0
  58. data/spec/units/stacker_bee/middleware/remove_empty_strings_spec.rb +54 -0
  59. data/spec/units/stacker_bee/middleware/remove_nils_spec.rb +8 -0
  60. data/spec/units/stacker_bee/request_error_spec.rb +25 -37
  61. data/spec/units/stacker_bee/utilities_spec.rb +26 -0
  62. data/stacker_bee.gemspec +6 -2
  63. metadata +84 -38
  64. data/lib/stacker_bee/body_parser.rb +0 -23
  65. data/lib/stacker_bee/dictionary_flattener.rb +0 -41
  66. data/lib/stacker_bee/graylog_faraday_middleware.rb +0 -12
  67. data/lib/stacker_bee/middleware/logger.rb +0 -47
  68. data/lib/stacker_bee/request.rb +0 -46
  69. data/lib/stacker_bee/response.rb +0 -29
  70. data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/a_request_parameter_with_a_Map/object.yml +0 -153
  71. data/spec/units/stacker_bee/middleware/logger_spec.rb +0 -55
  72. data/spec/units/stacker_bee/request_spec.rb +0 -51
  73. data/spec/units/stacker_bee/response_spec.rb +0 -79
@@ -1,55 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe StackerBee::Middleware::Logger do
4
- let(:app) { double }
5
- let(:io) { StringIO.new }
6
- let(:logger) { Logger.new(io) }
7
- let(:log_string) { io.string }
8
- let(:middleware) { described_class.new app, logger }
9
- subject { middleware }
10
-
11
- context "with a no logger specified" do
12
- let(:middleware) { described_class.new app, nil }
13
- its(:logger) { should be_a Logger }
14
- end
15
-
16
- describe "logging request" do
17
- let(:env) do
18
- {
19
- method: "PATCH",
20
- url: "http://localhost",
21
- request_headers: { "User-Agent" => "RSpec" }
22
- }
23
- end
24
- before do
25
- middleware.log_request(env)
26
- end
27
- subject { log_string }
28
- it { should include "PATCH" }
29
- it { should include "localhost" }
30
- it { should include "User-Agent" }
31
- end
32
-
33
- describe "logging a response" do
34
- let(:status) { 200 }
35
- let(:env) do
36
- {
37
- status: status,
38
- body: "OK",
39
- response_headers: { "Server" => "RSpec" }
40
- }
41
- end
42
- before do
43
- middleware.log_response(env)
44
- end
45
- subject { log_string }
46
- it { should =~ /INFO.*#{status}/ }
47
- it { should include "OK" }
48
- it { should include "Server" }
49
-
50
- context "failing status" do
51
- let(:status) { 401 }
52
- it { should =~ /ERROR.*#{status}/ }
53
- end
54
- end
55
- end
@@ -1,51 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe StackerBee::Request do
4
- let(:endpoint) { "listStuff" }
5
- let(:api_key) { "this_guy" }
6
- let(:params) do
7
- {
8
- list: :all,
9
- nothing: nil,
10
- deets: [:things, :stuff],
11
- settings: { cookiename: "Fred", something: "cool" },
12
- blank: ''
13
- }
14
- end
15
-
16
- let(:request) { StackerBee::Request.new endpoint, api_key, params }
17
- subject { request }
18
-
19
- describe "#query_params" do
20
- let(:new_params) { params.merge("settings[1].name" => "cool") }
21
- let(:flattener) { double(new: double(params: new_params)) }
22
-
23
- before do
24
- stub_const "StackerBee::DictionaryFlattener", flattener
25
- end
26
-
27
- subject { request.query_params }
28
-
29
- it { should include ["settings[1].name", "cool"] }
30
- it { should include ["list", :all] }
31
- it { should include %W(apiKey #{api_key}) }
32
- it { should include %w(command listStuff) }
33
- it { should include %w(response json) }
34
- it { should include %w(deets things,stuff) }
35
-
36
- it "removes params with nil values" do
37
- subject.map(&:first).should_not include "nothing"
38
- end
39
-
40
- it "removes params with blank values" do
41
- subject.map(&:first).should_not include "blank"
42
- end
43
-
44
- context "allowing blank strings" do
45
- before do
46
- request.allow_empty_string_params = true
47
- end
48
- it { should include ['blank', ''] }
49
- end
50
- end
51
- end
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe StackerBee::Response do
4
- let(:raw_body) { '{ "json": "here" }' }
5
- let(:raw_response) { double body: raw_body, :success? => true }
6
- let(:response) { StackerBee::Response.new raw_response }
7
- subject { response }
8
- its(:body) { should == 'here' }
9
-
10
- context "raw response for list endpoint" do
11
- let(:raw_body) do
12
- '{ "listvirtualmachinesresponse":
13
- { "count": 1, "virtualmachine": [{"ohai": "there"}] }
14
- }'
15
- end
16
- its(:body) { should == [{ "ohai" => "there" }] }
17
-
18
- context "first item" do
19
- subject { response.first }
20
- it { should == { "ohai" => "there" } }
21
- its(["o_hai"]) { should == "there" }
22
- end
23
- end
24
-
25
- context "raw response for list endpoint with no records" do
26
- let(:raw_body) { '{ "listvirtualmachinesresponse": {} }' }
27
- its(:body) { should == {} }
28
- end
29
-
30
- context "raw response for async endpoint" do
31
- let(:raw_body) do
32
- '{ "deployvirtualmachineresponse": { "id": 123, "jobid": 321 } }'
33
- end
34
- its(:body) { should == { "id" => 123, "jobid" => 321 } }
35
- end
36
-
37
- context "raw response for create endpoint" do
38
- let(:raw_body) { '{ "register_ssh_keypair": { "fingerprint": 456 } }' }
39
- its(:body) { should == { "fingerprint" => 456 } }
40
- end
41
-
42
- context "for failed request" do
43
- let(:raw_response) do
44
- double(
45
- :body => '{ "foo": "bar" }',
46
- :success? => false,
47
- :status => 431
48
- )
49
- end
50
- it { expect { subject }.to raise_exception StackerBee::ClientError }
51
- end
52
-
53
- context "for response with single key that's an object" do
54
- let(:raw_body) { '{ "getuserresponse": { "user": { "id": 1 } } }' }
55
- its(:body) { should == { "id" => 1 } }
56
- end
57
-
58
- context "for request with invalid credentials" do
59
- let(:raw_response) do
60
- double(
61
- body: %[
62
- { "createprojectresponse" :
63
- {"uuidList":[],"errorcode":401,"errortext":"#{message}"} } ],
64
- success?: false,
65
- status: 401
66
- )
67
- end
68
- let(:client_error) { StackerBee::AuthenticationError.new raw_response }
69
- let(:message) do
70
- "unable to verify user credentials and/or request signature"
71
- end
72
- it "raises an AuthenticationError" do
73
- expect { subject }.to raise_exception(
74
- StackerBee::AuthenticationError, message
75
- )
76
- end
77
- end
78
-
79
- end