stacker_bee 2.1.0.pre201 → 2.1.0.pre227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/stacker_bee/builder.rb +1 -1
- data/lib/stacker_bee/client.rb +11 -25
- data/lib/stacker_bee/configuration.rb +58 -6
- data/lib/stacker_bee/middleware/environment.rb +2 -0
- data/spec/integration/request_spec.rb +3 -4
- data/spec/units/stacker_bee/client_spec.rb +26 -46
- data/spec/units/stacker_bee/configuration_spec.rb +154 -10
- data/stacker_bee.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmIxNjBiNGExMjdmODM0MGRjMmE5MWE2YWQ1ZjNhYzVhYzAwNDM3NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWQwY2I1MmZlZjBmMGQwMGQ4OTVlNGNhMWMxY2YzMWY5MzA3YTlhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTM1YWVhMTFjNmY2MTAxZjk5MDZkZmNhNmE4YTBhZjUwMmU4ZTIxZWU4MzYz
|
10
|
+
YWI0ODFlNDk2ZmQyN2FlMTFmMzJiZjc5ZDlkZGNiZmRlMmVlYWM5NWU2OTAy
|
11
|
+
NzUxNGUyODE3Y2U1MWUwZGUxZDRhNzQ2OGFhMDMxZDM1MmVkYTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGVhYzA2MDM4MTU1M2YxZjgxZGVhMGRhZjJhNGJmNmE4YzY1YTM1MmRlOWIx
|
14
|
+
YjM0NTlmZDUyMzcyMjg4ZWZhOWVmM2RkMTNhNmMyMTliY2FkYjM0MDA0Njg4
|
15
|
+
MmFlNjBkNjM2Yzc0ZjUzNzgzMDIxMjc2MmJiNDhlYzczZjc2ZjE=
|
data/lib/stacker_bee/builder.rb
CHANGED
data/lib/stacker_bee/client.rb
CHANGED
@@ -28,15 +28,6 @@ module StackerBee
|
|
28
28
|
File.dirname(__FILE__), '../../config/4.2.json'
|
29
29
|
)
|
30
30
|
|
31
|
-
extend Forwardable
|
32
|
-
def_delegators :configuration,
|
33
|
-
:url,
|
34
|
-
:url=,
|
35
|
-
:api_key,
|
36
|
-
:api_key=,
|
37
|
-
:secret_key,
|
38
|
-
:secret_key=
|
39
|
-
|
40
31
|
# rubocop:disable MethodLength
|
41
32
|
def middlewares
|
42
33
|
# request
|
@@ -72,18 +63,16 @@ module StackerBee
|
|
72
63
|
|
73
64
|
class << self
|
74
65
|
def reset!
|
75
|
-
|
66
|
+
self.api, self.api_path, self.configuration = nil
|
76
67
|
end
|
77
68
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
middlewares: proc {}
|
82
|
-
}
|
69
|
+
def configuration
|
70
|
+
self.configuration = nil unless @configuration
|
71
|
+
@configuration
|
83
72
|
end
|
84
73
|
|
85
|
-
def configuration=(config_hash)
|
86
|
-
|
74
|
+
def configuration=(config_hash = {})
|
75
|
+
@configuration = Configuration.new(config_hash)
|
87
76
|
end
|
88
77
|
|
89
78
|
def api_path
|
@@ -96,6 +85,7 @@ module StackerBee
|
|
96
85
|
@api_path = new_api_path
|
97
86
|
end
|
98
87
|
|
88
|
+
attr_writer :api
|
99
89
|
def api
|
100
90
|
@api ||= API.new(api_path: api_path)
|
101
91
|
end
|
@@ -106,17 +96,18 @@ module StackerBee
|
|
106
96
|
end
|
107
97
|
|
108
98
|
def configuration=(config)
|
109
|
-
@configuration =
|
99
|
+
@configuration = self.class.configuration.merge(config)
|
110
100
|
end
|
111
101
|
|
112
102
|
def configuration
|
113
|
-
|
103
|
+
self.configuration = {} unless @configuration
|
104
|
+
@configuration
|
114
105
|
end
|
115
106
|
|
116
107
|
def request(endpoint_name, params = {})
|
117
108
|
env = Middleware::Environment.new(
|
118
109
|
endpoint_name: endpoint_name,
|
119
|
-
api_key: api_key,
|
110
|
+
api_key: configuration.api_key,
|
120
111
|
params: params
|
121
112
|
)
|
122
113
|
|
@@ -160,10 +151,5 @@ module StackerBee
|
|
160
151
|
def connection
|
161
152
|
@connection ||= Connection.new(configuration)
|
162
153
|
end
|
163
|
-
|
164
|
-
def configuration_with_defaults(config = {})
|
165
|
-
config_hash = self.class.default_config.merge(config)
|
166
|
-
Configuration.new(config_hash)
|
167
|
-
end
|
168
154
|
end
|
169
155
|
end
|
@@ -1,11 +1,63 @@
|
|
1
|
-
require "ostruct"
|
2
|
-
|
3
1
|
module StackerBee
|
4
|
-
class Configuration
|
2
|
+
class Configuration
|
3
|
+
class NoAttributeError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
ATTRIBUTES = [
|
7
|
+
:ssl_verify,
|
8
|
+
:url,
|
9
|
+
:secret_key,
|
10
|
+
:api_key,
|
11
|
+
:middlewares,
|
12
|
+
:faraday_middlewares
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(attrs = nil)
|
16
|
+
@attributes = attrs || {}
|
17
|
+
|
18
|
+
@attributes.each_pair do |key, value|
|
19
|
+
unless ATTRIBUTES.include?(key)
|
20
|
+
fail NoAttributeError, "No attribute defined: '#{key}'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
def ssl_verify?
|
6
|
-
|
7
|
-
|
8
|
-
|
26
|
+
attribute :ssl_verify, true
|
27
|
+
end
|
28
|
+
|
29
|
+
def url
|
30
|
+
attribute :url
|
31
|
+
end
|
32
|
+
|
33
|
+
def secret_key
|
34
|
+
attribute :secret_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_key
|
38
|
+
attribute :api_key
|
39
|
+
end
|
40
|
+
|
41
|
+
def middlewares
|
42
|
+
attribute :middlewares, proc {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def faraday_middlewares
|
46
|
+
attribute :faraday_middlewares, proc {}
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_hash
|
50
|
+
@attributes
|
51
|
+
end
|
52
|
+
|
53
|
+
def merge(other)
|
54
|
+
self.class.new(to_hash.merge(other.to_hash))
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def attribute(key, value = nil)
|
60
|
+
@attributes.fetch(key, value)
|
9
61
|
end
|
10
62
|
end
|
11
63
|
end
|
@@ -7,10 +7,9 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
7
7
|
let(:url) { CONFIG["url"] }
|
8
8
|
let(:config_hash) do
|
9
9
|
{
|
10
|
-
url:
|
11
|
-
api_key:
|
12
|
-
secret_key:
|
13
|
-
apis_path: File.join(File.dirname(__FILE__), '../fixtures/4.2.json'),
|
10
|
+
url: url,
|
11
|
+
api_key: CONFIG["api_key"],
|
12
|
+
secret_key: CONFIG["secret_key"],
|
14
13
|
middlewares: middlewares
|
15
14
|
}
|
16
15
|
end
|
@@ -61,6 +61,8 @@ describe StackerBee::Client, "calling endpoint" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe StackerBee::Client, "configuration" do
|
64
|
+
before { described_class.configuration = default_config_hash }
|
65
|
+
|
64
66
|
let(:default_url) { "default_cloud-stack.com" }
|
65
67
|
let(:default_api_key) { "default-cloud-stack-api-key" }
|
66
68
|
let(:default_secret_key) { "default-cloud-stack-secret-key" }
|
@@ -73,9 +75,7 @@ describe StackerBee::Client, "configuration" do
|
|
73
75
|
middlewares: proc {}
|
74
76
|
}
|
75
77
|
end
|
76
|
-
|
77
|
-
StackerBee::Configuration.new(default_config_hash)
|
78
|
-
end
|
78
|
+
|
79
79
|
let(:instance_url) { "instance-cloud-stack.com" }
|
80
80
|
let(:instance_api_key) { "instance-cloud-stack-api-key" }
|
81
81
|
let(:instance_secret_key) { "instance-cloud-stack-secret-key" }
|
@@ -88,64 +88,44 @@ describe StackerBee::Client, "configuration" do
|
|
88
88
|
middlewares: proc {}
|
89
89
|
}
|
90
90
|
end
|
91
|
-
let!(:instance_configuration) do
|
92
|
-
StackerBee::Configuration.new(instance_config_hash)
|
93
|
-
end
|
94
|
-
before do
|
95
|
-
StackerBee::Configuration.stub(:new) do
|
96
|
-
fail "Unexpected Configuration instantiation: \n#{args.inspect}"
|
97
|
-
end
|
98
|
-
StackerBee::Configuration.stub(:new).with(default_config_hash) do
|
99
|
-
default_configuration
|
100
|
-
end
|
101
|
-
StackerBee::Configuration.stub(:new).with(instance_config_hash) do
|
102
|
-
instance_configuration
|
103
|
-
end
|
104
|
-
described_class.configuration = default_config_hash
|
105
|
-
end
|
106
91
|
|
107
92
|
describe ".new" do
|
108
|
-
subject {
|
93
|
+
subject { client.configuration }
|
109
94
|
|
110
95
|
context "with default, class configuration" do
|
111
|
-
|
112
|
-
|
113
|
-
its(:
|
96
|
+
let(:client) { described_class.new }
|
97
|
+
|
98
|
+
its(:url) { should eq default_url }
|
99
|
+
its(:api_key) { should eq default_api_key }
|
100
|
+
its(:secret_key) { should eq default_secret_key }
|
114
101
|
end
|
115
102
|
|
116
103
|
context "with instance-specific configuration" do
|
117
|
-
|
118
|
-
|
119
|
-
its(:url)
|
120
|
-
its(:api_key)
|
121
|
-
its(:secret_key)
|
104
|
+
let(:client) { described_class.new(instance_config_hash) }
|
105
|
+
|
106
|
+
its(:url) { should eq instance_url }
|
107
|
+
its(:api_key) { should eq instance_api_key }
|
108
|
+
its(:secret_key) { should eq instance_secret_key }
|
122
109
|
end
|
123
110
|
|
124
111
|
context "with instance-specific configuration that's not a hash" do
|
125
|
-
|
112
|
+
let(:client) { described_class.new(config) }
|
126
113
|
let(:config) { double(to_hash: instance_config_hash) }
|
127
|
-
its(:configuration) { should eq instance_configuration }
|
128
|
-
its(:url) { should eq instance_url }
|
129
|
-
its(:api_key) { should eq instance_api_key }
|
130
|
-
its(:secret_key) { should eq instance_secret_key }
|
131
|
-
end
|
132
114
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
its(:url) { should eq other_url }
|
115
|
+
its(:url) { should eq instance_url }
|
116
|
+
its(:api_key) { should eq instance_api_key }
|
117
|
+
its(:secret_key) { should eq instance_secret_key }
|
137
118
|
end
|
138
119
|
|
139
|
-
|
140
|
-
let(:
|
141
|
-
|
142
|
-
|
143
|
-
|
120
|
+
context "with partial instance-specific configuration" do
|
121
|
+
let(:client) { described_class.new(partial_config_hash) }
|
122
|
+
let(:partial_config_hash) do
|
123
|
+
{ url: instance_config_hash[:url] }
|
124
|
+
end
|
144
125
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
its(:secret_key) { should eq other_secret_key }
|
126
|
+
its(:url) { should eq instance_url }
|
127
|
+
its(:api_key) { should eq default_api_key }
|
128
|
+
its(:secret_key) { should eq default_secret_key }
|
149
129
|
end
|
150
130
|
end
|
151
131
|
end
|
@@ -1,25 +1,169 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe StackerBee::Configuration do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe "setting an attribute that doesn't exist" do
|
5
|
+
[:ssl_verify?, :url?, :other_attr].each do |attr|
|
6
|
+
it "raises an error" do
|
7
|
+
expect { described_class.new(attr => true) }
|
8
|
+
.to raise_error described_class::NoAttributeError, /#{attr}/
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
8
13
|
describe "#ssl_verify?" do
|
9
14
|
subject { configuration.ssl_verify? }
|
10
|
-
let(:configuration) { described_class.new(ssl_verify: ssl_verify) }
|
11
15
|
|
12
|
-
context "when
|
13
|
-
let(:
|
16
|
+
context "when not set" do
|
17
|
+
let(:configuration) { described_class.new }
|
14
18
|
it { should eq true }
|
15
19
|
end
|
16
|
-
|
17
|
-
|
20
|
+
|
21
|
+
context "when set to false" do
|
22
|
+
let(:configuration) { described_class.new(ssl_verify: false) }
|
18
23
|
it { should eq false }
|
19
24
|
end
|
20
|
-
|
21
|
-
|
25
|
+
|
26
|
+
context "when set to true" do
|
27
|
+
let(:configuration) { described_class.new(ssl_verify: true) }
|
22
28
|
it { should eq true }
|
23
29
|
end
|
24
30
|
end
|
31
|
+
|
32
|
+
describe "#url" do
|
33
|
+
subject { configuration.url }
|
34
|
+
|
35
|
+
context "when not set" do
|
36
|
+
let(:configuration) { described_class.new }
|
37
|
+
it { should eq nil }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when set" do
|
41
|
+
let(:configuration) { described_class.new(url: setting) }
|
42
|
+
let(:setting) { "http://example.com" }
|
43
|
+
it { should eq setting }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#secret_key" do
|
48
|
+
subject { configuration.secret_key }
|
49
|
+
|
50
|
+
context "when not set" do
|
51
|
+
let(:configuration) { described_class.new }
|
52
|
+
it { should eq nil }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when set" do
|
56
|
+
let(:configuration) { described_class.new(secret_key: setting) }
|
57
|
+
let(:setting) { "qwertyuiop" }
|
58
|
+
it { should eq setting }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#api_key" do
|
63
|
+
subject { configuration.api_key }
|
64
|
+
|
65
|
+
context "when not set" do
|
66
|
+
let(:configuration) { described_class.new }
|
67
|
+
it { should eq nil }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when set" do
|
71
|
+
let(:configuration) { described_class.new(api_key: setting) }
|
72
|
+
let(:setting) { "qwertyuiop" }
|
73
|
+
it { should eq setting }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#middlewares" do
|
78
|
+
subject { configuration.middlewares }
|
79
|
+
|
80
|
+
context "when not set" do
|
81
|
+
let(:configuration) { described_class.new }
|
82
|
+
it { should be_a Proc }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when set" do
|
86
|
+
let(:configuration) { described_class.new(middlewares: setting) }
|
87
|
+
let(:setting) { proc { something } }
|
88
|
+
it { should eq setting }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#faraday_middlewares" do
|
93
|
+
subject { configuration.faraday_middlewares }
|
94
|
+
|
95
|
+
context "when not set" do
|
96
|
+
let(:configuration) { described_class.new }
|
97
|
+
it { should be_a Proc }
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when set" do
|
101
|
+
let(:configuration) { described_class.new(faraday_middlewares: setting) }
|
102
|
+
let(:setting) { proc { something } }
|
103
|
+
it { should eq setting }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#merge" do
|
108
|
+
subject { parent.merge(child) }
|
109
|
+
|
110
|
+
let(:parent) do
|
111
|
+
described_class.new(
|
112
|
+
url: :parent_url,
|
113
|
+
api_key: :parent_api_key,
|
114
|
+
secret_key: :parent_secret_key,
|
115
|
+
ssl_verify: :parent_ssl_verify,
|
116
|
+
middlewares: :parent_ssl_middlewares,
|
117
|
+
faraday_middlewares: :parent_faraday_middlewares
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
let(:child) do
|
122
|
+
described_class.new(
|
123
|
+
url: :child_url,
|
124
|
+
api_key: :child_api_key,
|
125
|
+
secret_key: :child_secret_key,
|
126
|
+
ssl_verify: :child_ssl_verify,
|
127
|
+
middlewares: :child_ssl_middlewares,
|
128
|
+
faraday_middlewares: :child_faraday_middlewares
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when the child doesn't have an attribute set" do
|
133
|
+
let(:child) { described_class.new }
|
134
|
+
it "uses the attribute of the parent" do
|
135
|
+
subject.url.should eq :parent_url
|
136
|
+
subject.api_key.should eq :parent_api_key
|
137
|
+
subject.secret_key.should eq :parent_secret_key
|
138
|
+
subject.ssl_verify?.should eq :parent_ssl_verify
|
139
|
+
subject.middlewares.should eq :parent_ssl_middlewares
|
140
|
+
subject.faraday_middlewares.should eq :parent_faraday_middlewares
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "when the parent doesn't have an attribute set" do
|
145
|
+
let(:parent) { described_class.new }
|
146
|
+
it "uses the attribute of the child" do
|
147
|
+
subject.url.should eq :child_url
|
148
|
+
subject.api_key.should eq :child_api_key
|
149
|
+
subject.secret_key.should eq :child_secret_key
|
150
|
+
subject.ssl_verify?.should eq :child_ssl_verify
|
151
|
+
subject.middlewares.should eq :child_ssl_middlewares
|
152
|
+
subject.faraday_middlewares.should eq :child_faraday_middlewares
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when the parent and child don't have an attribut set" do
|
157
|
+
let(:child) { described_class.new }
|
158
|
+
let(:parent) { described_class.new }
|
159
|
+
it "uses the defaults of the attributes of the child" do
|
160
|
+
subject.url.should eq nil
|
161
|
+
subject.api_key.should eq nil
|
162
|
+
subject.secret_key.should eq nil
|
163
|
+
subject.ssl_verify?.should eq true
|
164
|
+
subject.middlewares.should be_a Proc
|
165
|
+
subject.faraday_middlewares.should be_a Proc
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
25
169
|
end
|
data/stacker_bee.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "faraday",
|
23
|
-
spec.add_runtime_dependency 'multi_json',
|
22
|
+
spec.add_runtime_dependency "faraday", "~> 0.8", "< 0.9"
|
23
|
+
spec.add_runtime_dependency 'multi_json', "~> 1.8"
|
24
24
|
|
25
25
|
# this is a dependency for FaradayMiddleware::Graylog
|
26
26
|
spec.add_runtime_dependency "faraday_middleware", "~> 0.9"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stacker_bee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0.
|
4
|
+
version: 2.1.0.pre227
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sterndale
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|