aviator 0.0.1 → 0.0.2

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.
Files changed (72) hide show
  1. data/.coveralls.yml +1 -0
  2. data/.gitignore +6 -1
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +12 -0
  6. data/Gemfile +13 -0
  7. data/Guardfile +6 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.md +151 -2
  10. data/Rakefile +8 -0
  11. data/aviator.gemspec +14 -1
  12. data/bin/aviator +110 -0
  13. data/lib/aviator/core.rb +9 -0
  14. data/lib/aviator/core/request.rb +229 -0
  15. data/lib/aviator/core/response.rb +33 -0
  16. data/lib/aviator/core/service.rb +203 -0
  17. data/lib/aviator/core/session.rb +187 -0
  18. data/lib/aviator/openstack/compute/v2/public/list_images.rb +49 -0
  19. data/lib/aviator/openstack/identity/v2/admin/create_tenant.rb +42 -0
  20. data/lib/aviator/openstack/identity/v2/admin/list_tenants.rb +43 -0
  21. data/lib/aviator/openstack/identity/v2/public/create_token.rb +61 -0
  22. data/lib/aviator/openstack/identity/v2/public/list_tenants.rb +44 -0
  23. data/lib/aviator/version.rb +1 -1
  24. data/test/aviator/core/request_test.rb +342 -0
  25. data/test/aviator/core/service_test.rb +158 -0
  26. data/test/aviator/core/session_test.rb +201 -0
  27. data/test/aviator/openstack/compute/v2/public/list_images_test.rb +179 -0
  28. data/test/aviator/openstack/identity/v2/admin/create_tenant_test.rb +151 -0
  29. data/test/aviator/openstack/identity/v2/public/create_token_test.rb +159 -0
  30. data/test/cassettes/core/service/i_default_session_data_/sets_the_service_s_default_session_data.yml +63 -0
  31. data/test/cassettes/core/service/i_request/accepts_an_endpoint_type_option_for_selecting_a_specific_request.yml +140 -0
  32. data/test/cassettes/core/service/i_request/can_find_the_correct_request_based_on_bootstrapped_session_data.yml +63 -0
  33. data/test/cassettes/core/service/i_request/can_find_the_correct_request_based_on_non-bootstrapped_session_data.yml +97 -0
  34. data/test/cassettes/core/service/i_request/can_find_the_correct_request_if_api_version_is_not_defined_but_can_be_inferred_from_host_uri.yml +63 -0
  35. data/test/cassettes/core/service/i_request/uses_the_default_session_data_if_session_data_is_not_provided.yml +97 -0
  36. data/test/cassettes/core/session/c_load/creates_a_new_instance_from_the_given_session_dump.yml +63 -0
  37. data/test/cassettes/core/session/c_load/uses_the_loaded_auth_info_for_its_services.yml +63 -0
  38. data/test/cassettes/core/session/c_new/directs_log_entries_to_the_given_log_file.yml +63 -0
  39. data/test/cassettes/core/session/i_authenticate/authenticates_against_the_auth_service_indicated_in_the_config_file.yml +63 -0
  40. data/test/cassettes/core/session/i_authenticate/authenticates_against_the_auth_service_using_the_credentials_in_the_given_block.yml +38 -0
  41. data/test/cassettes/core/session/i_authenticate/raises_an_AuthenticationError_when_authentication_fails.yml +35 -0
  42. data/test/cassettes/core/session/i_authenticate/updates_the_session_data_of_its_service_objects.yml +123 -0
  43. data/test/cassettes/core/session/i_dump/serializes_the_session_data_for_caching.yml +63 -0
  44. data/test/cassettes/core/session/i_validate/returns_false_if_session_is_no_longer_valid.yml +97 -0
  45. data/test/cassettes/core/session/i_validate/returns_true_if_session_is_still_valid.yml +98 -0
  46. data/test/cassettes/core/session/i_xxx_service/returns_an_instance_of_the_indicated_service.yml +63 -0
  47. data/test/cassettes/openstack/compute/v2/public/list_images/leads_to_a_valid_response_when_no_parameters_are_provided.yml +108 -0
  48. data/test/cassettes/openstack/compute/v2/public/list_images/leads_to_a_valid_response_when_parameters_are_invalid.yml +96 -0
  49. data/test/cassettes/openstack/compute/v2/public/list_images/leads_to_a_valid_response_when_parameters_are_valid.yml +103 -0
  50. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_body.yml +63 -0
  51. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_body_.yml +63 -0
  52. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_headers.yml +63 -0
  53. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_headers_.yml +63 -0
  54. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_url.yml +63 -0
  55. data/test/cassettes/openstack/compute/v2/public/list_images/returns_the_correct_value_for_url_.yml +63 -0
  56. data/test/cassettes/openstack/identity/v2/admin/create_tenant/leads_to_a_valid_response_when_params_are_invalid.yml +97 -0
  57. data/test/cassettes/openstack/identity/v2/admin/create_tenant/leads_to_a_valid_response_when_params_are_valid.yml +97 -0
  58. data/test/cassettes/openstack/identity/v2/admin/create_tenant/leads_to_a_valid_response_when_provided_with_invalid_params.yml +97 -0
  59. data/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_parameters_are_invalid.yml +35 -0
  60. data/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_parameters_are_valid.yml +38 -0
  61. data/test/cassettes/openstack/identity/v2/public/create_token/leads_to_a_valid_response_when_provided_with_a_token.yml +98 -0
  62. data/test/environment.yml.example +22 -0
  63. data/test/environment.yml.travis-ci +24 -0
  64. data/test/support/openstack_request_test_helper.rb +57 -0
  65. data/test/support/test_base_class.rb +39 -0
  66. data/test/support/test_environment.rb +37 -0
  67. data/test/support/test_reporter.rb +45 -0
  68. data/test/support/vcr_setup.rb +41 -0
  69. data/test/test_helper.rb +35 -0
  70. data/tmp/.gitignore +0 -0
  71. metadata +310 -8
  72. data/lib/aviator.rb +0 -5
@@ -0,0 +1,42 @@
1
+ define_request :create_tenant do
2
+
3
+ endpoint_type :admin
4
+ api_version :v2
5
+ http_method :post
6
+
7
+ link_to 'documentation',
8
+ 'http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_addTenant_v2.0_tenants_.html'
9
+
10
+ required_param :name
11
+ required_param :description
12
+ required_param :enabled
13
+
14
+
15
+ def url
16
+ service_spec = session_data[:access][:serviceCatalog].find{|s| s[:type] == 'identity' }
17
+ "#{ service_spec[:endpoints][0][:adminURL] }/tenants"
18
+ end
19
+
20
+
21
+ def headers
22
+ h = {}
23
+
24
+ unless self.anonymous?
25
+ h['X-Auth-Token'] = session_data[:access][:token][:id]
26
+ end
27
+
28
+ h
29
+ end
30
+
31
+
32
+ def body
33
+ {
34
+ tenant: {
35
+ name: params[:name],
36
+ description: params[:description],
37
+ enabled: params[:enabled]
38
+ }
39
+ }
40
+ end
41
+
42
+ end
@@ -0,0 +1,43 @@
1
+ define_request :list_tenants do
2
+
3
+ endpoint_type :admin
4
+ api_version :v2
5
+ http_method :get
6
+
7
+ link_to 'documentation',
8
+ 'http://docs.openstack.org/api/openstack-identity-service/2.0/content/GET_listTenants_v2.0_tenants_Tenant_Operations.html'
9
+
10
+ link_to 'documentation bug',
11
+ 'https://bugs.launchpad.net/keystone/+bug/1218601'
12
+
13
+ optional_param :marker
14
+ optional_param :limit
15
+
16
+
17
+ def url
18
+ service_spec = session_data[:access][:serviceCatalog].find{|s| s[:type] == 'identity' }
19
+ str = "#{ service_spec[:endpoints][0][:adminURL] }/tenants"
20
+
21
+ filters = []
22
+
23
+ (optional_params + required_params).each do |param_name|
24
+ filters << "#{ param_name }=#{ params[param_name] }" if params[param_name]
25
+ end
26
+
27
+ str += "?#{ filters.join('&') }" unless filters.empty?
28
+
29
+ str
30
+ end
31
+
32
+
33
+ def headers
34
+ h = {}
35
+
36
+ unless self.anonymous?
37
+ h['X-Auth-Token'] = session_data[:access][:token][:id]
38
+ end
39
+
40
+ h
41
+ end
42
+
43
+ end
@@ -0,0 +1,61 @@
1
+ define_request :create_token do
2
+
3
+ anonymous
4
+
5
+ endpoint_type :public
6
+ api_version :v2
7
+ http_method :post
8
+
9
+ link_to 'documentation',
10
+ 'http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_.html'
11
+
12
+ link_to 'documentation bug',
13
+ 'https://bugs.launchpad.net/keystone/+bug/1208607'
14
+
15
+
16
+ optional_param :username
17
+ optional_param :password
18
+ optional_param :tokenId
19
+
20
+ optional_param :tenantName
21
+ optional_param :tenantId
22
+
23
+
24
+ # TODO: Add logic for when session_data is actually an OpenStack
25
+ # authentication response body and not auth bootstrap information
26
+ def url
27
+ url = session_data[:auth_service][:host_uri]
28
+ url += '/v2.0' if (URI(url).path =~ /^\/?\w+/).nil?
29
+ url += "/tokens"
30
+
31
+ url
32
+ end
33
+
34
+
35
+ def body
36
+ p = if params[:tokenId]
37
+ {
38
+ auth: {
39
+ token: {
40
+ id: params[:tokenId]
41
+ }
42
+ }
43
+ }
44
+ else
45
+ {
46
+ auth: {
47
+ passwordCredentials: {
48
+ username: params[:username],
49
+ password: params[:password]
50
+ }
51
+ }
52
+ }
53
+ end
54
+
55
+ p[:auth][:tenantName] = params[:tenantName] if params[:tenantName]
56
+ p[:auth][:tenantId] = params[:tenantId] if params[:tenantId]
57
+
58
+ p
59
+ end
60
+
61
+ end
@@ -0,0 +1,44 @@
1
+ define_request :list_tenants do
2
+
3
+ endpoint_type :public
4
+ api_version :v2
5
+ http_method :get
6
+
7
+ link_to 'documentation',
8
+ 'http://docs.openstack.org/api/openstack-identity-service/2.0/content/GET_listTenants_v2.0_tokens_tenants_.html'
9
+
10
+ link_to 'documentation bug',
11
+ 'https://bugs.launchpad.net/keystone/+bug/1218601'
12
+
13
+
14
+ optional_param :marker
15
+ optional_param :limit
16
+
17
+
18
+ def url
19
+ service_spec = session_data[:access][:serviceCatalog].find{|s| s[:type] == 'identity' }
20
+ str = "#{ service_spec[:endpoints][0][:publicURL] }/tenants"
21
+
22
+ filters = []
23
+
24
+ (optional_params + required_params).each do |param_name|
25
+ filters << "#{ param_name }=#{ params[param_name] }" if params[param_name]
26
+ end
27
+
28
+ str += "?#{ filters.join('&') }" unless filters.empty?
29
+
30
+ str
31
+ end
32
+
33
+
34
+ def headers
35
+ h = {}
36
+
37
+ unless self.anonymous?
38
+ h['X-Auth-Token'] = session_data[:access][:token][:id]
39
+ end
40
+
41
+ h
42
+ end
43
+
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Aviator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,342 @@
1
+ require 'test_helper'
2
+
3
+ class Aviator::Test
4
+
5
+ describe 'aviator/core/request' do
6
+
7
+ describe '::new' do
8
+
9
+ it 'raises an error when a required param is not provided' do
10
+ klass = Class.new(Aviator::Request) do
11
+ required_param :someparamname
12
+ end
13
+
14
+ initializer = lambda { klass.new }
15
+ initializer.must_raise ArgumentError
16
+
17
+ error = initializer.call rescue $!
18
+
19
+ error.message.wont_be_nil
20
+ error.message.must_include "someparamname"
21
+ end
22
+
23
+
24
+ it 'does not raise any error when the required param is provided' do
25
+ klass = Class.new(Aviator::Request) do
26
+ required_param :someparamname
27
+ end
28
+
29
+ # obj = klass.new({ someparamname: 'someparamvalue' })
30
+
31
+ obj = klass.new do |params|
32
+ params.someparamname = 'something'
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+
39
+ describe '::anonymous?' do
40
+
41
+ it 'is false by default' do
42
+ klass = Class.new(Aviator::Request)
43
+
44
+ klass.anonymous?.must_equal false
45
+ end
46
+
47
+
48
+ it 'returns true if specified as such' do
49
+ klass = Class.new(Aviator::Request) do
50
+ anonymous
51
+ end
52
+
53
+ klass.anonymous?.must_equal true
54
+ end
55
+
56
+ end
57
+
58
+
59
+ describe '#anonymous?' do
60
+
61
+ it 'is false by default' do
62
+ klass = Class.new(Aviator::Request)
63
+
64
+ klass.new.anonymous?.must_equal false
65
+ end
66
+
67
+
68
+ it 'returns true if specified as such' do
69
+ klass = Class.new(Aviator::Request) do
70
+ anonymous
71
+ end
72
+
73
+ klass.new.anonymous?.must_equal true
74
+ end
75
+
76
+ end
77
+
78
+
79
+ describe '::api_version' do
80
+
81
+ it 'returns the api version' do
82
+ klass = Class.new(Aviator::Request) do
83
+ api_version :v2
84
+ end
85
+
86
+ klass.api_version.must_equal :v2
87
+ end
88
+
89
+ end
90
+
91
+
92
+ describe '#api_version' do
93
+
94
+ it 'returns the api version' do
95
+ klass = Class.new(Aviator::Request) do
96
+ api_version :v2
97
+ end
98
+
99
+ klass.new.api_version.must_equal :v2
100
+ end
101
+
102
+ end
103
+
104
+
105
+ describe '::body?' do
106
+
107
+ it 'returns false if the body method is not defined' do
108
+ klass = Class.new(Aviator::Request)
109
+
110
+ klass.body?.must_equal false
111
+ end
112
+
113
+
114
+ it 'returns true if the body method is defined' do
115
+ klass = Class.new(Aviator::Request) do
116
+ def body; end
117
+ end
118
+
119
+ klass.body?.must_equal true
120
+ end
121
+
122
+ end
123
+
124
+
125
+ describe '#body?' do
126
+
127
+ it 'returns false if the body method is not defined' do
128
+ klass = Class.new(Aviator::Request)
129
+
130
+ klass.new.body?.must_equal false
131
+ end
132
+
133
+
134
+ it 'returns true if the body method is defined' do
135
+ klass = Class.new(Aviator::Request) do
136
+ def body; end
137
+ end
138
+
139
+ klass.new.body?.must_equal true
140
+ end
141
+
142
+ end
143
+
144
+
145
+ describe '::endpoint_type' do
146
+
147
+ it 'returns the endpoint type' do
148
+ klass = Class.new(Aviator::Request) do
149
+ endpoint_type :public
150
+ end
151
+
152
+ klass.endpoint_type.must_equal :public
153
+ end
154
+
155
+ end
156
+
157
+
158
+ describe '#endpoint_type' do
159
+
160
+ it 'returns the endpoint type' do
161
+ klass = Class.new(Aviator::Request) do
162
+ endpoint_type :public
163
+ end
164
+
165
+ klass.new.endpoint_type.must_equal :public
166
+ end
167
+
168
+ end
169
+
170
+
171
+ describe '::http_method' do
172
+
173
+ it 'returns the http method if it is defined' do
174
+ klass = Class.new(Aviator::Request) do
175
+ http_method :post
176
+ end
177
+
178
+ klass.http_method.must_equal :post
179
+ end
180
+
181
+ end
182
+
183
+
184
+ describe '#http_method' do
185
+
186
+ it 'returns the http method if it is defined' do
187
+ klass = Class.new(Aviator::Request) do
188
+ http_method :post
189
+ end
190
+
191
+ klass.new.http_method.must_equal :post
192
+ end
193
+
194
+ end
195
+
196
+
197
+ describe '::link_to' do
198
+
199
+ it 'adds a link to Request::links' do
200
+ rel = 'documentation'
201
+ href = 'http://x.y.z'
202
+
203
+ klass = Class.new(Aviator::Request) do
204
+ link_to rel, href
205
+ end
206
+
207
+ expected = [
208
+ { rel: rel, href: href }
209
+ ]
210
+
211
+ klass.links.must_equal expected
212
+ klass.new.links.must_equal expected
213
+ end
214
+
215
+ end
216
+
217
+
218
+ describe '::optional_param' do
219
+
220
+ it 'is a private class method' do
221
+ private_method = lambda { Aviator::Request.optional_param }
222
+ private_method.must_raise NoMethodError
223
+
224
+ error = private_method.call rescue $!
225
+
226
+ error.message.wont_be_nil
227
+ error.message.must_include "private method"
228
+ end
229
+
230
+ end
231
+
232
+
233
+ describe '::optional_params' do
234
+
235
+ it 'returns an array' do
236
+ klass = Class.new(Aviator::Request) do
237
+ optional_param :whatever
238
+ end
239
+
240
+ klass.optional_params.must_equal [:whatever]
241
+ end
242
+
243
+ end
244
+
245
+
246
+ describe '#optional_params' do
247
+
248
+ it 'returns an array' do
249
+ klass = Class.new(Aviator::Request) do
250
+ optional_param :whatever
251
+ end
252
+
253
+ klass.new.optional_params.must_equal [:whatever]
254
+ end
255
+
256
+ end
257
+
258
+
259
+ describe '::required_param' do
260
+
261
+ it 'is a private class method' do
262
+ private_method = lambda { Aviator::Request.required_param }
263
+ private_method.must_raise NoMethodError
264
+
265
+ error = private_method.call rescue $!
266
+
267
+ error.message.wont_be_nil
268
+ error.message.must_include "private method"
269
+ end
270
+
271
+ end
272
+
273
+
274
+ describe '::required_params' do
275
+
276
+ it 'returns an array' do
277
+ klass = Class.new(Aviator::Request) do
278
+ required_param :whatever
279
+ end
280
+
281
+ klass.required_params.must_equal [:whatever]
282
+ end
283
+
284
+ end
285
+
286
+
287
+ describe '#required_params' do
288
+
289
+ it 'returns an array' do
290
+ klass = Class.new(Aviator::Request) do
291
+ required_param :whatever
292
+ end
293
+
294
+ klass.required_params.must_equal [:whatever]
295
+ end
296
+
297
+ end
298
+
299
+
300
+ describe '::url?' do
301
+
302
+ it 'returns false if the path method is not defined' do
303
+ klass = Class.new(Aviator::Request)
304
+
305
+ klass.url?.must_equal false
306
+ end
307
+
308
+
309
+ it 'returns true if the path method is defined' do
310
+ klass = Class.new(Aviator::Request) do
311
+ def url; end
312
+ end
313
+
314
+ klass.url?.must_equal true
315
+ end
316
+
317
+ end
318
+
319
+
320
+ describe '#path?' do
321
+
322
+ it 'returns false if the path method is not defined' do
323
+ klass = Class.new(Aviator::Request)
324
+
325
+ klass.new.url?.must_equal false
326
+ end
327
+
328
+
329
+ it 'returns true if the path method is defined' do
330
+ klass = Class.new(Aviator::Request) do
331
+ def url; end
332
+ end
333
+
334
+ klass.new.url?.must_equal true
335
+ end
336
+
337
+ end
338
+
339
+
340
+ end
341
+
342
+ end