stacker_bee 2.1.1.pre252 → 2.1.1.pre263
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rubocop.yml +0 -3
- data/Rakefile +1 -1
- data/bin/stacker_bee +10 -10
- data/lib/stacker_bee/api.rb +4 -4
- data/lib/stacker_bee/client.rb +24 -24
- data/lib/stacker_bee/configuration.rb +13 -7
- data/lib/stacker_bee/connection.rb +5 -5
- data/lib/stacker_bee/http_middleware/detokenizer.rb +2 -2
- data/lib/stacker_bee/http_middleware/signed_query.rb +3 -3
- data/lib/stacker_bee/middleware/adapter.rb +1 -1
- data/lib/stacker_bee/middleware/base.rb +1 -1
- data/lib/stacker_bee/middleware/clean_response.rb +2 -2
- data/lib/stacker_bee/middleware/cloud_stack_api.rb +2 -2
- data/lib/stacker_bee/middleware/dictionary_flattener.rb +3 -3
- data/lib/stacker_bee/middleware/endpoint_normalizer.rb +2 -2
- data/lib/stacker_bee/middleware/error_message.rb +3 -3
- data/lib/stacker_bee/middleware/log_response.rb +1 -1
- data/lib/stacker_bee/middleware/raise_on_http_error.rb +1 -1
- data/lib/stacker_bee/middleware/remove_nils.rb +1 -1
- data/lib/stacker_bee/rash.rb +3 -3
- data/lib/stacker_bee/version.rb +1 -1
- data/lib/stacker_bee.rb +2 -2
- data/spec/integration/configure_middleware_spec.rb +12 -12
- data/spec/integration/console_spec.rb +4 -4
- data/spec/integration/request_spec.rb +46 -46
- data/spec/spec_helper.rb +4 -4
- data/spec/support/vcr.rb +4 -4
- data/spec/units/stacker_bee/api_spec.rb +11 -11
- data/spec/units/stacker_bee/client_spec.rb +19 -19
- data/spec/units/stacker_bee/configuration_spec.rb +28 -28
- data/spec/units/stacker_bee/connection_spec.rb +18 -18
- data/spec/units/stacker_bee/middleware/adapter_spec.rb +7 -7
- data/spec/units/stacker_bee/middleware/base_spec.rb +17 -17
- data/spec/units/stacker_bee/middleware/cloudstack_api_spec.rb +9 -9
- data/spec/units/stacker_bee/middleware/console_access_spec.rb +10 -10
- data/spec/units/stacker_bee/middleware/dictionary_flattener_spec.rb +22 -22
- data/spec/units/stacker_bee/middleware/endpoint_normalizer_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/error_message_spec.rb +6 -6
- data/spec/units/stacker_bee/middleware/format_keys_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/format_values_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/http_status_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/log_response_spec.rb +15 -15
- data/spec/units/stacker_bee/middleware/remove_empty_strings_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/remove_nils_spec.rb +1 -1
- data/spec/units/stacker_bee/rash_spec.rb +41 -41
- data/spec/units/stacker_bee/request_error_spec.rb +7 -7
- data/spec/units/stacker_bee/utilities_spec.rb +30 -30
- data/spec/units/stacker_bee_spec.rb +2 -2
- data/stacker_bee.gemspec +24 -22
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGZiMGQ0YTBhNmNhMjAzM2FhOWE1NWRjMmM0MWYxNjBlNjYzMmQwZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmMwOWM4YjdkYTk1NDJhODgzNTM4Yjg3MmIzNzcxMDg4MTA3ZWE1MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2M0M2IxZTAwMTA0NzMzMDNhMTQxNjg5OWViNWM4YzVlM2E4MWYzODNmYThi
|
10
|
+
YmYzMzljMGI0Y2FjYzQ4MDVlNTJlNDJjYWNiMzhlODRkY2ZhYzM5MzVhMjFk
|
11
|
+
ODNmNmE2YTIwZTRhN2VkZWQ0NGQ5MTAxYTYyNTIwMTY3YWZlMWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGZkOWNiMjUzODU1YTI3MjFlOTdjYzVjNjgzN2NiMDMzYTk4ZGZkMWYyY2Qy
|
14
|
+
YzE3ZjU5YmM0ZTFjZDYyOTg3Y2Y1YTM4Mzk4NmFiZWIxNWI2ZWIxYTUwNzQ3
|
15
|
+
YTAyMmVlODU5ODNjNTQ0MjZjNTIxMWM2OTU4YjVkYjRhZWQ3ODU=
|
data/.rubocop.yml
CHANGED
data/Rakefile
CHANGED
data/bin/stacker_bee
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'stacker_bee'
|
@@ -9,7 +9,7 @@ require 'yaml'
|
|
9
9
|
require 'irb'
|
10
10
|
require 'irb/completion'
|
11
11
|
|
12
|
-
cli_title =
|
12
|
+
cli_title = 'StackerBee CloudStack REPL'
|
13
13
|
|
14
14
|
command = File.basename(__FILE__)
|
15
15
|
options = {}
|
@@ -21,27 +21,27 @@ optparse = OptionParser.new do |opts|
|
|
21
21
|
Example: #{command} -u http://localhost:8080 -a MY_API_KEY -s MY_SECRET_KEY
|
22
22
|
BANNER
|
23
23
|
|
24
|
-
config_help =
|
24
|
+
config_help = 'StackerBee configuration file, formatted as YAML'
|
25
25
|
opts.on('-c', '--config=/PATH/TO/CONFIG.yml', config_help) do |config|
|
26
26
|
options[:config] = config
|
27
27
|
end
|
28
|
-
opts.on('-a', '--api_key=API_KEY',
|
28
|
+
opts.on('-a', '--api_key=API_KEY', 'CloudStack API Key') do |key|
|
29
29
|
options[:api_key] = key
|
30
30
|
end
|
31
|
-
opts.on('-s', '--secret_key=SECRET_KEY',
|
31
|
+
opts.on('-s', '--secret_key=SECRET_KEY', 'CloudStack Secret Key') do |key|
|
32
32
|
options[:secret_key] = key
|
33
33
|
end
|
34
|
-
opts.on('-u', '--url=URL',
|
34
|
+
opts.on('-u', '--url=URL', 'CloudStack URL') do |url|
|
35
35
|
options[:url] = url
|
36
36
|
end
|
37
|
-
opts.on('-v', '--[no-]verbose', 'Run verbosely') do
|
37
|
+
opts.on('-v', '--[no-]verbose', 'Run verbosely') do
|
38
38
|
verbose = true
|
39
39
|
end
|
40
40
|
opts.on('-h', '--help', 'Display this screen') do
|
41
41
|
puts opts
|
42
42
|
|
43
43
|
puts
|
44
|
-
puts
|
44
|
+
puts 'Example config file:'
|
45
45
|
puts
|
46
46
|
puts "url: 'http://127.0.0.1:1234/client/api'"
|
47
47
|
puts "api_key: 'MY_KEY-MY_KEY-MY_KEY'"
|
@@ -59,8 +59,8 @@ begin
|
|
59
59
|
end
|
60
60
|
unless options.keys.include?(:config) ||
|
61
61
|
([:api_key, :secret_key, :url] - options.keys).empty?
|
62
|
-
puts
|
63
|
-
|
62
|
+
puts 'Please specify a config file or all of the following: ' \
|
63
|
+
'--api_key, --secret_key and --url'
|
64
64
|
exit
|
65
65
|
end
|
66
66
|
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
data/lib/stacker_bee/api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'multi_json'
|
2
|
+
require 'stacker_bee/utilities'
|
3
3
|
|
4
4
|
module StackerBee
|
5
5
|
class API
|
@@ -35,8 +35,8 @@ module StackerBee
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def apis_by_endpoint(response)
|
38
|
-
response[
|
39
|
-
memo[uncase(api[
|
38
|
+
response['listapisresponse']['api'].each_with_object({}) do |api, memo|
|
39
|
+
memo[uncase(api['name'])] = api
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/stacker_bee/client.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
1
|
+
require 'forwardable'
|
2
|
+
require 'stacker_bee/builder'
|
3
|
+
require 'stacker_bee/configuration'
|
4
|
+
require 'stacker_bee/api'
|
5
|
+
require 'stacker_bee/connection'
|
6
|
+
require 'stacker_bee/middleware/environment'
|
7
|
+
require 'stacker_bee/middleware/base'
|
8
|
+
require 'stacker_bee/middleware/adapter'
|
9
|
+
require 'stacker_bee/middleware/endpoint_normalizer'
|
10
|
+
require 'stacker_bee/middleware/remove_empty_strings'
|
11
|
+
require 'stacker_bee/middleware/cloud_stack_api'
|
12
|
+
require 'stacker_bee/middleware/dictionary_flattener'
|
13
|
+
require 'stacker_bee/middleware/remove_nils'
|
14
|
+
require 'stacker_bee/middleware/format_keys'
|
15
|
+
require 'stacker_bee/middleware/format_values'
|
16
|
+
require 'stacker_bee/middleware/json_body'
|
17
|
+
require 'stacker_bee/middleware/de_namespace'
|
18
|
+
require 'stacker_bee/middleware/rashify_response'
|
19
|
+
require 'stacker_bee/middleware/clean_response'
|
20
|
+
require 'stacker_bee/middleware/raise_on_http_error'
|
21
|
+
require 'stacker_bee/middleware/http_status'
|
22
|
+
require 'stacker_bee/middleware/console_access'
|
23
|
+
require 'stacker_bee/middleware/error_message'
|
24
|
+
require 'stacker_bee/middleware/log_response'
|
25
25
|
|
26
26
|
# rubocop:disable ClassLength
|
27
27
|
module StackerBee
|
@@ -10,19 +10,25 @@ module StackerBee
|
|
10
10
|
:api_key,
|
11
11
|
:middlewares,
|
12
12
|
:faraday_middlewares,
|
13
|
-
:logger
|
13
|
+
:logger,
|
14
|
+
:config
|
14
15
|
]
|
15
16
|
|
16
17
|
def initialize(attrs = nil)
|
17
18
|
@attributes = attrs || {}
|
18
|
-
|
19
|
-
next if key == :config
|
20
|
-
unless ATTRIBUTES.include?(key)
|
21
|
-
fail NoAttributeError, "No attribute defined: '#{key}'"
|
22
|
-
end
|
23
|
-
end
|
19
|
+
validate_attributes
|
24
20
|
end
|
25
21
|
|
22
|
+
def validate_attributes
|
23
|
+
unknown_attributes = @attributes.keys - ATTRIBUTES
|
24
|
+
return if unknown_attributes.empty?
|
25
|
+
|
26
|
+
attribute_list = unknown_attributes.join(', ')
|
27
|
+
message = "No configuration attribute exists: #{attribute_list}"
|
28
|
+
fail NoAttributeError, message
|
29
|
+
end
|
30
|
+
private :validate_attributes
|
31
|
+
|
26
32
|
def ssl_verify?
|
27
33
|
attribute :ssl_verify, true
|
28
34
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'faraday'
|
2
|
+
require 'uri'
|
3
|
+
require 'stacker_bee/http_middleware/signed_query'
|
4
|
+
require 'stacker_bee/http_middleware/detokenizer'
|
5
5
|
|
6
6
|
module StackerBee
|
7
7
|
class ConnectionError < StandardError
|
@@ -15,7 +15,7 @@ module StackerBee
|
|
15
15
|
|
16
16
|
uri = URI.parse(configuration.url)
|
17
17
|
uri.path = ''
|
18
|
-
fail ConnectionError,
|
18
|
+
fail ConnectionError, 'no protocol specified' unless uri.scheme
|
19
19
|
|
20
20
|
initialize_faraday(
|
21
21
|
url: uri.to_s,
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'faraday'
|
2
|
+
require 'base64'
|
3
3
|
|
4
4
|
module StackerBee
|
5
5
|
module HTTPMiddleware
|
6
6
|
class SignedQuery < Faraday::Middleware
|
7
7
|
def initialize(app, key)
|
8
8
|
@key = key
|
9
|
-
fail
|
9
|
+
fail 'Key cannot be nil' unless @key
|
10
10
|
super app
|
11
11
|
end
|
12
12
|
|
@@ -5,7 +5,7 @@ module StackerBee
|
|
5
5
|
params = env.request.params.to_a.sort
|
6
6
|
env.raw_response = connection.get(env.request.path, params)
|
7
7
|
env.response.content_type =
|
8
|
-
env.raw_response.env[:response_headers][
|
8
|
+
env.raw_response.env[:response_headers]['content-type']
|
9
9
|
env.response.body = env.raw_response.body
|
10
10
|
end
|
11
11
|
|
@@ -18,11 +18,11 @@ module StackerBee
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def contains_count?(body)
|
21
|
-
body.size == 2 && body.key?(
|
21
|
+
body.size == 2 && body.key?('count')
|
22
22
|
end
|
23
23
|
|
24
24
|
def remove_count(body)
|
25
|
-
body.reject { |key,
|
25
|
+
body.reject { |key, _| key == 'count' }.values.first
|
26
26
|
end
|
27
27
|
|
28
28
|
def single_hash?(body)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module StackerBee
|
2
2
|
module Middleware
|
3
3
|
class DictionaryFlattener < Base
|
4
|
-
LB =
|
5
|
-
RB =
|
4
|
+
LB = 'SBLEFTBRACKET'
|
5
|
+
RB = 'SBRIGHTBRACKET'
|
6
6
|
|
7
7
|
# TODO: should the tokenizing be separate from the flattener?
|
8
8
|
# it could be a middleware that finds [] in the keys and replaces them
|
@@ -38,7 +38,7 @@ module StackerBee
|
|
38
38
|
|
39
39
|
# TODO: isn't this done with the RemoveEmptyStrings middleware?
|
40
40
|
def remove_falseish(hash)
|
41
|
-
hash.reject { |_, v| v ==
|
41
|
+
hash.reject { |_, v| v == '' || v =~ /false/i || !v }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -8,10 +8,10 @@ module StackerBee
|
|
8
8
|
|
9
9
|
def endpoint_name_for(name)
|
10
10
|
# TODO: shouldn't this be in the base endpoint?
|
11
|
-
fail
|
11
|
+
fail 'API required' unless api
|
12
12
|
endpoint_description = api[name]
|
13
13
|
if endpoint_description
|
14
|
-
endpoint_description.fetch(
|
14
|
+
endpoint_description.fetch('name')
|
15
15
|
else
|
16
16
|
super
|
17
17
|
end
|
@@ -2,9 +2,9 @@ module StackerBee
|
|
2
2
|
module Middleware
|
3
3
|
class ErrorMessage < Base
|
4
4
|
def after(env)
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
return if env.response.success?
|
6
|
+
|
7
|
+
env.response.error = env.response.body[:errortext]
|
8
8
|
end
|
9
9
|
|
10
10
|
def content_types
|
data/lib/stacker_bee/rash.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'forwardable'
|
2
|
+
require 'stacker_bee/utilities'
|
3
3
|
|
4
4
|
module StackerBee
|
5
5
|
class Rash
|
@@ -78,7 +78,7 @@ module StackerBee
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def convert_key(key)
|
81
|
-
key.
|
81
|
+
key.is_a?(Numeric) ? key : uncase(key)
|
82
82
|
end
|
83
83
|
|
84
84
|
def convert_value(value)
|
data/lib/stacker_bee/version.rb
CHANGED
data/lib/stacker_bee.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'stacker_bee/version'
|
2
|
+
require_relative 'stacker_bee/client'
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Configuring middlewares' do
|
4
4
|
let(:configuration) do
|
5
5
|
{
|
6
|
-
url:
|
7
|
-
api_key:
|
8
|
-
secret_key:
|
6
|
+
url: 'http://garbagestring',
|
7
|
+
api_key: 'HI!',
|
8
|
+
secret_key: 'SECRET',
|
9
9
|
faraday_middlewares: faraday_middlewares,
|
10
10
|
middlewares: middlewares
|
11
11
|
}
|
@@ -19,21 +19,21 @@ describe "Configuring middlewares" do
|
|
19
19
|
|
20
20
|
let(:body) do
|
21
21
|
proc do
|
22
|
-
def call(
|
23
|
-
fail
|
22
|
+
def call(_env)
|
23
|
+
fail 'MiddlewareUsed'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.it_uses_the_middleware
|
29
|
-
it
|
29
|
+
it 'uses the middle ware' do
|
30
30
|
expect { subject.list_virtual_machines }
|
31
|
-
.to raise_exception
|
31
|
+
.to raise_exception 'MiddlewareUsed'
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.it_configures_a_faraday_middleware
|
36
|
-
describe
|
36
|
+
describe 'a Faraday middleware' do
|
37
37
|
let(:faraday_middlewares) do
|
38
38
|
->(faraday) { faraday.use faraday_middleware_class }
|
39
39
|
end
|
@@ -43,7 +43,7 @@ describe "Configuring middlewares" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.it_configures_a_middleware
|
46
|
-
describe
|
46
|
+
describe 'a StackerBee middleware' do
|
47
47
|
let(:middlewares) do
|
48
48
|
->(builder) { builder.use middleware_class }
|
49
49
|
end
|
@@ -51,7 +51,7 @@ describe "Configuring middlewares" do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe 'via StackerBee::Client.configuration=' do
|
55
55
|
subject { StackerBee::Client.new }
|
56
56
|
before { StackerBee::Client.configuration = configuration }
|
57
57
|
|
@@ -59,7 +59,7 @@ describe "Configuring middlewares" do
|
|
59
59
|
it_configures_a_faraday_middleware
|
60
60
|
end
|
61
61
|
|
62
|
-
describe
|
62
|
+
describe 'via the Client initializer' do
|
63
63
|
subject { StackerBee::Client.new(configuration) }
|
64
64
|
|
65
65
|
it_configures_a_middleware
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'A request sent to CloudStack for console access', :vcr do
|
4
4
|
subject(:console_access) { client.console_access(vm: vm) }
|
5
5
|
|
6
|
-
let(:vm) {
|
6
|
+
let(:vm) { '36f9c08b-f17a-4d0e-ac9b-d45ce2d34fcd' }
|
7
7
|
let(:client) { StackerBee::Client.new(config_hash) }
|
8
8
|
let(:config_hash) do
|
9
9
|
{
|
@@ -13,7 +13,7 @@ describe "A request sent to CloudStack for console access", :vcr do
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns html for console access' do
|
17
17
|
expect(console_access).to match(/<html>.*<frame src=.*<\/html>/)
|
18
18
|
end
|
19
19
|
end
|